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

Description

template<typename E, typename V = int64_t>
class Sawyer::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> 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);
}
};
Stores a vector of enum bit flags.
BitFlags & set(Enum e)
Set the specified bit.
BitFlags & clear(Enum e)
Clear the specified bit.
bool testAndClear(Enum e)
Test whether a bit is set, then clear it.

Definition at line 63 of file Sawyer/BitFlags.h.

#include <Sawyer/BitFlags.h>

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

Public Types

typedef E Enum
 
typedef V Vector
 

Public Member Functions

 BitFlags ()
 Default constructor with all bits clear.
 
 BitFlags (Vector v)
 Construct bit vector from value or bit.
 
 BitFlags (E e)
 
 BitFlags (const BitFlags &other)
 Copy constructor.
 
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.
 
std::vector< Enum > split () 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 Typedef Documentation

◆ Enum

template<typename E , typename V = int64_t>
typedef E Sawyer::BitFlags< E, V >::Enum

Definition at line 65 of file Sawyer/BitFlags.h.

◆ Vector

template<typename E , typename V = int64_t>
typedef V Sawyer::BitFlags< E, V >::Vector

Definition at line 66 of file Sawyer/BitFlags.h.

Constructor & Destructor Documentation

◆ BitFlags() [1/4]

template<typename E , typename V = int64_t>
Sawyer::BitFlags< E, V >::BitFlags ( )
inline

Default constructor with all bits clear.

Definition at line 93 of file Sawyer/BitFlags.h.

◆ BitFlags() [2/4]

template<typename E , typename V = int64_t>
Sawyer::BitFlags< E, V >::BitFlags ( Vector  v)
inline

Construct bit vector from value or bit.

Definition at line 97 of file Sawyer/BitFlags.h.

◆ BitFlags() [3/4]

template<typename E , typename V = int64_t>
Sawyer::BitFlags< E, V >::BitFlags ( e)
inline

Definition at line 100 of file Sawyer/BitFlags.h.

◆ BitFlags() [4/4]

template<typename E , typename V = int64_t>
Sawyer::BitFlags< E, V >::BitFlags ( const BitFlags< E, V > &  other)
inline

Copy constructor.

Definition at line 104 of file Sawyer/BitFlags.h.

Member Function Documentation

◆ vector()

template<typename E , typename V = int64_t>
Vector Sawyer::BitFlags< E, V >::vector ( ) const
inline

Current value of the bit vector.

Definition at line 108 of file Sawyer/BitFlags.h.

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

◆ isSet()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::isSet ( Enum  e) const
inline

◆ isAllSet()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::isAllSet ( BitFlags< E, V >  other) const
inline

True if all specified bits are set.

Definition at line 118 of file Sawyer/BitFlags.h.

◆ isAnySet() [1/2]

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::isAnySet ( BitFlags< E, V >  other) const
inline

True if any of the specified bits are set.

Definition at line 123 of file Sawyer/BitFlags.h.

◆ isAnySet() [2/2]

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::isAnySet ( ) const
inline

True if any bit is set.

Definition at line 128 of file Sawyer/BitFlags.h.

◆ isEmpty()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::isEmpty ( ) const
inline

True if no bits are set.

Definition at line 133 of file Sawyer/BitFlags.h.

◆ isClear()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::isClear ( Enum  e) const
inline

Test whether a bit is clear.

Definition at line 138 of file Sawyer/BitFlags.h.

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

Referenced by Rose::BinaryAnalysis::Debugger::Base::trace().

◆ set() [1/2]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::set ( Enum  e)
inline

Set the specified bit.

Definition at line 143 of file Sawyer/BitFlags.h.

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

◆ set() [2/2]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::set ( BitFlags< E, V >  other)
inline

Set all bits that are set in other.

Definition at line 149 of file Sawyer/BitFlags.h.

◆ clear() [1/3]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::clear ( Enum  e)
inline

Clear the specified bit.

Definition at line 155 of file Sawyer/BitFlags.h.

◆ clear() [2/3]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::clear ( BitFlags< E, V >  other)
inline

Clear all bits that are set in other.

Definition at line 161 of file Sawyer/BitFlags.h.

◆ clear() [3/3]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::clear ( )
inline

Clear all bits.

Definition at line 167 of file Sawyer/BitFlags.h.

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

◆ testAndClear()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::testAndClear ( Enum  e)
inline

Test whether a bit is set, then clear it.

Definition at line 173 of file Sawyer/BitFlags.h.

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

◆ testAndSet()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::testAndSet ( Enum  e)
inline

Test whether a bit is set, then set it.

Definition at line 180 of file Sawyer/BitFlags.h.

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

◆ operator=() [1/2]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::operator= ( Vector  v)
inline

Set the vector to an exact value.

Definition at line 187 of file Sawyer/BitFlags.h.

◆ operator=() [2/2]

template<typename E , typename V = int64_t>
BitFlags & Sawyer::BitFlags< E, V >::operator= ( BitFlags< E, V >  other)
inline

Set the vector to the same as another.

Definition at line 193 of file Sawyer/BitFlags.h.

◆ operator|() [1/2]

template<typename E , typename V = int64_t>
BitFlags Sawyer::BitFlags< E, V >::operator| ( BitFlags< E, V >  other) const
inline

Create a new vector that's the union of two vectors.

Definition at line 201 of file Sawyer/BitFlags.h.

◆ operator|() [2/2]

template<typename E , typename V = int64_t>
BitFlags Sawyer::BitFlags< E, V >::operator| ( Enum  e) const
inline

Create a new vector that's the union of two vectors.

Definition at line 204 of file Sawyer/BitFlags.h.

◆ intersection() [1/2]

template<typename E , typename V = int64_t>
BitFlags Sawyer::BitFlags< E, V >::intersection ( BitFlags< E, V >  other) const
inline

Create a new vector that's the intersection of two vectors.

Definition at line 212 of file Sawyer/BitFlags.h.

Referenced by Sawyer::BitFlags< E, V >::operator&(), and Sawyer::BitFlags< E, V >::operator&().

◆ intersection() [2/2]

template<typename E , typename V = int64_t>
BitFlags Sawyer::BitFlags< E, V >::intersection ( Enum  e) const
inline

Create a new vector that's the intersection of two vectors.

Definition at line 215 of file Sawyer/BitFlags.h.

◆ operator&() [1/2]

template<typename E , typename V = int64_t>
BitFlags Sawyer::BitFlags< E, V >::operator& ( BitFlags< E, V >  other) const
inline

Create a new vector that's the intersection of two vectors.

Definition at line 218 of file Sawyer/BitFlags.h.

References Sawyer::BitFlags< E, V >::intersection().

◆ operator&() [2/2]

template<typename E , typename V = int64_t>
BitFlags Sawyer::BitFlags< E, V >::operator& ( Enum  e) const
inline

Create a new vector that's the intersection of two vectors.

Definition at line 221 of file Sawyer/BitFlags.h.

References Sawyer::BitFlags< E, V >::intersection().

◆ operator==()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::operator== ( BitFlags< E, V >  other) const
inline

Compare two vectors.

Definition at line 229 of file Sawyer/BitFlags.h.

◆ operator!=()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::operator!= ( BitFlags< E, V >  other) const
inline

Compare two vectors.

Definition at line 232 of file Sawyer/BitFlags.h.

◆ operator<()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::operator< ( BitFlags< E, V >  other) const
inline

Compare two vectors.

Definition at line 235 of file Sawyer/BitFlags.h.

◆ operator<=()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::operator<= ( BitFlags< E, V >  other) const
inline

Compare two vectors.

Definition at line 238 of file Sawyer/BitFlags.h.

◆ operator>()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::operator> ( BitFlags< E, V >  other) const
inline

Compare two vectors.

Definition at line 241 of file Sawyer/BitFlags.h.

◆ operator>=()

template<typename E , typename V = int64_t>
bool Sawyer::BitFlags< E, V >::operator>= ( BitFlags< E, V >  other) const
inline

Compare two vectors.

Definition at line 244 of file Sawyer/BitFlags.h.

◆ split() [1/2]

template<typename E , typename V = int64_t>
std::vector< Enum > Sawyer::BitFlags< E, V >::split ( std::vector< int64_t >  constants,
Vector &  leftovers 
) const
inline

Split a vector into the individual enum values.

The enum constants are first sorted so that those with more set bits appear before those with fewer bits. Then each constant is searched in the bit vector and those bits are removed. This continues until either no bits remain or no matching constant is found. The leftovers is set to those bits that could not be matched by this process.

Definition at line 254 of file Sawyer/BitFlags.h.

◆ split() [2/2]

template<typename E , typename V = int64_t>
std::vector< Enum > Sawyer::BitFlags< E, V >::split ( ) const
inline

Split a vector into the individual bits values.

Definition at line 277 of file Sawyer/BitFlags.h.

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

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


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