michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++: internal template EnumSet<> michael@0: */ michael@0: michael@0: #ifndef ENUMSET_H michael@0: #define ENUMSET_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * enum bitset for boolean fields. Similar to Java EnumSet<>. michael@0: * Needs to range check. michael@0: * @internal michael@0: */ michael@0: template michael@0: class EnumSet { michael@0: public: michael@0: inline EnumSet() : fBools(0) {} michael@0: inline EnumSet(const EnumSet& other) : fBools(other.fBools) {} michael@0: inline ~EnumSet() {} michael@0: inline void clear() { fBools=0; } michael@0: inline void add(T toAdd) { set(toAdd, 1); } michael@0: inline void remove(T toRemove) { set(toRemove, 0); } michael@0: inline int32_t contains(T toCheck) const { return get(toCheck); } michael@0: inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); } michael@0: inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } michael@0: inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck& operator=(const EnumSet& other) { michael@0: fBools = other.fBools; michael@0: return *this; michael@0: } michael@0: michael@0: inline uint32_t getAll() const { michael@0: return fBools; michael@0: } michael@0: michael@0: private: michael@0: inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } michael@0: private: michael@0: uint32_t fBools; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* U_SHOW_CPLUSPLUS_API */ michael@0: #endif /* ENUMSET_H */