LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 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...
 
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...
 
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...
 
Access to flags
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...
 
Setting flags
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...
 
Number of flags
static constexpr size_t capacity ()
 Returns the number of flags the set has room for. More...
 
Static mask manipulation
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...
 

Static Public Attributes

static constexpr auto fromValues = maskFromValues
 Constructor tag from values. More...
 

Private Member Functions

bool testImpl (Flag_t flag) const
 Implementation detail of test() 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 40 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 50 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 53 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 65 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 59 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 56 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 71 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 48 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 68 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 46 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 83 of file FlagSet.h.

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

Member Function Documentation

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::all ( Bits_t  bits) const
inherited

Returns whether all the specified bits are set.

Parameters
bitsbits to check
Returns
whether all bits are set
See also
isSet(Flag_t)

This method is equivalent to calling isSet(Flag_t) on each single flag defined in bits. The result is true only if all of them are set, that includes all of them being defined.

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::any ( Bits_t  bits) const
inherited

Returns whether at least one of the specified bits is set.

Parameters
bitsbits to check
Returns
whether any of the bits is set
See also
isSet(Flag_t)

This method is equivalent to calling isSet(Flag_t) on each single flag defined in bits. The result is true only if at least one of them is set (including that one being defined).

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::anySet ( Mask_t const &  mask) const
inherited

Returns whether any of the bits set in the mask are set.

Parameters
maskthe mask of bits
Returns
whether we have any of those bits set
See also
noneSet(), match()

The bits that are undefined in mask are not used to compute the result.

template<typename Storage>
static constexpr size_t util::flags::BitMask< Storage >::capacity ( )
staticinherited

Returns the number of flags the set has room for.

template<typename Storage>
void util::flags::BitMask< Storage >::clear ( )
inlineinherited

Undefines all bits.

Definition at line 799 of file BitMask.h.

References util::values().

800  {
801  presence.clear();
802  values.clear();
803  }
void clear()
Unsets all bits.
Definition: BitMask.h:263
Bits_t values
Storage of value bits.
Definition: BitMask.h:1125
Bits_t presence
Storage of definition bits.
Definition: BitMask.h:1126
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::combineWithMask ( Mask_t  A,
Mask_t  B 
)
staticinherited

Returns a new mask combining bits set from two masks.

Parameters
Aone of the masks to be combined
Bthe other mask to be combined
Returns
a new mask with all set bits from of the two masks

The content of the new mask has a bit set if it was set (isSet()) in either of the masks, otherwise unset if it was unset (isUnset()) in either of the masks, or else undefined (isUndefined()), as it was undefined in both masks.

The result differs from mergeIntoMask() only for bits which are set (isSet()) in the first mask but unset (isUnset()) in the second: combineWithMask() will leave the bit set, like in the first mask, while mergeIntoMask() would have that bit always unset.

This is equivalent to a flagwise OR operation.

The truth table of the operation is described in the following table, where '-' represents an undefined flag (isUndefined()), '0' an unset flag (isUnset()), and '1' a set flag (isSet()).

B - 0 1
A
- - 0 1
0 0 0 1
1 1 1 1
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::combineWithMask ( Mask_t  baseMask,
Bits_t  bits 
)
staticinherited

Returns a new mask with the specified flag defined and set.

Parameters
baseMaskthe starting mask
bitsthe bits to be set
Returns
a new mask with all content from baseMask, plus the flag bit set

The truth table of this operation follows (see mergeIntoMask() for its legend).

bits 0 1
baseMask
- - 1
0 0 1
1 1 1
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::combineWithMask ( Mask_t  baseMask,
Flag_t  flag 
)
staticinherited

Returns a new mask with the specified flag defined and set.

Parameters
baseMaskthe starting mask
flagthe single flag to be set
Returns
a new mask with all content from baseMask, plus the bits set
template<typename Storage>
template<typename... Args>
static constexpr Mask_t util::flags::BitMask< Storage >::create ( Args...  args)
staticinherited

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). The order of the arguments matters: the first arguments are processed first and their effect can be overridden by the following arguments. For the details, see mergeIntoMask(), which is used to incrementally merge the argument to create the result.

Referenced by util::flags::FlagSet< NFlags, Storage >::createMask().

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 173 of file FlagSet.h.

References util::flags::BitMask< Storage >::create(), and util::flags::FlagSet< NFlags, Storage >::testImpl().

174  {
175  return Mask_t::create(args...);
176  }
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 153 of file FlagSet.h.

References util::flags::BitMask< Storage >::dump(), util::flags::FlagSet< NFlags, Storage >::mask(), and util::flags::FlagSet< NFlags, Storage >::size().

154  {
155  mask().dump(std::forward<Stream>(out), size());
156  }
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:91
static constexpr size_t size()
Returns the number of flags the set supports.
Definition: FlagSet.h:159
template<typename Storage>
template<typename Stream >
void util::flags::BitMask< Storage >::dump ( Stream &&  out,
unsigned int  nBits 
) const
inherited

Prints into the specified stream the least nBits significant bits.

Referenced by util::flags::FlagSet< NFlags, Storage >::dump().

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::get ( Flag_t  flag) const
inherited

Returns if the specified flag is on ("set").

Parameters
flagindex of the flag to test
Returns
whether the specified flag is set

This method provides an unchecked access to a single flag value. If the flag is isUndefined(), the behaviour of this method is also undefined.

template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::intersectWithMask ( Mask_t  A,
Mask_t  B 
)
staticinherited

Returns a new mask with the bits set from both masks.

Parameters
Aone of the masks to be combined
Bthe other mask to be combined
Returns
a new mask with all bits set in both masks

The content of the new mask has a bit set if it was set (isSet()) in both masks, otherwise unset if it was unset (isUnset()) in either of the masks, or else undefined (isUndefined()), as it was undefined in both masks.

This is equivalent to a flagwise AND operation.

The truth table of the operation is described in the following table, where '-' represents an undefined flag (isUndefined()), '0' an unset flag (isUnset()), and '1' a set flag (isSet()).

B - 0 1
A
- - 0 1
0 0 0 0
1 1 0 1
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::intersectWithMask ( Mask_t  baseMask,
Bits_t  bits 
)
staticinherited

Returns a new mask with only the specified bits set.

Parameters
baseMaskthe starting mask
bitsthe bits to be set
Returns
a new mask with all defined flags from baseMask, with only the specified bits set

All bits in the argument are also defined.

The truth table of this operation follows (see mergeIntoMask() for its legend).

bits 0 1
baseMask
- - 1
0 0 0
1 0 1
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::intersectWithMask ( Mask_t  baseMask,
Flag_t  flag 
)
staticinherited

Returns a new mask with the specified flag as only set flag.

Parameters
baseMaskthe starting mask
flagthe single flag to be set
Returns
a new mask with all flags from baseMask, with only flag set
template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::isDefined ( Flag_t  flag) const
inherited

Returns whether the flag is defined.

Parameters
flagindex of the flag to check
Returns
whether the flag is defined

A flag must be defined before it can be used. A common convention is to use the "undefined" state of the flag to denote that its value is currently unknown.

A flag is defined by setting (set()) or unsetting (unset()) it.

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::isDefined ( Bits_t  bits) const
inherited

Returns whether all specified bits are defined.

Parameters
bitsbits to check
Returns
whether all bits set in bits are defined
See also
isDefined(Flag_t)

This method is equivalent to calling isDefined(Flag_t) on each single flag defined in bits. The result is true only if all of them are defined.

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.

Referenced by util::flags::FlagSet< NFlags, Storage >::mask().

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<typename Storage>
constexpr bool util::flags::BitMask< Storage >::isSet ( Flag_t  flag) const
inherited

Returns if the specified flag is set.

Parameters
flagindex of the flag to test
Returns
whether the specified flag is set

This method provides an unchecked access to a single flag value. If the flag is isUndefined(), the behaviour of this method is also undefined.

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::isUndefined ( Flag_t  flag) const
inherited

Returns whether the flag is undefined.

Parameters
flagindex of the flag to check
Returns
whether the flag is undefined
See also
isUndefined()

This is exactly the negation of isDefined().

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::isUndefined ( Bits_t  bits) const
inherited

Returns whether all specified bits are undefined.

Parameters
bitsbits to check
Returns
whether all bits set in bits are undefined
See also
isDefined(Bits_t), isUndefined(Flag_t)

This is exactly the negation of isDefined().

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::isUnset ( Flag_t  flag) const
inherited

Returns if the specified flag is unset.

Parameters
flagindex of the flag to test
Returns
whether the specified flag is unset

This method provides an unchecked access to a single flag value. If the flag is isUndefined(), the behaviour of this method is also undefined.

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 91 of file FlagSet.h.

References util::flags::FlagSet< NFlags, Storage >::isFlag(), and util::flags::FlagSet< NFlags, Storage >::test().

Referenced by util::flags::FlagSet< NFlags, Storage >::dump().

91 { return *this; }
template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::match ( Mask_t const &  mask) const
inherited

Returns whether all bits defined in the mask are equal to ours.

Parameters
maskthe mask of bits
Returns
whether the mask matches ours

The flags that are undefined in mask are not used to compute the result. If all the flags that are set in mask (isSet()) are set in this object, and likewise all the flags that are unset in mask (isUnset()) are unset, this method returns true.

template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::mergeIntoMask ( Mask_t  baseMask,
Mask_t  mask 
)
staticinherited

Returns a new mask with the content of the other mask merged.

Parameters
baseMaskthe starting mask
maskthe bits to be set
Returns
a new mask with all the content of base and the new mask

The content of the new mask overrides the base one: if a flag is defined in mask, it is defined and copied into the result, otherwise the state of the flag is copied from baseMask.

The truth table of the operation is described in the following table, where '-' represents an undefined flag (isUndefined()), '0' an unset flag (isUnset()), and '1' a set flag (isSet()).

mask - 0 1
baseMask
- - 0 1
0 0 0 1
1 1 0 1
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::mergeIntoMask ( Mask_t  baseMask,
Bits_t  bits 
)
staticinherited

Returns a new mask with the specified bits defined and set.

Parameters
baseMaskthe starting mask
bitsthe bits to be set
Returns
a new mask with all content from baseMask, plus the flag bit set

The truth table of this operation follows (see mergeIntoMask() for its legend).

bits 0 1
baseMask
- - 1
0 0 1
1 1 1
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::mergeIntoMask ( Mask_t  baseMask,
Flag_t  flag 
)
staticinherited

Returns a new mask with the specified flag defined and set.

Parameters
baseMaskthe starting mask
flagthe single flag to be set
Returns
a new mask with all content from baseMask, plus the flag bit set
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::negateMask ( Mask_t  mask)
staticinherited

Returns the negation of mask.

Parameters
maskthe starting mask
Returns
a new mask with all defined bits flipped

The bits which were undefined, stay so. The others change their value.

The truth table of this operation follows (see mergeIntoMask() for its legend).

mask negate()
- -
0 1
1 0
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::negateMask ( Bits_t  bits)
staticinherited

Returns a new mask with the specified bits unset.

Parameters
bitsbits to be unset
Returns
a new mask with the specified bits unset

Only the unset bits are defined.

template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::negateMask ( Flag_t  flag)
staticinherited

Returns a new mask with the specified flag unset.

Parameters
flagthe single flag to be set
Returns
a new mask with only the flag bit defined, and unset
template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::none ( Bits_t  bits) const
inherited

Returns whether all the specified bits are unset.

Parameters
bitsbits to check
Returns
whether all bits are unset
See also
isUnset(Flag_t)

This method is equivalent to calling isUnset(Flag_t) on each single flag defined in bits. The result is true only if all of them are unset, that includes all of them being defined.

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::noneSet ( Mask_t const &  mask) const
inherited

Returns whether none of the bits set in the mask is set.

Parameters
maskthe mask of bits
Returns
whether we have any of those bits set
See also
anySet(), match()

This is the logical negation of anySet().

template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::operator!= ( Mask_t const &  other) const
inlineinherited

Comparison: not all flags must be the same

Bug:
Also the value of undefined flags is currently checked

Definition at line 827 of file BitMask.h.

References util::flags::BitMask< Storage >::presence, util::values(), and util::flags::BitMask< Storage >::values.

828  {
829  return (values != other.values) || (presence != other.presence);
830  }
Bits_t values
Storage of value bits.
Definition: BitMask.h:1125
Bits_t presence
Storage of definition bits.
Definition: BitMask.h:1126
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<typename Storage>
constexpr bool util::flags::BitMask< Storage >::operator== ( Mask_t const &  other) const
inlineinherited

Comparison: all flags must be the same

Bug:
Also the value of undefined flags is currently checked

Definition at line 820 of file BitMask.h.

References util::flags::BitMask< Storage >::presence, util::values(), and util::flags::BitMask< Storage >::values.

821  {
822  return (values == other.values) && (presence == other.presence);
823  }
Bits_t values
Storage of value bits.
Definition: BitMask.h:1125
Bits_t presence
Storage of definition bits.
Definition: BitMask.h:1126
template<typename Storage>
template<typename BeginIter , typename EndIter >
void util::flags::BitMask< Storage >::rangeSet ( BeginIter  begin,
EndIter  end 
)
inherited

Sets all flags specified by the index iterator range.

Template Parameters
BeginItertype of iterator to the first of the flags
EndItertype of end iterator
Parameters
beginiterator to the index of the first flag
enditerator past the index of the last flag
See also
set()

Each flag is set as if set(flag) were called.

template<typename Storage>
template<typename BeginIter , typename EndIter >
void util::flags::BitMask< Storage >::rangeUnset ( BeginIter  begin,
EndIter  end 
)
inherited

Unsets all flags specified by the index iterator range.

Template Parameters
BeginItertype of iterator to the first of the flags
EndItertype of end iterator
Parameters
beginiterator to the index of the first flag
enditerator past the index of the last flag
See also
unset()

Each flag is unset as if unset(flag) were called.

template<typename Storage>
template<typename Flag , typename... OtherFlags>
void util::flags::BitMask< Storage >::remove ( Flag  first,
OtherFlags...  others 
)
inlineinherited

Declares all specified flags as undefined.

Template Parameters
Flagtypes of the first flag
OtherFlagstypes of other optional flags
Parameters
firstthe first flag to be removed
othersflags also to be removed
See also
set(), unset(), isDefined()

All specified flags are marked back as undefined. Already undefined flags are not affected. The value of an undefined flag is... well, undefined.

There is no equivalent direct way to just define a flag, but rather when a flag is assigned a value the first time, that flag is at the same time defined.

Each argument can be of one of the following supported types:

  • Flag_t: single flag (a FlagIndex_t can be implicitly converted to this one, too)

Definition at line 793 of file BitMask.h.

794  {
795  undefineImpl(first, others...);
796  }
void undefineImpl()
Implementation detail of remove()
Definition: BitMask.h:1139
template<typename Storage>
template<typename Flag , typename... OtherFlags>
void util::flags::BitMask< Storage >::set ( Flag  first,
OtherFlags...  others 
)
inlineinherited

Sets all specified flags.

Template Parameters
Flagtypes of the first flag
OtherFlagstypes of other optional flags
Parameters
firstthe first flag to be set
othersflags also to be set

All specified flags are set. Flags set are automatically defined.

Each argument can be of one of the following supported types:

  • Flag_t: single flag (a FlagIndex_t can be implicitly converted to this one, too)

Definition at line 724 of file BitMask.h.

References util::begin(), and util::end().

725  {
726  setImpl(first, others...);
727  }
void setImpl()
Implementation detail of set()
Definition: BitMask.h:1146
template<unsigned int NFlags, typename Storage = details::smallestUInt_t<NFlags>>
static constexpr size_t util::flags::FlagSet< NFlags, Storage >::size ( )
inlinestatic

Returns the number of flags the set supports.

Definition at line 159 of file FlagSet.h.

Referenced by util::flags::FlagSet< NFlags, Storage >::dump().

159 { 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.

Referenced by util::flags::FlagSet< NFlags, Storage >::mask().

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()

Referenced by util::flags::FlagSet< NFlags, Storage >::createMask().

template<typename Storage>
template<typename Flag , typename... OtherFlags>
void util::flags::BitMask< Storage >::unset ( Flag  first,
OtherFlags...  others 
)
inlineinherited

Unsets all specified flags.

Template Parameters
Flagtypes of the first flag
OtherFlagstypes of other optional flags
Parameters
firstthe first flag to be unset
othersflags also to be unset
See also
set()

All specified flags are unset. Flags unset are automatically defined. The types accepted are the same as for set().

Definition at line 754 of file BitMask.h.

Referenced by trkmkr::KalmanFilterFitTrackMaker::restoreInputPoints().

755  {
756  unsetImpl(first, others...);
757  }
void unsetImpl()
Implementation detail of unset()
Definition: BitMask.h:1156
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::unsetMask ( Mask_t  baseMask,
Mask_t  mask 
)
staticinherited

Returns a new mask with the bits set from both masks.

Parameters
baseMaskone of the masks to be combined
maskthe other mask to be combined
Returns
a new mask with all bits set in both masks

The content of the new mask has a bit set if it was set (isSet()) in both masks, otherwise unset if it was unset (isUnset()) in either of the masks, or else undefined (isUndefined()), as it was undefined in both masks.

The truth table of this operation follows (see mergeIntoMask() for its legend).

mask - 0 1
baseMask
- - 0 0
0 0 0 0
1 1 1 0
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::unsetMask ( Mask_t  baseMask,
Bits_t  bits 
)
staticinherited

Returns a new mask with only the specified bits set.

Parameters
baseMaskthe starting mask
bitsthe bits to be set
Returns
a new mask with all defined flags from baseMask, with only the specified bits set

All bits in the argument are also defined.

The truth table of this operation follows (see mergeIntoMask() for its legend).

bits 0 1
baseMask
- - 0
0 0 0
1 1 0
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::unsetMask ( Mask_t  baseMask,
Flag_t  flag 
)
staticinherited

Returns a new mask with the specified flag as only set flag.

Parameters
baseMaskthe starting mask
flagthe single flag to be set
Returns
a new mask with all flags from baseMask, with only flag set

Member Data Documentation

template<typename Storage>
constexpr auto util::flags::BitMask< Storage >::fromValues = maskFromValues
staticinherited

Constructor tag from values.

Definition at line 437 of file BitMask.h.


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