Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:04

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 ******************************************************************************
0005 *
0006 *   Copyright (C) 2012,2014 International Business Machines
0007 *   Corporation and others.  All Rights Reserved.
0008 *
0009 ******************************************************************************
0010 */
0011 
0012 /**
0013  * \file
0014  * \brief C++: internal template EnumSet<>
0015  */
0016 
0017 #ifndef ENUMSET_H
0018 #define ENUMSET_H
0019 
0020 #include "unicode/utypes.h"
0021 
0022 #if U_SHOW_CPLUSPLUS_API
0023 
0024 U_NAMESPACE_BEGIN
0025 
0026 /* Can't use #ifndef U_HIDE_INTERNAL_API for the entire EnumSet class, needed in .h file declarations */
0027 /**
0028  * enum bitset for boolean fields. Similar to Java EnumSet<>. 
0029  * Needs to range check. Used for private instance variables.
0030  * @internal
0031  * \cond
0032  */
0033 template<typename T, uint32_t minValue, uint32_t limitValue>
0034 class EnumSet {
0035 public:
0036     inline EnumSet() : fBools(0) {}
0037     inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}
0038     inline ~EnumSet() {}
0039 #ifndef U_HIDE_INTERNAL_API
0040     inline void clear() { fBools=0; }
0041     inline void add(T toAdd) { set(toAdd, 1); }
0042     inline void remove(T toRemove) { set(toRemove, 0); }
0043     inline int32_t contains(T toCheck) const { return get(toCheck); }
0044     inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }
0045     inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }
0046     inline UBool isValidEnum(T toCheck) const {  return (toCheck>=minValue&&toCheck<limitValue); }
0047     inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }
0048     inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {
0049         fBools = other.fBools;
0050         return *this;
0051     }
0052   
0053     inline uint32_t getAll() const {
0054         return fBools; 
0055     }
0056 #endif /* U_HIDE_INTERNAL_API */
0057 
0058 private:
0059     inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }
0060 private:
0061     uint32_t fBools;
0062 };
0063 
0064 /** \endcond */
0065 
0066 U_NAMESPACE_END
0067 
0068 #endif /* U_SHOW_CPLUSPLUS_API */
0069 #endif /* ENUMSET_H */