Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
util::flags::FlagSet< NFlags, Storage > Class Template Reference

A class containing a set of flags. More...

#include <FlagSet.h>

Inheritance diagram for util::flags::FlagSet< NFlags, Storage >:
util::flags::BitMask< Storage >

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...
 
- Public Types inherited from util::flags::BitMask< Storage >
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
 
FlagSetoperator= (This_t const &)=default
 
FlagSetoperator= (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...
 
- Public Member Functions inherited from util::flags::BitMask< Storage >
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 Public Member Functions inherited from util::flags::BitMask< Storage >
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 Public Attributes inherited from util::flags::BitMask< Storage >
static constexpr auto fromValues = maskFromValues
 Constructor tag from values. More...
 

Detailed Description

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
class util::flags::FlagSet< NFlags, Storage >

A class containing a set of flags.


Template Parameters
NFlagsnumber of flags to be allocated
Storageunderlying 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.

Definition at line 41 of file FlagSet.h.

Member Typedef Documentation

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::Base_t = Mask_t

Type of the base class.

Definition at line 51 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::Bits_t = typename Mask_t::Bits_t

Type of bits for this flag set.

Definition at line 54 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::Exception = typename Mask_t::Exception

Generic BitMask exception.

Definition at line 67 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::Flag_t = typename Mask_t::Flag_t

Type identifying a single flag.

Definition at line 60 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::FlagIndex_t = typename Mask_t::FlagIndex_t

Type of index of flag.

Definition at line 57 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::FlagNotDefinedError = typename Mask_t::FlagNotDefinedError

Flag not defined.

Definition at line 73 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::Mask_t = BitMask<Storage>

Type of bit mask for this flag set.

Definition at line 49 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::OutOfRangeError = typename Mask_t::OutOfRangeError

Out-of-range flag index.

Definition at line 70 of file FlagSet.h.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
using util::flags::FlagSet< NFlags, Storage >::This_t = FlagSet<NFlags, Storage>

Type of this class.

Definition at line 47 of file FlagSet.h.

Constructor & Destructor Documentation

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
util::flags::FlagSet< NFlags, Storage >::FlagSet ( )
default
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
util::flags::FlagSet< NFlags, Storage >::FlagSet ( This_t const &  )
default
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
util::flags::FlagSet< NFlags, Storage >::FlagSet ( This_t &&  )
default
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
constexpr util::flags::FlagSet< NFlags, Storage >::FlagSet ( Mask_t const &  from)
inline

Constructor: copy the specified mask.

Definition at line 86 of file FlagSet.h.

86 : Base_t(from) {}
Mask_t Base_t
Type of the base class.
Definition: FlagSet.h:51

Member Function Documentation

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
template<typename... Args>
static constexpr Mask_t util::flags::FlagSet< NFlags, Storage >::createMask ( Args...  args)
inlinestatic

Creates a new BitMask.

Template Parameters
Argstypes of the arguments
Parameters
argsthe data to create the mask from
Returns
a BitMask with the features specified in the arguments

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.

183  { return Mask_t::create(args...); }
static QCString args
Definition: declinfo.cpp:674
static constexpr Mask_t create(Args...args)
Creates a new BitMask.
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
template<typename Stream >
void util::flags::FlagSet< NFlags, Storage >::dump ( Stream &&  out) const
inline

Dumps on screen only the "official" flags (see size()).

Definition at line 161 of file FlagSet.h.

162  { mask().dump(std::forward<Stream>(out), size()); }
void dump(Stream &&out, unsigned int nBits) const
Prints into the specified stream the least nBits significant bits.
constexpr Mask_t const & mask() const
Returns all the flags in the form of a mask.
Definition: FlagSet.h:97
static constexpr size_t size()
Returns the number of flags the set supports.
Definition: FlagSet.h:166
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
constexpr bool util::flags::FlagSet< NFlags, Storage >::isFlag ( FlagIndex_t  flagIndex) const

Returns whether the flag index is valid.

Parameters
flagIndexindex of the flag to check
Returns
whether the flag index is valid

Valid flag index values go from 0 up to the size (size()) of this flag set.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
constexpr bool util::flags::FlagSet< NFlags, Storage >::isFlag ( Flag_t  flag) const

Returns whether the flag index is valid.

Parameters
flagflag to check
Returns
whether the flag is valid

Valid flag index values go from 0 up to the size (size()) of this flag set.

Note
This method is unable to check flags that are beyond the capacity of the flag set itself. For example, in a flag set represented with 8 bits, the Flag_t value corresponding to flag #12 would be Flag_t(0x1000), which is beyond the range that Flag_t can represent.
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
constexpr Mask_t const& util::flags::FlagSet< NFlags, Storage >::mask ( ) const
inline

Returns all the flags in the form of a mask.

Definition at line 97 of file FlagSet.h.

97 { return *this; }
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
FlagSet& util::flags::FlagSet< NFlags, Storage >::operator= ( This_t const &  )
default
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
FlagSet& util::flags::FlagSet< NFlags, Storage >::operator= ( This_t &&  )
default
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
static constexpr size_t util::flags::FlagSet< NFlags, Storage >::size ( void  )
inlinestatic

Returns the number of flags the set supports.

Definition at line 166 of file FlagSet.h.

167  { return NFlags; }
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
bool util::flags::FlagSet< NFlags, Storage >::test ( Flag_t  flag) const

Returns if the specified flag is set.

Parameters
flagflag to test
Returns
whether the specified flag is set
Exceptions
FlagNotDefinedErrorif the flag was not defined at all
OutOfRangeErrorif 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.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
bool util::flags::FlagSet< NFlags, Storage >::test ( FlagIndex_t  flagIndex) const

Returns if the specified flag is set.

Parameters
flagIndexindex of the flag to test
Returns
whether the specified flag is set
Exceptions
FlagNotDefinedErrorif the flag was not defined at all
OutOfRangeErrorif 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.

template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
bool util::flags::FlagSet< NFlags, Storage >::testImpl ( Flag_t  flag) const
private

Implementation detail of test()


The documentation for this class was generated from the following file: