ROSE  0.9.10.135
Public Types | Public Member Functions | List of all members
Rose::BitFlags< E, V > Class Template Reference

Description

template<typename E, typename V = unsigned long>
class Rose::BitFlags< E, V >

Stores a vector of enum bit flags.

This is a more self-documenting and terse way to use bit flags. For example, consider this original code:

class TableCharacter {
enum Corner { NONE = 0, LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
unsigned current; // bit vector of Corner flags for current character
unsigned previous; // bit vector of Corner flags for previous character
TableCharacter(): current(NONE), previous(NONE) {}
void process(unsigned next) { // next is vector of Corner bit flags
if ((current & LEFT) != 0) {
previous |= LEFT;
current &= ~LEFT;
}
if ((next & TOP) == 0) {
current &= ~TOP;
current |= BOTTOM;
}
}
};

Now rewritten to use this class:

class TableCharacter {
enum Corner { NONE = 0, LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
BitFlags<Corner> current;
BitFlags<Corner> previous;
TableCharacters(): current(NONE), previous(NONE) {}
void process(BitFlags<Corner> next) {
if (current.testAndClear(LEFT))
previous.set(LEFT);
if (next.isClear(TOP))
current.clear(TOP).set(BOTTOM);
}
};

Definition at line 56 of file BitFlags.h.

#include <BitFlags.h>

Public Types

typedef E Enum
 
typedef V Vector
 

Public Member Functions

 BitFlags ()
 Default constructor with all bits clear. More...
 
 BitFlags (Vector v)
 Construct bit vector from value or bit. More...
 
Vector vector () const
 Current value of the bit vector. More...
 
bool isSet (Enum e) const
 Test whether a bit is set. More...
 
bool isClear (Enum e) const
 Test whether a bit is clear. More...
 
BitFlagsset (Enum e)
 Set the specified bit. More...
 
BitFlagsclear (Enum e)
 Clear the specified bit. More...
 
bool testAndClear (Enum e)
 Test whether a bit is set, then clear it. More...
 
bool testAndSet (Enum e)
 Test whether a bit is set, then set it. More...
 
BitFlagsoperator= (Vector v)
 Set the vector to an exact value. More...
 
BitFlagsoperator= (BitFlags other)
 Set the vector to the same as another. More...
 
std::string toString (std::vector< long > constants, const char *(*stringifier)(long)) const
 Convert to string. More...
 
bool operator== (BitFlags other) const
 Compare two vectors.
 
bool operator!= (BitFlags other) const
 Compare two vectors.
 
bool operator< (BitFlags other) const
 Compare two vectors.
 
bool operator<= (BitFlags other) const
 Compare two vectors.
 
bool operator> (BitFlags other) const
 Compare two vectors.
 
bool operator>= (BitFlags other) const
 Compare two vectors.
 

Constructor & Destructor Documentation

template<typename E , typename V = unsigned long>
Rose::BitFlags< E, V >::BitFlags ( )
inline

Default constructor with all bits clear.

Definition at line 66 of file BitFlags.h.

template<typename E , typename V = unsigned long>
Rose::BitFlags< E, V >::BitFlags ( Vector  v)
inline

Construct bit vector from value or bit.

Definition at line 70 of file BitFlags.h.

Member Function Documentation

template<typename E , typename V = unsigned long>
Vector Rose::BitFlags< E, V >::vector ( ) const
inline

Current value of the bit vector.

Definition at line 74 of file BitFlags.h.

template<typename E , typename V = unsigned long>
bool Rose::BitFlags< E, V >::isSet ( Enum  e) const
inline

Test whether a bit is set.

Definition at line 79 of file BitFlags.h.

Referenced by Rose::BitFlags< E, V >::isClear(), Rose::BitFlags< E, V >::testAndClear(), and Rose::BitFlags< E, V >::testAndSet().

template<typename E , typename V = unsigned long>
bool Rose::BitFlags< E, V >::isClear ( Enum  e) const
inline

Test whether a bit is clear.

Definition at line 84 of file BitFlags.h.

References Rose::BitFlags< E, V >::isSet().

template<typename E , typename V = unsigned long>
BitFlags& Rose::BitFlags< E, V >::set ( Enum  e)
inline

Set the specified bit.

Definition at line 89 of file BitFlags.h.

Referenced by Rose::BitFlags< E, V >::testAndSet().

template<typename E , typename V = unsigned long>
BitFlags& Rose::BitFlags< E, V >::clear ( Enum  e)
inline

Clear the specified bit.

Definition at line 95 of file BitFlags.h.

Referenced by Rose::BitFlags< E, V >::testAndClear().

template<typename E , typename V = unsigned long>
bool Rose::BitFlags< E, V >::testAndClear ( Enum  e)
inline

Test whether a bit is set, then clear it.

Definition at line 101 of file BitFlags.h.

References Rose::BitFlags< E, V >::clear(), and Rose::BitFlags< E, V >::isSet().

template<typename E , typename V = unsigned long>
bool Rose::BitFlags< E, V >::testAndSet ( Enum  e)
inline

Test whether a bit is set, then set it.

Definition at line 108 of file BitFlags.h.

References Rose::BitFlags< E, V >::isSet(), and Rose::BitFlags< E, V >::set().

template<typename E , typename V = unsigned long>
BitFlags& Rose::BitFlags< E, V >::operator= ( Vector  v)
inline

Set the vector to an exact value.

Definition at line 115 of file BitFlags.h.

template<typename E , typename V = unsigned long>
BitFlags& Rose::BitFlags< E, V >::operator= ( BitFlags< E, V >  other)
inline

Set the vector to the same as another.

Definition at line 121 of file BitFlags.h.

template<typename E , typename V = unsigned long>
std::string Rose::BitFlags< E, V >::toString ( std::vector< long >  constants,
const char *(*)(long)  stringifier 
) const
inline

Convert to string.

Converts a bit vector to a string of the form "NAME1|NAME2|...". The constants are the individual enum flags, and the stringifier is a function that converts each of those constants to strings.

Definition at line 153 of file BitFlags.h.


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