OLD | NEW |
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 * | 3 * |
4 * Copyright (C) 2012, International Business Machines | 4 * Copyright (C) 2012,2014 International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ****************************************************************************** | 7 ****************************************************************************** |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
11 * \file | 11 * \file |
12 * \brief C++: internal template EnumSet<> | 12 * \brief C++: internal template EnumSet<> |
13 */ | 13 */ |
14 | 14 |
15 #ifndef ENUMSET_H | 15 #ifndef ENUMSET_H |
16 #define ENUMSET_H | 16 #define ENUMSET_H |
17 | 17 |
18 #include "unicode/utypes.h" | 18 #include "unicode/utypes.h" |
19 | 19 |
20 #if U_SHOW_CPLUSPLUS_API | 20 #if U_SHOW_CPLUSPLUS_API |
21 | 21 |
22 U_NAMESPACE_BEGIN | 22 U_NAMESPACE_BEGIN |
23 | 23 |
| 24 /* Can't use #ifndef U_HIDE_INTERNAL_API for the entire EnumSet class, needed in
.h file declarations */ |
24 /** | 25 /** |
25 * enum bitset for boolean fields. Similar to Java EnumSet<>. | 26 * enum bitset for boolean fields. Similar to Java EnumSet<>. |
26 * Needs to range check. | 27 * Needs to range check. Used for private instance variables. |
27 * @internal | 28 * @internal |
28 */ | 29 */ |
29 template<typename T, uint32_t minValue, uint32_t limitValue> | 30 template<typename T, uint32_t minValue, uint32_t limitValue> |
30 class EnumSet { | 31 class EnumSet { |
31 public: | 32 public: |
32 inline EnumSet() : fBools(0) {} | 33 inline EnumSet() : fBools(0) {} |
33 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.f
Bools) {} | 34 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.f
Bools) {} |
34 inline ~EnumSet() {} | 35 inline ~EnumSet() {} |
| 36 #ifndef U_HIDE_INTERNAL_API |
35 inline void clear() { fBools=0; } | 37 inline void clear() { fBools=0; } |
36 inline void add(T toAdd) { set(toAdd, 1); } | 38 inline void add(T toAdd) { set(toAdd, 1); } |
37 inline void remove(T toRemove) { set(toRemove, 0); } | 39 inline void remove(T toRemove) { set(toRemove, 0); } |
38 inline int32_t contains(T toCheck) const { return get(toCheck); } | 40 inline int32_t contains(T toCheck) const { return get(toCheck); } |
39 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(fla
g(toSet)):0); } | 41 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(fla
g(toSet)):0); } |
40 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } | 42 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } |
41 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCh
eck<limitValue); } | 43 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCh
eck<limitValue); } |
42 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); } | 44 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); } |
43 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minVa
lue,limitValue>& other) { | 45 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minVa
lue,limitValue>& other) { |
44 fBools = other.fBools; | 46 fBools = other.fBools; |
45 return *this; | 47 return *this; |
46 } | 48 } |
47 | 49 |
48 inline uint32_t getAll() const { | 50 inline uint32_t getAll() const { |
49 return fBools; | 51 return fBools; |
50 } | 52 } |
| 53 #endif /* U_HIDE_INTERNAL_API */ |
51 | 54 |
52 private: | 55 private: |
53 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } | 56 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } |
54 private: | 57 private: |
55 uint32_t fBools; | 58 uint32_t fBools; |
56 }; | 59 }; |
57 | 60 |
58 U_NAMESPACE_END | 61 U_NAMESPACE_END |
59 | 62 |
60 #endif /* U_SHOW_CPLUSPLUS_API */ | 63 #endif /* U_SHOW_CPLUSPLUS_API */ |
61 #endif /* ENUMSET_H */ | 64 #endif /* ENUMSET_H */ |
OLD | NEW |