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

Description

template<typename E, typename V = int64_t>
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 59 of file Rose/BitFlags.h.

#include <BitFlags.h>

Inheritance diagram for Rose::BitFlags< E, V >:
Inheritance graph
[legend]
Collaboration diagram for Rose::BitFlags< E, V >:
Collaboration graph
[legend]

Public Types

typedef E Enum
 
typedef V Vector
 
- Public Types inherited from Sawyer::BitFlags< E, int64_t >
typedef E Enum
 
typedef int64_t Vector
 

Public Member Functions

 BitFlags ()
 Default constructor with all bits clear.
 
 BitFlags (Vector v)
 Construct bit vector from value or bit.
 
 BitFlags (Sawyer::BitFlags< E, V > bf)
 
std::string toString (std::vector< int64_t > constants, const char *(*stringifier)(int64_t)) const
 Convert to string. More...
 
- Public Member Functions inherited from Sawyer::BitFlags< E, int64_t >
 BitFlags ()
 Default constructor with all bits clear.
 
 BitFlags (Vector v)
 Construct bit vector from value or bit.
 
 BitFlags (E e)
 
Vector vector () const
 Current value of the bit vector.
 
bool isSet (Enum e) const
 Test whether a bit is set.
 
bool isAllSet (BitFlags other) const
 True if all specified bits are set.
 
bool isAnySet (BitFlags other) const
 True if any of the specified bits are set.
 
bool isAnySet () const
 True if any bit is set.
 
bool isEmpty () const
 True if no bits are set.
 
bool isClear (Enum e) const
 Test whether a bit is clear.
 
BitFlagsset (Enum e)
 Set the specified bit.
 
BitFlagsset (BitFlags other)
 Set all bits that are set in other.
 
BitFlagsclear (Enum e)
 Clear the specified bit.
 
BitFlagsclear (BitFlags other)
 Clear all bits that are set in other.
 
BitFlagsclear ()
 Clear all bits.
 
bool testAndClear (Enum e)
 Test whether a bit is set, then clear it.
 
bool testAndSet (Enum e)
 Test whether a bit is set, then set it.
 
BitFlagsoperator= (Vector v)
 Set the vector to an exact value.
 
BitFlagsoperator= (BitFlags other)
 Set the vector to the same as another.
 
std::vector< Enum > split (std::vector< int64_t > constants, Vector &leftovers) const
 Split a vector into the individual enum values. More...
 
std::vector< Enum > split (Vector &leftovers) const
 Split a vector into the individual bits values.
 
BitFlags operator| (BitFlags other) const
 Create a new vector that's the union of two vectors.
 
BitFlags operator| (Enum e) const
 Create a new vector that's the union of two vectors.
 
BitFlags intersection (BitFlags other) const
 Create a new vector that's the intersection of two vectors.
 
BitFlags intersection (Enum e) const
 Create a new vector that's the intersection of two vectors.
 
BitFlags operator& (BitFlags other) const
 Create a new vector that's the intersection of two vectors.
 
BitFlags operator& (Enum e) const
 Create a new vector that's the intersection of 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.
 
bool operator>= (BitFlags other) const
 Compare two vectors.
 

Member Function Documentation

◆ toString()

template<typename E , typename V = int64_t>
std::string Rose::BitFlags< E, V >::toString ( std::vector< int64_t >  constants,
const char *(*)(int64_t)  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 79 of file Rose/BitFlags.h.

References Sawyer::BitFlags< E, int64_t >::split(), and Sawyer::BitFlags< E, int64_t >::vector().

Here is the call graph for this function:

The documentation for this class was generated from the following file:
Rose::Color::Layer::NONE
@ NONE
No specific layer.
Definition: Color.h:54