PEARL
Parallel Event Access and Replay Library
Public Types | List of all members
pearl::Flags< EnumT, StorageT > Class Template Reference

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
Flagsoperator&= (EnumT rhs)
 Binary AND. More...
 
Flagsoperator&= (const Flags &rhs)
 Binary AND. More...
 
Flagsoperator|= (EnumT rhs)
 Binary OR. More...
 
Flagsoperator|= (const Flags &rhs)
 Binary OR. More...
 
Flagsset (EnumT flag)
 Set flag. More...
 
Flagsset (const Flags &flags)
 Set flags. More...
 
Flagsunset (EnumT flag)
 Unset flag. More...
 
Flagsunset (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...
 

Detailed Description

template<typename EnumT, typename StorageT = unsigned int>
class pearl::Flags< EnumT, StorageT >

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.

Example:
#include <pearl/Flags.h>
class MyClass
{
public:
enum PropertyEnum
{
PROPERTY_NONE = 0x00,
PROPERTY_A = 0x01,
PROPERTY_B = 0x02,
PROPERTY_C = 0x04
};
typedef pearl::Flags< PropertyEnum > PropertyFlags;
};
PEARL_DEFINE_FLAGS_OPERATORS(MyClass, PropertyFlags)
// ...
MyClass::PropertyFlags flags(MyClass::PROPERTY_C);
flags.set(MyClass::PROPERTY_A | MyClass::PROPERTY_B);
Template Parameters
EnumTAssociated flag enumeration type
StorageTUnderlying storage type for the bit mask

Member Typedef Documentation

◆ EnumType

template<typename EnumT , typename StorageT = unsigned int>
typedef EnumT pearl::Flags< EnumT, StorageT >::EnumType

◆ ValueType

template<typename EnumT , typename StorageT = unsigned int>
typedef StorageT pearl::Flags< EnumT, StorageT >::ValueType

Constructor & Destructor Documentation

◆ Flags() [1/2]

template<typename EnumT , typename StorageT >
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

◆ Flags() [2/2]

template<typename EnumT , typename StorageT >
pearl::Flags< EnumT, StorageT >::Flags ( EnumT  flag)

Constructs a new instance initialized with the given flag.

Parameters
flagInitial flag
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

Member Function Documentation

◆ getValue()

template<typename EnumT , typename StorageT >
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

◆ operator&=() [1/2]

template<typename EnumT , typename StorageT >
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.

Parameters
rhsRight-hand side operand
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ operator&=() [2/2]

template<typename EnumT , typename StorageT >
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.

Parameters
rhsRight-hand side operand
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ operator|=() [1/2]

template<typename EnumT , typename StorageT >
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.

Parameters
rhsRight-hand side operand
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ operator|=() [2/2]

template<typename EnumT , typename StorageT >
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.

Parameters
rhsRight-hand side operand
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ set() [1/2]

template<typename EnumT , typename StorageT >
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::set ( const Flags< EnumT, StorageT > &  flags)

Sets the given flags in the instance.

Parameters
flagsFlags to be set
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ set() [2/2]

template<typename EnumT , typename StorageT >
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::set ( EnumT  flag)

Sets the given flag in the instance.

Parameters
flagFlag to be set
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ test() [1/2]

template<typename EnumT , typename StorageT >
bool pearl::Flags< EnumT, StorageT >::test ( const Flags< EnumT, StorageT > &  flags) const

Tests whether the given flags are set in the instance.

Parameters
flagsFlags to be tested
Returns
True if flags are set, false otherwise
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ test() [2/2]

template<typename EnumT , typename StorageT >
bool pearl::Flags< EnumT, StorageT >::test ( EnumT  flag) const

Tests whether the given flag is set in the instance.

Parameters
flagFlag to be tested
Returns
True if flag is set, false otherwise
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ unset() [1/2]

template<typename EnumT , typename StorageT >
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::unset ( const Flags< EnumT, StorageT > &  flags)

Unsets the given flags in the instance.

Parameters
flagsFlags to be unset
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ unset() [2/2]

template<typename EnumT , typename StorageT >
Flags< EnumT, StorageT > & pearl::Flags< EnumT, StorageT >::unset ( EnumT  flag)

Unsets the given flag in the instance.

Parameters
flagFlag to be unset
Returns
Reference to instance
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

Friends And Related Function Documentation

◆ operator!=()

template<typename EnumT , typename StorageT >
bool operator!= ( const Flags< EnumT, StorageT > &  lhs,
const Flags< EnumT, StorageT > &  rhs 
)
related

Tests whether the flags stored in lhs and rhs are unequal.

Parameters
lhsLeft-hand side operand
rhsRight-hand side operand
Returns
True if the operands are not equal, false otherwise.
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

◆ operator==()

template<typename EnumT , typename StorageT >
bool operator== ( const Flags< EnumT, StorageT > &  lhs,
const Flags< EnumT, StorageT > &  rhs 
)
related

Tests whether the flags stored in lhs and rhs are equal.

Parameters
lhsLeft-hand side operand
rhsRight-hand side operand
Returns
True if the operands are equal, false otherwise.
        \n@par Exception safety\n        <b class="paramname">No-throw guarantee:</b>         never throws exceptions.        <br>\n

The documentation for this class was generated from the following files:
PEARL_DEFINE_FLAGS_OPERATORS
#define PEARL_DEFINE_FLAGS_OPERATORS(classT, flagsT)
Convenience macro to define binary logic operators.
Definition: Flags.h:367
pearl::Flags
Class template for type-safe enum flags.
Definition: Flags.h:94
Flags.h
Declaration and implementation of the class template Flags.

Scalasca    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