Revision: 8715
Author: [email protected]
Date: Thu Jul 21 06:06:55 2011
Log: Introduce a poor man's version of STL's bitset.
Used in a separate upcoming patch...
Review URL: http://codereview.chromium.org/7472029
http://code.google.com/p/v8/source/detail?r=8715
Modified:
/branches/bleeding_edge/src/utils.h
=======================================
--- /branches/bleeding_edge/src/utils.h Wed Jul 6 02:15:10 2011
+++ /branches/bleeding_edge/src/utils.h Thu Jul 21 06:06:55 2011
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
+#include <climits>
#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_
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev