2 ******************************************************************************
4 * Copyright (C) 2012, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
12 * \brief C++: internal template EnumSet<>
18 #include "unicode/utypes.h"
20 #if U_SHOW_CPLUSPLUS_API
25 * enum bitset for boolean fields. Similar to Java EnumSet<>.
26 * Needs to range check.
29 template<typename T, uint32_t minValue, uint32_t limitValue>
32 inline EnumSet() : fBools(0) {}
33 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}
35 inline void clear() { fBools=0; }
36 inline void add(T toAdd) { set(toAdd, 1); }
37 inline void remove(T toRemove) { set(toRemove, 0); }
38 inline int32_t contains(T toCheck) const { return get(toCheck); }
39 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }
40 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }
41 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); }
42 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }
43 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {
44 fBools = other.fBools;
48 inline uint32_t getAll() const {
53 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }
60 #endif /* U_SHOW_CPLUSPLUS_API */
61 #endif /* ENUMSET_H */