Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ****************************************************************************** |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2012, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ****************************************************************************** |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * \file |
michael@0 | 12 | * \brief C++: internal template EnumSet<> |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | #ifndef ENUMSET_H |
michael@0 | 16 | #define ENUMSET_H |
michael@0 | 17 | |
michael@0 | 18 | #include "unicode/utypes.h" |
michael@0 | 19 | |
michael@0 | 20 | #if U_SHOW_CPLUSPLUS_API |
michael@0 | 21 | |
michael@0 | 22 | U_NAMESPACE_BEGIN |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * enum bitset for boolean fields. Similar to Java EnumSet<>. |
michael@0 | 26 | * Needs to range check. |
michael@0 | 27 | * @internal |
michael@0 | 28 | */ |
michael@0 | 29 | template<typename T, uint32_t minValue, uint32_t limitValue> |
michael@0 | 30 | class EnumSet { |
michael@0 | 31 | public: |
michael@0 | 32 | inline EnumSet() : fBools(0) {} |
michael@0 | 33 | inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {} |
michael@0 | 34 | inline ~EnumSet() {} |
michael@0 | 35 | inline void clear() { fBools=0; } |
michael@0 | 36 | inline void add(T toAdd) { set(toAdd, 1); } |
michael@0 | 37 | inline void remove(T toRemove) { set(toRemove, 0); } |
michael@0 | 38 | inline int32_t contains(T toCheck) const { return get(toCheck); } |
michael@0 | 39 | inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); } |
michael@0 | 40 | inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } |
michael@0 | 41 | inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); } |
michael@0 | 42 | inline UBool isValidValue(int32_t v) const { return (v==0||v==1); } |
michael@0 | 43 | inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) { |
michael@0 | 44 | fBools = other.fBools; |
michael@0 | 45 | return *this; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | inline uint32_t getAll() const { |
michael@0 | 49 | return fBools; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | private: |
michael@0 | 53 | inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } |
michael@0 | 54 | private: |
michael@0 | 55 | uint32_t fBools; |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | U_NAMESPACE_END |
michael@0 | 59 | |
michael@0 | 60 | #endif /* U_SHOW_CPLUSPLUS_API */ |
michael@0 | 61 | #endif /* ENUMSET_H */ |