File indexing completed on 2025-01-18 10:13:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef ENUMSET_H
0018 #define ENUMSET_H
0019
0020 #include "unicode/utypes.h"
0021
0022 #if U_SHOW_CPLUSPLUS_API
0023
0024 U_NAMESPACE_BEGIN
0025
0026
0027
0028
0029
0030
0031
0032
0033 template<typename T, uint32_t minValue, uint32_t limitValue>
0034 class EnumSet {
0035 public:
0036 inline EnumSet() : fBools(0) {}
0037 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}
0038 inline ~EnumSet() {}
0039 #ifndef U_HIDE_INTERNAL_API
0040 inline void clear() { fBools=0; }
0041 inline void add(T toAdd) { set(toAdd, 1); }
0042 inline void remove(T toRemove) { set(toRemove, 0); }
0043 inline int32_t contains(T toCheck) const { return get(toCheck); }
0044 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }
0045 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }
0046 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); }
0047 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }
0048 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {
0049 fBools = other.fBools;
0050 return *this;
0051 }
0052
0053 inline uint32_t getAll() const {
0054 return fBools;
0055 }
0056 #endif
0057
0058 private:
0059 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }
0060 private:
0061 uint32_t fBools;
0062 };
0063
0064
0065
0066 U_NAMESPACE_END
0067
0068 #endif
0069 #endif