Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: src/utils.h

Issue 7472029: Introduce a poor man's version of STL's bitset. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils.h
===================================================================
--- src/utils.h (revision 8701)
+++ src/utils.h (working copy)
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
+#include <climits>
Vitaly Repeshko 2011/07/21 12:56:18 We include old school standard library headers wit
Sven Panne 2011/07/21 13:07:13 That's not completely true, cstdio and cstdarg are
#include "globals.h"
#include "checks.h"
@@ -885,6 +886,30 @@
DISALLOW_IMPLICIT_CONSTRUCTORS(SimpleStringBuilder);
};
+
+// A poor man's version of STL's bitset: A bit set of enums E (without explicit
+// values), fitting into an integral type T.
+template <class E, class T = int>
+class EnumSet {
+ public:
+ explicit EnumSet(T bits = 0) : bits_(bits) {}
+ bool IsEmpty() const { return bits_ == 0; }
+ bool Contains(E element) const { return (bits_ & Mask(element)) != 0; }
+ void Add(E element) { bits_ |= Mask(element); }
+ void Remove(E element) { bits_ &= ~Mask(element); }
+ T ToIntegral() const { return bits_; }
+
+ private:
+ T Mask(E element) const {
+ // The strange typing in ASSERT is necessary to avoid stupid warnings, see:
+ // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680
+ ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));
+ return 1 << element;
+ }
+
+ T bits_;
+};
+
} } // namespace v8::internal
#endif // V8_UTILS_H_
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698