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). | |
FlagSet (const std::initializer_list< T > &_list) | |
Construct a FlagSet with the given flags set and all other unset. | |
FlagSet (const T &_val) | |
Construct a FlagSet with the given flag set and all other unset. | |
bool | All () const |
Test whether all flags are set. | |
bool | Any () const |
Test whether any flag is set. | |
std::size_t | Count () const |
Return the number of flags set to true. | |
FlagSet & | Flip () |
Set all flags to their negation. | |
FlagSet & | Flip (const T &_val) |
Negate the given flag. | |
size_t | Hash () const |
Compute hash of the FlagSet. | |
bool | None () const |
Test whether no flag is set. | |
operator bool () const | |
Return true if at least one flag is set to true. | |
bool | operator!= (const FlagSet &_o) const |
Test FlagSet inequality. | |
FlagSet | operator& (const FlagSet &_val) const |
Return a bit AND of this FlagSet and the argument. | |
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). | |
FlagSet & | operator&= (const FlagSet &_o) noexcept |
Return a bit AND of this FlagSet and the argument. | |
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). | |
bool | operator== (const FlagSet &_o) const |
Test FlagSet equality. | |
constexpr bool | operator[] (const T &_val) const |
Return whether the given flag is set. | |
FlagSet | operator| (const FlagSet &_val) const |
Return a bit OR of this FlagSet and the argument. | |
FlagSet | operator| (const T &_val) const |
Return a FlagSet with the given flag set to true. | |
FlagSet & | operator|= (const FlagSet &_o) noexcept |
Return a bit OR of this FlagSet and the argument. | |
FlagSet & | operator|= (const T &_val) noexcept |
Set the given flag to true in this FlagSet. | |
FlagSet | operator~ () const |
Return a negation of this FlagSet. | |
FlagSet & | Reset () |
Set all flags to false. | |
FlagSet & | Reset (const T &_val) |
Set the given flag to false. | |
FlagSet & | Set () |
Set all flags to true. | |
FlagSet & | Set (const T &_val, bool _value=true) |
Set the given flag to the specified value. | |
std::size_t | Size () const |
Return the total number of flags represented by this FlagSet. | |
std::string | String () const |
Return a string describing this FlagSet. | |
Static Public Member Functions | |
static FlagSet | AllSet () |
Retrurn a FlagSet with all flags set to true. | |
static FlagSet | NoneSet () |
Retrurn a FlagSet with all flags set to false. | |
Static Public Attributes | |
static constexpr size_t | numElements |
Number of elements of the bitset. | |
Detailed Description
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(), and FlagSet< T, LastElement, ExcludeLast >::Set().
◆ 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 all flags to true.
- Returns
- This.
References bitset< Bits >::set().
Referenced by FlagSet< T, LastElement, ExcludeLast >::AllSet().
◆ 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: