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