|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ****************************************************************************** 00005 * 00006 * Copyright (C) 2012,2014 International Business Machines 00007 * Corporation and others. All Rights Reserved. 00008 * 00009 ****************************************************************************** 00010 */ 00011 00017 #ifndef ENUMSET_H 00018 #define ENUMSET_H 00019 00020 #include "unicode/utypes.h" 00021 00022 #if U_SHOW_CPLUSPLUS_API 00023 00024 U_NAMESPACE_BEGIN 00025 00026 /* Can't use #ifndef U_HIDE_INTERNAL_API for the entire EnumSet class, needed in .h file declarations */ 00033 template<typename T, uint32_t minValue, uint32_t limitValue> 00034 class EnumSet { 00035 public: 00036 inline EnumSet() : fBools(0) {} 00037 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {} 00038 inline ~EnumSet() {} 00039 #ifndef U_HIDE_INTERNAL_API 00040 inline void clear() { fBools=0; } 00041 inline void add(T toAdd) { set(toAdd, 1); } 00042 inline void remove(T toRemove) { set(toRemove, 0); } 00043 inline int32_t contains(T toCheck) const { return get(toCheck); } 00044 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); } 00045 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } 00046 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); } 00047 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); } 00048 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) { 00049 fBools = other.fBools; 00050 return *this; 00051 } 00052 00053 inline uint32_t getAll() const { 00054 return fBools; 00055 } 00056 #endif /* U_HIDE_INTERNAL_API */ 00057 00058 private: 00059 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } 00060 private: 00061 uint32_t fBools; 00062 }; 00063 00066 U_NAMESPACE_END 00067 00068 #endif /* U_SHOW_CPLUSPLUS_API */ 00069 #endif /* ENUMSET_H */
1.7.6.1