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

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

#include <BitMask.h>

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

Public Types

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...
 
Exceptions
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

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...
 
Constructors from values

These constructors initialize the bit mask from the traditional bit mask constants in C style. The first argument of them should be util::flags::maskFromValues (or the equivalent fromValues from BitMask itself).

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...
 
Constructors combining flags
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...
 
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

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 Types

using Storage_t = Storage
 Type of underlying bit data representation. More...
 

Private Member Functions

void defineSingle (Flag_t flag)
 Marks a flag as defined. Value is still uninitialised! More...
 
void undefineSingle (Flag_t flag)
 Marks a flag as undefined. More...
 
void undefineImpl ()
 Implementation detail of remove() More...
 
template<typename... Flags>
void undefineImpl (Flag_t flag, Flags...others)
 Implementation detail of remove() More...
 
void setImpl ()
 Implementation detail of set() More...
 
template<typename... Flags>
void setImpl (Flag_t flag, Flags...others)
 Implementation detail of set() More...
 
void setSingle (Flag_t flag)
 Implementation detail of set() More...
 
void unsetImpl ()
 Implementation detail of unset() More...
 
constexpr Bits_t definedOnly () const
 Returns a bit set with all undefined bits unset. More...
 
template<typename... Flags>
void unsetImpl (Flag_t flag, Flags...others)
 Implementation detail of unset() More...
 
void unsetSingle (Flag_t flag)
 Implementation detail of unset() More...
 

Static Private Member Functions

static constexpr bool testBits (Storage_t data, Storage_t bits)
 Returns whether any of the specified bits is set. More...
 
static constexpr bool testBitmask (Storage_t data, Storage_t mask)
 Returns whether all the specified bits in the mask are set. More...
 
static constexpr bool testUnsetBitmask (Storage_t data, Storage_t mask)
 Returns whether all the specified bits in the mask are set. More...
 

Private Attributes

Bits_t values
 Storage of value bits. More...
 
Bits_t presence
 Storage of definition bits. More...
 

Detailed Description

template<typename Storage>
class util::flags::BitMask< 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 BitMask 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 420 of file BitMask.h.

Member Typedef Documentation

template<typename Storage>
using util::flags::BitMask< Storage >::Bits_t = util::flags::Bits_t<Storage_t>

Set of bits.

Definition at line 431 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::Exception = errors::Exception

Generic BitMask exception.

Definition at line 440 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::Flag_t = typename Bits_t::Flag_t

Type identifying a single flag.

Definition at line 434 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::FlagIndex_t = util::flags::Index_t

Type of index of flag.

Definition at line 429 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::FlagNotDefinedError = errors::FlagNotDefined

Flag not defined.

Definition at line 446 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::Mask_t = BitMask<Storage>

This type.

Definition at line 427 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::OutOfRangeError = errors::OutOfRange

Out-of-range flag index.

Definition at line 443 of file BitMask.h.

template<typename Storage>
using util::flags::BitMask< Storage >::Storage_t = Storage
private

Type of underlying bit data representation.

Definition at line 423 of file BitMask.h.

Constructor & Destructor Documentation

template<typename Storage>
constexpr util::flags::BitMask< Storage >::BitMask ( )
explicitdefault

Default constructor: no flag defined at all.

template<typename Storage>
constexpr util::flags::BitMask< Storage >::BitMask ( BitMaskFromValuesTag  ,
Storage_t  defined 
)

Constructor: defines and sets flags.

Parameters
defineda bit mask of the values to be defined and set

All bits in values will be defined and set. Example:

constexpr MyMask_t DefaultMask(MyMask_t::fromValues, 0x0300U);
template<typename Storage>
constexpr util::flags::BitMask< Storage >::BitMask ( BitMaskFromValuesTag  ,
Storage_t  defined,
Storage_t  values 
)

Constructor: defines and sets flags.

Parameters
defineda bit mask of the flags to be defined
valuesa bit mask of the values to be set

If a bit value is requested to be set (in values), it will be also defined, regardless whether its definition bit (in defined) is set. Example:

constexpr MyMask_t DefaultMask(MyMask_t::fromValues, 0x0300U, 0x0200U);
template<typename Storage>
constexpr util::flags::BitMask< Storage >::BitMask ( BitMaskFromValuesTag  ,
Bits_t  values 
)

Constructor: defines and sets flags.

Parameters
valuesa bit mask of the values to be set
template<typename Storage>
constexpr util::flags::BitMask< Storage >::BitMask ( BitMaskFromValuesTag  ,
Bits_t  defined,
Bits_t  values 
)

Constructor: defines and sets flags.

Parameters
defineda bit mask of the flags to be defined
valuesa bit mask of the values to be set

If a bit value is requested to be set (in values), it will be also defined, regardless whether its definition bit (in defined) is set.

template<typename Storage>
template<typename... Others>
constexpr util::flags::BitMask< Storage >::BitMask ( Flag_t  first,
Others...  others 
)
inline

Constructor: merges all arguments in the argument list.

Template Parameters
Otherstype of the remaining parameters to be merged
Parameters
firstfirst argument to be merged (here, a Flag_t)
othersremaining arguments to be merged
See also
create()

The effect is equivalent to call create(first, others...).

Definition at line 536 of file BitMask.h.

537  : BitMask(create(first, others...))
538  {}
static constexpr Mask_t create(Args...args)
Creates a new BitMask.
constexpr BitMask()=default
Default constructor: no flag defined at all.
template<typename Storage>
template<typename... Others>
constexpr util::flags::BitMask< Storage >::BitMask ( Bits_t  first,
Others...  others 
)
inline

Constructor: merges all arguments in the argument list.

Template Parameters
Otherstype of the remaining parameters to be merged
Parameters
firstfirst argument to be merged (here, a Bits_t)
othersremaining arguments to be merged
See also
create()

The effect is equivalent to call create(first, others...).

Definition at line 550 of file BitMask.h.

551  : BitMask(create(first, others...))
552  {}
static constexpr Mask_t create(Args...args)
Creates a new BitMask.
constexpr BitMask()=default
Default constructor: no flag defined at all.
template<typename Storage>
template<typename Second , typename... Others>
constexpr util::flags::BitMask< Storage >::BitMask ( Mask_t  first,
Second  second,
Others...  others 
)
inline

Constructor: merges all arguments in the argument list.

Template Parameters
Secondtype of the second argument to be merged
Otherstype of the remaining arguments to be merged
Parameters
firstfirst argument to be merged (here, a Mask_t)
secondsecond argument to be merged
othersremaining arguments to be merged
See also
create()

The effect is equivalent to call create(first, others...).

Definition at line 569 of file BitMask.h.

570  : BitMask(create(first, second, others...))
571  {}
static constexpr Mask_t create(Args...args)
Creates a new BitMask.
constexpr BitMask()=default
Default constructor: no flag defined at all.
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85

Member Function Documentation

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

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

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

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

Returns the number of flags the set has room for.

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

Undefines all bits.

Definition at line 821 of file BitMask.h.

822  { presence.clear(); values.clear(); }
void clear()
Unsets all bits.
Definition: BitMask.h:251
Bits_t values
Storage of value bits.
Definition: BitMask.h:1142
Bits_t presence
Storage of definition bits.
Definition: BitMask.h:1143
template<typename Storage>
static constexpr Mask_t util::flags::BitMask< Storage >::combineWithMask ( Mask_t  A,
Mask_t  B 
)
static

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

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

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

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.

template<typename Storage>
constexpr Bits_t util::flags::BitMask< Storage >::definedOnly ( ) const
private

Returns a bit set with all undefined bits unset.

template<typename Storage>
void util::flags::BitMask< Storage >::defineSingle ( Flag_t  flag)
private

Marks a flag as defined. Value is still uninitialised!

template<typename Storage>
template<typename Stream >
void util::flags::BitMask< Storage >::dump ( Stream &&  out,
unsigned int  nBits 
) const

Prints into the specified stream the least nBits significant bits.

template<typename Storage>
template<typename Stream >
void util::flags::BitMask< Storage >::dump ( Stream &&  out) const
inline

Prints into the specified stream all bits.

Definition at line 855 of file BitMask.h.

856  { dump(std::forward<Stream>(out), capacity()); }
void dump(Stream &&out, unsigned int nBits) const
Prints into the specified stream the least nBits significant bits.
static constexpr size_t capacity()
Returns the number of flags the set has room for.
template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::get ( Flag_t  flag) const

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

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

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

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

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

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

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

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

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

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<typename Storage>
constexpr bool util::flags::BitMask< Storage >::match ( Mask_t const &  mask) const

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

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

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

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

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

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

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

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

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
inline

Comparison: not all flags must be the same

Bug:
Also the value of undefined flags is currently checked

Definition at line 845 of file BitMask.h.

846  { return (values != other.values) || (presence != other.presence); }
Bits_t values
Storage of value bits.
Definition: BitMask.h:1142
Bits_t presence
Storage of definition bits.
Definition: BitMask.h:1143
template<typename Storage>
constexpr bool util::flags::BitMask< Storage >::operator== ( Mask_t const &  other) const
inline

Comparison: all flags must be the same

Bug:
Also the value of undefined flags is currently checked

Definition at line 840 of file BitMask.h.

841  { return (values == other.values) && (presence == other.presence); }
Bits_t values
Storage of value bits.
Definition: BitMask.h:1142
Bits_t presence
Storage of definition bits.
Definition: BitMask.h:1143
template<typename Storage>
template<typename BeginIter , typename EndIter >
void util::flags::BitMask< Storage >::rangeSet ( BeginIter  begin,
EndIter  end 
)

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 
)

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

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 817 of file BitMask.h.

818  { undefineImpl(first, others...); }
void undefineImpl()
Implementation detail of remove()
Definition: BitMask.h:1156
template<typename Storage>
template<typename Flag , typename... OtherFlags>
void util::flags::BitMask< Storage >::set ( Flag  first,
OtherFlags...  others 
)
inline

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 751 of file BitMask.h.

752  { setImpl(first, others...); }
void setImpl()
Implementation detail of set()
Definition: BitMask.h:1163
template<typename Storage>
void util::flags::BitMask< Storage >::setImpl ( )
inlineprivate

Implementation detail of set()

Definition at line 1163 of file BitMask.h.

1163 {}
template<typename Storage>
template<typename... Flags>
void util::flags::BitMask< Storage >::setImpl ( Flag_t  flag,
Flags...  others 
)
private

Implementation detail of set()

template<typename Storage>
void util::flags::BitMask< Storage >::setSingle ( Flag_t  flag)
private

Implementation detail of set()

template<typename Storage>
static constexpr bool util::flags::BitMask< Storage >::testBitmask ( Storage_t  data,
Storage_t  mask 
)
inlinestaticprivate

Returns whether all the specified bits in the mask are set.

Definition at line 1190 of file BitMask.h.

template<typename Storage>
static constexpr bool util::flags::BitMask< Storage >::testBits ( Storage_t  data,
Storage_t  bits 
)
inlinestaticprivate

Returns whether any of the specified bits is set.

Definition at line 1186 of file BitMask.h.

1187  { return data & bits; }
template<typename Storage>
static constexpr bool util::flags::BitMask< Storage >::testUnsetBitmask ( Storage_t  data,
Storage_t  mask 
)
inlinestaticprivate

Returns whether all the specified bits in the mask are set.

Definition at line 1194 of file BitMask.h.

template<typename Storage>
void util::flags::BitMask< Storage >::undefineImpl ( )
inlineprivate

Implementation detail of remove()

Definition at line 1156 of file BitMask.h.

1156 {}
template<typename Storage>
template<typename... Flags>
void util::flags::BitMask< Storage >::undefineImpl ( Flag_t  flag,
Flags...  others 
)
private

Implementation detail of remove()

template<typename Storage>
void util::flags::BitMask< Storage >::undefineSingle ( Flag_t  flag)
private

Marks a flag as undefined.

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

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 779 of file BitMask.h.

780  { unsetImpl(first, others...); }
void unsetImpl()
Implementation detail of unset()
Definition: BitMask.h:1173
template<typename Storage>
void util::flags::BitMask< Storage >::unsetImpl ( )
inlineprivate

Implementation detail of unset()

Definition at line 1173 of file BitMask.h.

1173 {}
template<typename Storage>
template<typename... Flags>
void util::flags::BitMask< Storage >::unsetImpl ( Flag_t  flag,
Flags...  others 
)
private

Implementation detail of unset()

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

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

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

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>
void util::flags::BitMask< Storage >::unsetSingle ( Flag_t  flag)
private

Implementation detail of unset()

Member Data Documentation

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

Constructor tag from values.

Definition at line 451 of file BitMask.h.

template<typename Storage>
Bits_t util::flags::BitMask< Storage >::presence
private

Storage of definition bits.

Definition at line 1143 of file BitMask.h.

template<typename Storage>
Bits_t util::flags::BitMask< Storage >::values
private

Storage of value bits.

Definition at line 1142 of file BitMask.h.


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