00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #ifndef ENUMSET_H
00016 #define ENUMSET_H
00017
00018 #include "unicode/utypes.h"
00019
00020 #if U_SHOW_CPLUSPLUS_API
00021
00022 U_NAMESPACE_BEGIN
00023
00029 template<typename T, uint32_t minValue, uint32_t limitValue>
00030 class EnumSet {
00031 public:
00032 inline EnumSet() : fBools(0) {}
00033 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}
00034 inline ~EnumSet() {}
00035 inline void clear() { fBools=0; }
00036 inline void add(T toAdd) { set(toAdd, 1); }
00037 inline void remove(T toRemove) { set(toRemove, 0); }
00038 inline int32_t contains(T toCheck) const { return get(toCheck); }
00039 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }
00040 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }
00041 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); }
00042 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }
00043 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {
00044 fBools = other.fBools;
00045 return *this;
00046 }
00047
00048 inline uint32_t getAll() const {
00049 return fBools;
00050 }
00051
00052 private:
00053 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }
00054 private:
00055 uint32_t fBools;
00056 };
00057
00058 U_NAMESPACE_END
00059
00060 #endif
00061 #endif