Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/enumset.h
48773 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3******************************************************************************4*5* Copyright (C) 2012,2014 International Business Machines6* Corporation and others. All Rights Reserved.7*8******************************************************************************9*/1011/**12* \file13* \brief C++: internal template EnumSet<>14*/1516#ifndef ENUMSET_H17#define ENUMSET_H1819#include "unicode/utypes.h"2021#if U_SHOW_CPLUSPLUS_API2223U_NAMESPACE_BEGIN2425/* Can't use #ifndef U_HIDE_INTERNAL_API for the entire EnumSet class, needed in .h file declarations */26/**27* enum bitset for boolean fields. Similar to Java EnumSet<>.28* Needs to range check. Used for private instance variables.29* @internal30* \cond31*/32template<typename T, uint32_t minValue, uint32_t limitValue>33class EnumSet {34public:35inline EnumSet() : fBools(0) {}36inline EnumSet(const EnumSet<T,minValue,limitValue>& other) : fBools(other.fBools) {}37inline ~EnumSet() {}38#ifndef U_HIDE_INTERNAL_API39inline void clear() { fBools=0; }40inline void add(T toAdd) { set(toAdd, 1); }41inline void remove(T toRemove) { set(toRemove, 0); }42inline int32_t contains(T toCheck) const { return get(toCheck); }43inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); }44inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; }45inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck<limitValue); }46inline UBool isValidValue(int32_t v) const { return (v==0||v==1); }47inline const EnumSet<T,minValue,limitValue>& operator=(const EnumSet<T,minValue,limitValue>& other) {48fBools = other.fBools;49return *this;50}5152inline uint32_t getAll() const {53return fBools;54}55#endif /* U_HIDE_INTERNAL_API */5657private:58inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); }59private:60uint32_t fBools;61};6263/** \endcond */6465U_NAMESPACE_END6667#endif /* U_SHOW_CPLUSPLUS_API */68#endif /* ENUMSET_H */697071