![]() |
PEARL
Parallel Event Access and Replay Library
|
Class template for type-safe enum flags. More...
#include <pearl/Flags.h>
Public Types | |
typedef EnumT | EnumType |
Base type of the associated flag enumeration. More... | |
typedef StorageT | ValueType |
Base type used for storing the bit mask. More... | |
Public Member Functions | |
Constructors & destructor | |
Flags () | |
Default constructor. More... | |
Flags (EnumT flag) | |
Constructor. More... | |
Manipulating operations | |
Flags & | operator&= (EnumT rhs) |
Binary AND. More... | |
Flags & | operator&= (const Flags &rhs) |
Binary AND. More... | |
Flags & | operator|= (EnumT rhs) |
Binary OR. More... | |
Flags & | operator|= (const Flags &rhs) |
Binary OR. More... | |
Flags & | set (EnumT flag) |
Set flag. More... | |
Flags & | set (const Flags &flags) |
Set flags. More... | |
Flags & | unset (EnumT flag) |
Unset flag. More... | |
Flags & | unset (const Flags &flags) |
Unset flags. More... | |
Value access | |
bool | test (EnumT flag) const |
Test flag. More... | |
bool | test (const Flags &flags) const |
Test flags. More... | |
StorageT | getValue () const |
Get integer representation of flags. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Comparison operators | |
template<typename EnumT , typename StorageT > | |
bool | operator== (const Flags< EnumT, StorageT > &lhs, const Flags< EnumT, StorageT > &rhs) |
Equality operator. More... | |
template<typename EnumT , typename StorageT > | |
bool | operator!= (const Flags< EnumT, StorageT > &lhs, const Flags< EnumT, StorageT > &rhs) |
Inequality operator. More... | |
The Flags class template provides a type-safe way to store and manipulate combinations of flags provided via an enum
type. The associated flag enumeration EnumT
should provide symbolic names for the individual flags using powers of two as values. (While non-power-of-two values are not prohibited, they are strongly discouraged. If used nevertheless, the enumerator name should at least properly reflect that it represents a combination of flags.)
The underlying storage type for the flag bit mask can be selected via the StorageT
template parameter (unsigned int
by default), with the restriction that it has to be large enough to hold a bit mask resulting from a binary OR of all individual flag values.
To define a flag type for a class MyClass
, provide an enum
type defining an enumerator for each flag with a value of the corresponding bit position. Then create a convenience typedef
for the Flags class template instantiated with the enum
type. To allow for binary logic operations on such flag types, the corresponding operators need to be defined as free functions (due to C++'s name resolution mechanism). This can be accomplished using the PEARL_DEFINE_FLAGS_OPERATORS(classT,flagsT) convenience macro.
EnumT | Associated flag enumeration type |
StorageT | Underlying storage type for the bit mask |
typedef EnumT pearl::Flags< EnumT, StorageT >::EnumType |
typedef StorageT pearl::Flags< EnumT, StorageT >::ValueType |
pearl::Flags< EnumT, StorageT >::Flags |
Constructs a new instance with no flags set.
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
pearl::Flags< EnumT, StorageT >::Flags | ( | EnumT | flag | ) |
Constructs a new instance initialized with the given flag
.
flag | Initial flag \n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n |
StorageT pearl::Flags< EnumT, StorageT >::getValue |
Returns the flags stored in the instance as a bit mask of type StorageT
.
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::operator&= | ( | const Flags< EnumT, StorageT > & | rhs | ) |
Performs a binary AND on corresponding pairs of flags with rhs
and stores the result in this instance.
rhs | Right-hand side operand |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::operator&= | ( | EnumT | rhs | ) |
Performs a binary AND on corresponding pairs of flags with rhs
and stores the result in this instance.
rhs | Right-hand side operand |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::operator|= | ( | const Flags< EnumT, StorageT > & | rhs | ) |
Performs a binary OR on corresponding pairs of flags with rhs
and stores the result in this instance.
rhs | Right-hand side operand |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::operator|= | ( | EnumT | rhs | ) |
Performs a binary OR on corresponding pairs of flags with rhs
and stores the result in this instance.
rhs | Right-hand side operand |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::set | ( | const Flags< EnumT, StorageT > & | flags | ) |
Sets the given flags
in the instance.
flags | Flags to be set |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::set | ( | EnumT | flag | ) |
Sets the given flag
in the instance.
flag | Flag to be set |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
bool pearl::Flags< EnumT, StorageT >::test | ( | const Flags< EnumT, StorageT > & | flags | ) | const |
Tests whether the given flags
are set in the instance.
flags | Flags to be tested |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
bool pearl::Flags< EnumT, StorageT >::test | ( | EnumT | flag | ) | const |
Tests whether the given flag
is set in the instance.
flag | Flag to be tested |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::unset | ( | const Flags< EnumT, StorageT > & | flags | ) |
Unsets the given flags
in the instance.
flags | Flags to be unset |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::unset | ( | EnumT | flag | ) |
Unsets the given flag
in the instance.
flag | Flag to be unset |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
|
related |
Tests whether the flags stored in lhs
and rhs
are unequal.
lhs | Left-hand side operand |
rhs | Right-hand side operand |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
|
related |
Tests whether the flags stored in lhs
and rhs
are equal.
lhs | Left-hand side operand |
rhs | Right-hand side operand |
\n@par Exception safety\n <b class="paramname">No-throw guarantee:</b> never throws exceptions. <br>\n
![]() |
Copyright © 1998–2019 Forschungszentrum Jülich GmbH,
Jülich Supercomputing Centre
Copyright © 2009–2015 German Research School for Simulation Sciences GmbH, Laboratory for Parallel Programming |