LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
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... | |
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... | |
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... | |
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 |
|
inherited |
Returns whether all the specified bits are set.
bits | bits to check |
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.
|
inherited |
Returns whether at least one of the specified bits is set.
bits | bits to check |
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).
|
inherited |
|
staticinherited |
Returns the number of flags the set has room for.
|
inlineinherited |
|
staticinherited |
Returns a new mask combining bits set from two masks.
A | one of the masks to be combined |
B | the other mask to be combined |
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 |
|
staticinherited |
Returns a new mask with the specified flag defined and set.
baseMask | the starting mask |
bits | the bits to be set |
The truth table of this operation follows (see mergeIntoMask()
for its legend).
bits | 0 | 1 |
---|---|---|
baseMask | ||
- | - | 1 |
0 | 0 | 1 |
1 | 1 | 1 |
|
staticinherited |
Returns a new mask with the specified flag defined and set.
baseMask | the starting mask |
flag | the single flag to be set |
|
staticinherited |
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). 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().
|
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 173 of file FlagSet.h.
References util::flags::BitMask< Storage >::create(), and util::flags::FlagSet< NFlags, Storage >::testImpl().
|
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().
|
inherited |
Prints into the specified stream the least nBits significant bits.
Referenced by util::flags::FlagSet< NFlags, Storage >::dump().
|
inherited |
Returns if the specified flag is on ("set").
flag | index of the flag to test |
This method provides an unchecked access to a single flag value. If the flag is isUndefined()
, the behaviour of this method is also undefined.
|
staticinherited |
Returns a new mask with the bits set from both masks.
A | one of the masks to be combined |
B | the other mask to be combined |
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 |
|
staticinherited |
Returns a new mask with only the specified bits set.
baseMask | the starting mask |
bits | the bits to be 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 |
|
staticinherited |
Returns a new mask with the specified flag as only set flag.
baseMask | the starting mask |
flag | the single flag to be set |
|
inherited |
Returns whether the flag is defined.
flag | index of the flag to check |
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.
|
inherited |
Returns whether all specified bits are defined.
bits | bits to check |
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.
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.
Referenced by util::flags::FlagSet< NFlags, Storage >::mask().
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.
|
inherited |
Returns if the specified flag is set.
flag | index of the flag to test |
This method provides an unchecked access to a single flag value. If the flag is isUndefined()
, the behaviour of this method is also undefined.
|
inherited |
Returns whether the flag is undefined.
flag | index of the flag to check |
This is exactly the negation of isDefined()
.
|
inherited |
Returns whether all specified bits are undefined.
bits | bits to check |
This is exactly the negation of isDefined()
.
|
inherited |
Returns if the specified flag is unset.
flag | index of the flag to test |
This method provides an unchecked access to a single flag value. If the flag is isUndefined()
, the behaviour of this method is also undefined.
|
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().
|
inherited |
Returns whether all bits defined in the mask are equal to ours.
mask | the mask of bits |
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
.
|
staticinherited |
Returns a new mask with the content of the other mask
merged.
baseMask | the starting mask |
mask | the bits to be set |
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 |
|
staticinherited |
Returns a new mask with the specified bits defined and set.
baseMask | the starting mask |
bits | the bits to be set |
The truth table of this operation follows (see mergeIntoMask()
for its legend).
bits | 0 | 1 |
---|---|---|
baseMask | ||
- | - | 1 |
0 | 0 | 1 |
1 | 1 | 1 |
|
staticinherited |
Returns a new mask with the specified flag defined and set.
baseMask | the starting mask |
flag | the single flag to be set |
|
staticinherited |
Returns the negation of mask.
mask | the starting mask |
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 |
|
staticinherited |
Returns a new mask with the specified bits unset.
bits | bits to be unset |
Only the unset bits are defined.
|
staticinherited |
Returns a new mask with the specified flag unset.
flag | the single flag to be set |
|
inherited |
Returns whether all the specified bits are unset.
bits | bits to check |
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.
|
inherited |
|
inlineinherited |
Comparison: not all flags must be the same
Definition at line 827 of file BitMask.h.
References util::flags::BitMask< Storage >::presence, util::values(), and util::flags::BitMask< Storage >::values.
|
default |
|
default |
|
inlineinherited |
Comparison: all flags must be the same
Definition at line 820 of file BitMask.h.
References util::flags::BitMask< Storage >::presence, util::values(), and util::flags::BitMask< Storage >::values.
|
inherited |
Sets all flags specified by the index iterator range.
BeginIter | type of iterator to the first of the flags |
EndIter | type of end iterator |
begin | iterator to the index of the first flag |
end | iterator past the index of the last flag |
Each flag is set as if set(flag)
were called.
|
inherited |
Unsets all flags specified by the index iterator range.
BeginIter | type of iterator to the first of the flags |
EndIter | type of end iterator |
begin | iterator to the index of the first flag |
end | iterator past the index of the last flag |
Each flag is unset as if unset(flag)
were called.
|
inlineinherited |
Declares all specified flags as undefined.
Flag | types of the first flag |
OtherFlags | types of other optional flags |
first | the first flag to be removed |
others | flags also to be removed |
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.
|
inlineinherited |
Sets all specified flags.
Flag | types of the first flag |
OtherFlags | types of other optional flags |
first | the first flag to be set |
others | flags 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().
|
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().
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.
Referenced by util::flags::FlagSet< NFlags, Storage >::mask().
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()
Referenced by util::flags::FlagSet< NFlags, Storage >::createMask().
|
inlineinherited |
Unsets all specified flags.
Flag | types of the first flag |
OtherFlags | types of other optional flags |
first | the first flag to be unset |
others | flags also to be unset |
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().
|
staticinherited |
Returns a new mask with the bits set from both masks.
baseMask | one of the masks to be combined |
mask | the other mask to be combined |
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 |
|
staticinherited |
Returns a new mask with only the specified bits set.
baseMask | the starting mask |
bits | the bits to be 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 |
|
staticinherited |
Returns a new mask with the specified flag as only set flag.
baseMask | the starting mask |
flag | the single flag to be set |
|
staticinherited |