A class containing a set of flags. More...
#include <FlagSet.h>
Public Types | |
using | This_t = FlagSet< NFlags, Storage > |
Type of this class. More... | |
using | Mask_t = BitMask< Storage > |
Type of bit mask for this flag set. More... | |
using | Base_t = Mask_t |
Type of the base class. More... | |
using | Bits_t = typename Mask_t::Bits_t |
Type of bits for this flag set. More... | |
using | FlagIndex_t = typename Mask_t::FlagIndex_t |
Type of index of flag. More... | |
using | Flag_t = typename Mask_t::Flag_t |
Type identifying a single flag. More... | |
Exceptions | |
using | Exception = typename Mask_t::Exception |
Generic BitMask exception. More... | |
using | OutOfRangeError = typename Mask_t::OutOfRangeError |
Out-of-range flag index. More... | |
using | FlagNotDefinedError = typename Mask_t::FlagNotDefinedError |
Flag not defined. More... | |
![]() | |
using | Mask_t = BitMask< Storage > |
This type. More... | |
using | FlagIndex_t = util::flags::Index_t |
Type of index of flag. More... | |
using | Bits_t = util::flags::Bits_t< Storage_t > |
Set of bits. More... | |
using | Flag_t = typename Bits_t::Flag_t |
Type identifying a single flag. More... | |
using | Exception = errors::Exception |
Generic BitMask exception. More... | |
using | OutOfRangeError = errors::OutOfRange |
Out-of-range flag index. More... | |
using | FlagNotDefinedError = errors::FlagNotDefined |
Flag not defined. More... | |
Public Member Functions | |
FlagSet ()=default | |
FlagSet (This_t const &)=default | |
FlagSet (This_t &&)=default | |
FlagSet & | operator= (This_t const &)=default |
FlagSet & | operator= (This_t &&)=default |
constexpr | FlagSet (Mask_t const &from) |
Constructor: copy the specified mask. More... | |
template<typename Stream > | |
void | dump (Stream &&out) const |
Dumps on screen only the "official" flags (see size() ). More... | |
Access to flags | |
constexpr Mask_t const & | mask () const |
Returns all the flags in the form of a mask. More... | |
constexpr bool | isFlag (FlagIndex_t flagIndex) const |
Returns whether the flag index is valid. More... | |
constexpr bool | isFlag (Flag_t flag) const |
Returns whether the flag index is valid. More... | |
bool | test (Flag_t flag) const |
Returns if the specified flag is set. More... | |
bool | test (FlagIndex_t flagIndex) const |
Returns if the specified flag is set. More... | |
![]() | |
constexpr bool | operator== (Mask_t const &other) const |
constexpr bool | operator!= (Mask_t const &other) const |
template<typename Stream > | |
void | dump (Stream &&out, unsigned int nBits) const |
Prints into the specified stream the least nBits significant bits. More... | |
template<typename Stream > | |
void | dump (Stream &&out) const |
Prints into the specified stream all bits. More... | |
constexpr | BitMask ()=default |
Default constructor: no flag defined at all. More... | |
constexpr | BitMask (BitMaskFromValuesTag, Storage_t defined) |
Constructor: defines and sets flags. More... | |
constexpr | BitMask (BitMaskFromValuesTag, Storage_t defined, Storage_t values) |
Constructor: defines and sets flags. More... | |
constexpr | BitMask (BitMaskFromValuesTag, Bits_t values) |
Constructor: defines and sets flags. More... | |
constexpr | BitMask (BitMaskFromValuesTag, Bits_t defined, Bits_t values) |
Constructor: defines and sets flags. More... | |
template<typename... Others> | |
constexpr | BitMask (Flag_t first, Others...others) |
Constructor: merges all arguments in the argument list. More... | |
template<typename... Others> | |
constexpr | BitMask (Bits_t first, Others...others) |
Constructor: merges all arguments in the argument list. More... | |
template<typename Second , typename... Others> | |
constexpr | BitMask (Mask_t first, Second second, Others...others) |
Constructor: merges all arguments in the argument list. More... | |
constexpr bool | isDefined (Flag_t flag) const |
Returns whether the flag is defined. More... | |
constexpr bool | isDefined (Bits_t bits) const |
Returns whether all specified bits are defined. More... | |
constexpr bool | isUndefined (Flag_t flag) const |
Returns whether the flag is undefined. More... | |
constexpr bool | isUndefined (Bits_t bits) const |
Returns whether all specified bits are undefined. More... | |
constexpr bool | get (Flag_t flag) const |
Returns if the specified flag is on ("set"). More... | |
constexpr bool | isSet (Flag_t flag) const |
Returns if the specified flag is set. More... | |
constexpr bool | isUnset (Flag_t flag) const |
Returns if the specified flag is unset. More... | |
constexpr bool | all (Bits_t bits) const |
Returns whether all the specified bits are set. More... | |
constexpr bool | any (Bits_t bits) const |
Returns whether at least one of the specified bits is set. More... | |
constexpr bool | none (Bits_t bits) const |
Returns whether all the specified bits are unset. More... | |
constexpr bool | anySet (Mask_t const &mask) const |
Returns whether any of the bits set in the mask are set. More... | |
constexpr bool | noneSet (Mask_t const &mask) const |
Returns whether none of the bits set in the mask is set. More... | |
constexpr bool | match (Mask_t const &mask) const |
Returns whether all bits defined in the mask are equal to ours. More... | |
template<typename Flag , typename... OtherFlags> | |
void | set (Flag first, OtherFlags...others) |
Sets all specified flags. More... | |
template<typename BeginIter , typename EndIter > | |
void | rangeSet (BeginIter begin, EndIter end) |
Sets all flags specified by the index iterator range. More... | |
template<typename Flag , typename... OtherFlags> | |
void | unset (Flag first, OtherFlags...others) |
Unsets all specified flags. More... | |
template<typename BeginIter , typename EndIter > | |
void | rangeUnset (BeginIter begin, EndIter end) |
Unsets all flags specified by the index iterator range. More... | |
template<typename Flag , typename... OtherFlags> | |
void | remove (Flag first, OtherFlags...others) |
Declares all specified flags as undefined. More... | |
void | clear () |
Undefines all bits. More... | |
Static Public Member Functions | |
static constexpr size_t | size () |
Returns the number of flags the set supports. More... | |
template<typename... Args> | |
static constexpr Mask_t | createMask (Args...args) |
Creates a new BitMask. More... | |
![]() | |
static constexpr size_t | capacity () |
Returns the number of flags the set has room for. More... | |
template<typename... Args> | |
static constexpr Mask_t | create (Args...args) |
Creates a new BitMask. More... | |
static constexpr Mask_t | mergeIntoMask (Mask_t baseMask, Mask_t mask) |
Returns a new mask with the content of the other mask merged. More... | |
static constexpr Mask_t | mergeIntoMask (Mask_t baseMask, Bits_t bits) |
Returns a new mask with the specified bits defined and set. More... | |
static constexpr Mask_t | mergeIntoMask (Mask_t baseMask, Flag_t flag) |
Returns a new mask with the specified flag defined and set. More... | |
static constexpr Mask_t | combineWithMask (Mask_t A, Mask_t B) |
Returns a new mask combining bits set from two masks. More... | |
static constexpr Mask_t | combineWithMask (Mask_t baseMask, Bits_t bits) |
Returns a new mask with the specified flag defined and set. More... | |
static constexpr Mask_t | combineWithMask (Mask_t baseMask, Flag_t flag) |
Returns a new mask with the specified flag defined and set. More... | |
static constexpr Mask_t | intersectWithMask (Mask_t A, Mask_t B) |
Returns a new mask with the bits set from both masks. More... | |
static constexpr Mask_t | intersectWithMask (Mask_t baseMask, Bits_t bits) |
Returns a new mask with only the specified bits set. More... | |
static constexpr Mask_t | intersectWithMask (Mask_t baseMask, Flag_t flag) |
Returns a new mask with the specified flag as only set flag. More... | |
static constexpr Mask_t | unsetMask (Mask_t baseMask, Mask_t mask) |
Returns a new mask with the bits set from both masks. More... | |
static constexpr Mask_t | unsetMask (Mask_t baseMask, Bits_t bits) |
Returns a new mask with only the specified bits set. More... | |
static constexpr Mask_t | unsetMask (Mask_t baseMask, Flag_t flag) |
Returns a new mask with the specified flag as only set flag. More... | |
static constexpr Mask_t | negateMask (Mask_t mask) |
Returns the negation of mask. More... | |
static constexpr Mask_t | negateMask (Bits_t bits) |
Returns a new mask with the specified bits unset. More... | |
static constexpr Mask_t | negateMask (Flag_t flag) |
Returns a new mask with the specified flag unset. More... | |
Private Member Functions | |
bool | testImpl (Flag_t flag) const |
Implementation detail of test() More... | |
Additional Inherited Members | |
![]() | |
static constexpr auto | fromValues = maskFromValues |
Constructor tag from values. More... | |
A class containing a set of flags.
NFlags | number of flags to be allocated |
Storage | underlying integral type whose bits represent the flags |
A FlagSet contains a set of flags. Each flag can be in one of two states ("set" and "unset"), or can be not defined at all ("undefined").
Note that the object might have a capacity()
larger than just NFlags
. The flags after the first NFlags
are "unsupported", in the sense that in future implementations they might disappear. For the rest, they behave just like the other flags though.
using util::flags::FlagSet< NFlags, Storage >::Base_t = Mask_t |
using util::flags::FlagSet< NFlags, Storage >::Bits_t = typename Mask_t::Bits_t |
using util::flags::FlagSet< NFlags, Storage >::Exception = typename Mask_t::Exception |
using util::flags::FlagSet< NFlags, Storage >::Flag_t = typename Mask_t::Flag_t |
using util::flags::FlagSet< NFlags, Storage >::FlagIndex_t = typename Mask_t::FlagIndex_t |
using util::flags::FlagSet< NFlags, Storage >::FlagNotDefinedError = typename Mask_t::FlagNotDefinedError |
using util::flags::FlagSet< NFlags, Storage >::Mask_t = BitMask<Storage> |
using util::flags::FlagSet< NFlags, Storage >::OutOfRangeError = typename Mask_t::OutOfRangeError |
using util::flags::FlagSet< NFlags, Storage >::This_t = FlagSet<NFlags, Storage> |
|
default |
|
default |
|
default |
|
inline |
|
inlinestatic |
Creates a new BitMask.
Args | types of the arguments |
args | the data to create the mask from |
If no argument is provided, the mask is returned with all the flags undefined (like in default constructor). For the details, see BitMask<Storage>::createMask()
.
Definition at line 182 of file FlagSet.h.
|
inline |
Dumps on screen only the "official" flags (see size()
).
Definition at line 161 of file FlagSet.h.
constexpr bool util::flags::FlagSet< NFlags, Storage >::isFlag | ( | FlagIndex_t | flagIndex | ) | const |
Returns whether the flag index is valid.
flagIndex | index of the flag to check |
Valid flag index values go from 0 up to the size (size()
) of this flag set.
constexpr bool util::flags::FlagSet< NFlags, Storage >::isFlag | ( | Flag_t | flag | ) | const |
Returns whether the flag index is valid.
flag | flag to check |
Valid flag index values go from 0 up to the size (size()
) of this flag set.
|
inline |
|
default |
|
default |
|
inlinestatic |
bool util::flags::FlagSet< NFlags, Storage >::test | ( | Flag_t | flag | ) | const |
Returns if the specified flag is set.
flag | flag to test |
FlagNotDefinedError | if the flag was not defined at all |
OutOfRangeError | if the flag index denotes a non-existing flag |
This method provides a checked access to a single flag value. If the flag is not supported (see isFlag()
), or if it is isUndefined()
, an exception is thrown.
See get()
for an unchecked access.
bool util::flags::FlagSet< NFlags, Storage >::test | ( | FlagIndex_t | flagIndex | ) | const |
Returns if the specified flag is set.
flagIndex | index of the flag to test |
FlagNotDefinedError | if the flag was not defined at all |
OutOfRangeError | if the flag index denotes a non-existing flag |
This method provides a checked access to a single flag value. If the flag is not supported (see isFlag()
), or if it is isUndefined()
, an exception is thrown.
See get()
for an unchecked access.
|
private |
Implementation detail of test()