Set of flags defined by a C++11 enum class. More...
#include <FlagSet.hh>
Public Member Functions | |
FlagSet ()=default | |
Create an empty FlagSet (no flags set). More... | |
FlagSet (const std::initializer_list< T > &_list) | |
Construct a FlagSet with the given flags set and all other unset. More... | |
FlagSet (const T &_val) | |
Construct a FlagSet with the given flag set and all other unset. More... | |
bool | All () const |
Test whether all flags are set. More... | |
bool | Any () const |
Test whether any flag is set. More... | |
std::size_t | Count () const |
Return the number of flags set to true. More... | |
FlagSet & | Flip () |
Set all flags to their negation. More... | |
FlagSet & | Flip (const T &_val) |
Negate the given flag. More... | |
size_t | Hash () const |
Compute hash of the FlagSet. More... | |
bool | None () const |
Test whether no flag is set. More... | |
operator bool () const | |
Return true if at least one flag is set to true. More... | |
bool | operator!= (const FlagSet &_o) const |
Test FlagSet inequality. More... | |
FlagSet | operator& (const FlagSet &_val) const |
Return a bit AND of this FlagSet and the argument. More... | |
FlagSet | operator& (const T &_val) const |
Return a FlagSet with only the given flag set (or even this one unset if it wasn't set in this FlagSet before). More... | |
FlagSet & | operator&= (const FlagSet &_o) noexcept |
Return a bit AND of this FlagSet and the argument. More... | |
FlagSet & | operator&= (const T &_val) noexcept |
Return a FlagSet with only the given flag set (or even this one unset if it wasn't set in this FlagSet before). More... | |
bool | operator== (const FlagSet &_o) const |
Test FlagSet equality. More... | |
constexpr bool | operator[] (const T &_val) const |
Return whether the given flag is set. More... | |
FlagSet | operator| (const FlagSet &_val) const |
Return a bit OR of this FlagSet and the argument. More... | |
FlagSet | operator| (const T &_val) const |
Return a FlagSet with the given flag set to true. More... | |
FlagSet & | operator|= (const FlagSet &_o) noexcept |
Return a bit OR of this FlagSet and the argument. More... | |
FlagSet & | operator|= (const T &_val) noexcept |
Set the given flag to true in this FlagSet. More... | |
FlagSet | operator~ () const |
Return a negation of this FlagSet. More... | |
FlagSet & | Reset () |
Set all flags to false. More... | |
FlagSet & | Reset (const T &_val) |
Set the given flag to false. More... | |
FlagSet & | Set () |
Set all flags to true. More... | |
FlagSet & | Set (const T &_val, bool _value=true) |
Set the given flag to the specified value. More... | |
std::size_t | Size () const |
Return the total number of flags represented by this FlagSet. More... | |
std::string | String () const |
Return a string describing this FlagSet. More... | |
Static Public Member Functions | |
static FlagSet | AllSet () |
Retrurn a FlagSet with all flags set to true. More... | |
static FlagSet | NoneSet () |
Retrurn a FlagSet with all flags set to false. More... | |
Static Public Attributes | |
static constexpr size_t | numElements |
Number of elements of the bitset. More... | |
Detailed Description
template<typename T, T LastElement = T::_, bool ExcludeLast = true>
class gz::common::FlagSet< T, LastElement, ExcludeLast >
Set of flags defined by a C++11 enum class.
- Note
- If the enum's last element is '_' (just underscore), the convenience signature can be used specifying just the enum type (the underscore will be automatically used as LastElement, and will be excluded from the list of valid values).
- FlagSet only works for enums that do not contain negative values.
- The underlying bitset representing this FlagSet will have as many bits as is the size_t value of LastElement (+- 1). Be aware of that when calling Count(), Size() etc. Also be aware of that when creating a FlagSet of an enum that would contain very high numbers in the underlying representation.
- Template Parameters
-
T The enum class type. The underlying type of the enum has to be convertible to size_t. LastElement Last element of the enum. If the enum's last element is '_' (just underscore), it can be deduced automatically. ExcludeLast If true, LastElement is considered as an element beyond all valid elements and will not be treated as a valid value of the FlagSet. If false, the last element is treated as a valid value.
Constructor & Destructor Documentation
◆ FlagSet() [1/3]
|
default |
Create an empty FlagSet (no flags set).
Referenced by FlagSet< T, LastElement, ExcludeLast >::AllSet(), and FlagSet< T, LastElement, ExcludeLast >::NoneSet().
◆ FlagSet() [2/3]
|
inline |
Construct a FlagSet with the given flag set and all other unset.
- Parameters
-
[in] _val The flag to set.
- Note
- This is intentionally not an explicit constructor so that values of the enum can be implicitly converted to a FlagSet with just the one value set.
References bitset< Bits >::set().
◆ FlagSet() [3/3]
|
inlineexplicit |
Construct a FlagSet with the given flags set and all other unset.
- Parameters
-
[in] _list The list of flags to set.
References bitset< Bits >::set().
Member Function Documentation
◆ All()
|
inline |
Test whether all flags are set.
- Returns
- True if at all flags are set to true.
References bitset< Bits >::all().
◆ AllSet()
|
inlinestatic |
Retrurn a FlagSet with all flags set to true.
References FlagSet< T, LastElement, ExcludeLast >::FlagSet().
◆ Any()
|
inline |
Test whether any flag is set.
- Returns
- True if at least one flag is set to true.
References bitset< Bits >::any().
◆ Count()
|
inline |
Return the number of flags set to true.
- Returns
- The number of true flags in this FlagSet.
- See also
- Size()
References bitset< Bits >::count().
◆ Flip() [1/2]
|
inline |
◆ Flip() [2/2]
|
inline |
Negate the given flag.
- Parameters
-
[in] _val The flag to negate.
- Returns
- This.
References bitset< Bits >::flip().
◆ Hash()
|
inline |
Compute hash of the FlagSet.
- Returns
- The hash.
◆ None()
|
inline |
Test whether no flag is set.
- Returns
- True if at no flag is set to true.
References bitset< Bits >::none().
◆ NoneSet()
|
inlinestatic |
Retrurn a FlagSet with all flags set to false.
References FlagSet< T, LastElement, ExcludeLast >::FlagSet().
◆ operator bool()
|
inlineexplicit |
Return true if at least one flag is set to true.
- Returns
- Whether at least one flag is set.
References bitset< Bits >::any().
◆ operator!=()
|
inline |
◆ operator&() [1/2]
◆ operator&() [2/2]
|
inline |
Return a FlagSet with only the given flag set (or even this one unset if it wasn't set in this FlagSet before).
- Parameters
-
[in] _val The flag to set.
- Returns
- The new FlagSet.
- Note
- The resulting bitset can contain at most 1 bit set to true.
References bitset< Bits >::count().
◆ operator&=() [1/2]
◆ operator&=() [2/2]
|
inlinenoexcept |
Return a FlagSet with only the given flag set (or even this one unset if it wasn't set in this FlagSet before).
- Parameters
-
[in] _val The flag to set.
- Returns
- This.
References bitset< Bits >::reset(), bitset< Bits >::set(), and bitset< Bits >::test().
◆ operator==()
|
inline |
◆ operator[]()
|
inlineconstexpr |
Return whether the given flag is set.
- Parameters
-
[in] _val The flag to test.
- Returns
- Whether the flag is set.
- Note
- This only works for enums whose underlying type is unsigned.
◆ operator|() [1/2]
◆ operator|() [2/2]
|
inline |
Return a FlagSet with the given flag set to true.
- Parameters
-
[in] _val The flag to set.
- Returns
- The new FlagSet.
- Note
- The resulting bitset contains at least 1 bit set to true.
References bitset< Bits >::count().
◆ operator|=() [1/2]
◆ operator|=() [2/2]
|
inlinenoexcept |
Set the given flag to true in this FlagSet.
- Parameters
-
[in] _val The flag to set.
- Returns
- This.
References bitset< Bits >::set().
◆ operator~()
|
inline |
◆ Reset() [1/2]
|
inline |
◆ Reset() [2/2]
|
inline |
Set the given flag to false.
- Parameters
-
[in] _val The flag to set.
- Returns
- This.
References bitset< Bits >::reset().
◆ Set() [1/2]
|
inline |
◆ Set() [2/2]
|
inline |
Set the given flag to the specified value.
- Parameters
-
[in] _val The flag to set. [in] _value The value to set.
- Returns
- This.
References bitset< Bits >::set().
◆ Size()
|
inline |
Return the total number of flags represented by this FlagSet.
- Note
- This corresponds to the value of the '_' element of the enum.
- Returns
- The number of flags in this FlagSet.
- See also
- Count()
References bitset< Bits >::size().
◆ String()
|
inline |
Member Data Documentation
◆ numElements
|
staticconstexpr |
Number of elements of the bitset.
The documentation for this class was generated from the following file: