libcommonc++  0.7
Flags< T > Class Template Reference

A wrapper template for primitive integer types that represent flag bitmasks. More...

#include <Flags.h++>

Public Member Functions

 Flags (const T &flags=0)
 Construct a new Flags object with an initial value of 0. More...
 
 ~Flags ()
 Destructor. More...
 
bool isSet (int index) const
 Test if the bit at the given index is set. More...
 
void set (int index, bool on=true)
 Set or clear the bit at the given index. More...
 
bool anySet (const T &mask) const
 Compare the flags to a mask, returning true if any of the bits in the mask are set in the flags. More...
 
bool allSet (const T &mask) const
 Compare the flags to a mask, returning true if all of the bits in the mask are set in the flags. More...
 
bool operator[] (int index) const
 Index operator. More...
 
BitRef operator[] (int index)
 Index operator. More...
 
void clear (int flag)
 Clear the bit at the given index. More...
 
void clear ()
 Clear all of the bits. More...
 
 operator T () const
 Cast operator. More...
 
Flagsoperator= (const T &flags)
 Assignment operator. More...
 

Detailed Description

template<typename T>
class ccxx::Flags< T >

A wrapper template for primitive integer types that represent flag bitmasks.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ Flags()

Flags ( const T &  flags = 0)

Construct a new Flags object with an initial value of 0.

◆ ~Flags()

~Flags ( )

Destructor.

Member Function Documentation

◆ allSet()

bool allSet ( const T &  mask) const

Compare the flags to a mask, returning true if all of the bits in the mask are set in the flags.

Parameters
maskThe bitmask.
Returns
true if the bitwise-AND of the flags and the mask is equal to the mask.

◆ anySet()

bool anySet ( const T &  mask) const

Compare the flags to a mask, returning true if any of the bits in the mask are set in the flags.

Parameters
maskThe bitmask.
Returns
true if the bitwise-AND of the flags and the mask is nonzero.

◆ clear() [1/2]

void clear ( int  flag)

Clear the bit at the given index.

Parameters
indexThe bit index.

◆ clear() [2/2]

void clear ( )

Clear all of the bits.

◆ isSet()

bool isSet ( int  index) const

Test if the bit at the given index is set.

Parameters
indexThe bit index.
Returns
true if the bit is set, false otherwise.

◆ operator T()

operator T ( ) const
inline

Cast operator.

◆ operator=()

Flags& operator= ( const T &  flags)

Assignment operator.

◆ operator[]() [1/2]

bool operator[] ( int  index) const

Index operator.

Equivalent to isSet().

◆ operator[]() [2/2]

BitRef operator[] ( int  index)

Index operator.

Returns a reference to the given bit.

Exceptions
OutOfBoundsExceptionIf index is invalid.

◆ set()

void set ( int  index,
bool  on = true 
)

Set or clear the bit at the given index.

Parameters
indexThe bit index.
onA flag indicating whether the bit should be set or cleared.

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