19 #ifndef PAGESPEED_KERNEL_BASE_ENUM_SET_H_
20 #define PAGESPEED_KERNEL_BASE_ENUM_SET_H_
25 namespace net_instaweb {
28 template<
typename EnumType,
size_t NumEnums>
class EnumSet {
30 bool IsSet(EnumType value)
const {
31 return bits_.test(static_cast<size_t>(value));
36 bool result = !IsSet(value);
45 bits_.set(static_cast<size_t>(value));
50 bool result = IsSet(value);
51 bits_.reset(static_cast<size_t>(value));
62 return bits_ != save.bits_;
70 return bits_ != save.bits_;
73 void EraseSet(
const EnumSet& src) {
84 size_t size()
const {
return bits_.count(); }
85 bool empty()
const {
return bits_.none(); }
89 return bits_ == that.bits_;
93 typedef std::bitset<NumEnums> BitSet;
void insert(EnumType value)
Definition: enum_set.h:44
bool Insert(EnumType value)
Inserts a new value, returning true if a change was made.
Definition: enum_set.h:35
Represents a set of values – implemented via a bitset.
Definition: enum_set.h:28
bool operator==(const EnumSet &that) const
This overload is required for use in EXPECT_EQ in tests.
Definition: enum_set.h:88
bool Erase(EnumType value)
Returns true if a change was made.
Definition: enum_set.h:49
void SetAll()
Sets all the entries to true.
Definition: enum_set.h:78
void clear()
Standard STL-like methods.
Definition: enum_set.h:83
bool MergeInverted(const EnumSet &src)
Definition: enum_set.h:67
bool Merge(const EnumSet &src)
Merges src into this, returning whether this resulted in a change.
Definition: enum_set.h:56