ICU 56.1: enumset.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

enumset.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 2012,2014 International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 */
9
15 #ifndef ENUMSET_H
16 #define ENUMSET_H
17
18 #include "unicode/utypes.h"
19
20 #if U_SHOW_CPLUSPLUS_API
21
22 U_NAMESPACE_BEGIN
23
24 /* Can't use #ifndef U_HIDE_INTERNAL_API for the entire EnumSet class, needed in .h file declarations */
30 template<typename T, uint32_t minValue, uint32_t limitValue>
31 class EnumSet {
32 public:
33 inline EnumSet() : fBools(0) {}
34 inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}
35 inline ~EnumSet() {}
36 #ifndef U_HIDE_INTERNAL_API
37 inline void clear() { fBools=0; }
38 inline void add(T toAdd) { set(toAdd, 1); }
39 inline void remove(T toRemove) { set(toRemove, 0); }
40 inline int32_t contains(T toCheck) const { return get(toCheck); }
41 inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }
42 inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }
43 inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); }
44 inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }
45 inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {
46 fBools = other.fBools;
47 return *this;
48 }
49
50 inline uint32_t getAll() const {
51 return fBools;
52 }
53 #endif /* U_HIDE_INTERNAL_API */
54
55 private:
56 inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }
57 private:
58 uint32_t fBools;
59 };
60
61 U_NAMESPACE_END
62
63 #endif /* U_SHOW_CPLUSPLUS_API */
64 #endif /* ENUMSET_H */
icu::EnumSet
enum bitset for boolean fields.
Definition: enumset.h:31
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234