awUtil::BitFieldAuto acts as an array of booleans with no maximum size.
It will automatically resize when you set the items. Note that the penalty for the automatic resize is that some operations do not make sense (operator~() or setAll() for example).
#include <awUtilBitFieldAuto.h>
Public Member Functions |
|
BitFieldAuto () | |
The default constructor. |
|
BitFieldAuto (int reserveSize) | |
Allocate enough space for resSize bits.
|
|
~BitFieldAuto () | |
BitFieldAuto (const BitFieldAuto &) | |
BitFieldAuto & | operator= (const BitFieldAuto &) |
void | reserveSize (int) |
void | resetAll () |
int | maxAvailableBits () const |
This value will change as the bitfield
grows. |
|
BitRefAuto | operator[] (int) |
Index operator that returns a reference
appropriate for LHS usage. |
|
bool | operator[] (int) const |
Constant version of the index operator
behaving as testBit(i). |
|
bool | operator== (const BitFieldAuto &) const |
bool | operator!= (const BitFieldAuto &) const |
Not-equals operator uses the operator== to
reduce code duplication. |
|
BitFieldAuto & | setBit (int, bool) |
bool | testBit (int) const |
Return true if the bit is set, false
otherwise. |
|
bool | anySet () const |
BitFieldAuto | operator^ (const BitFieldAuto &mask) const |
BitFieldAuto | operator& (const BitFieldAuto &mask) const |
BitFieldAuto | operator| (const BitFieldAuto &mask) const |
BitFieldAuto & | operator^= (const BitFieldAuto &mask) |
BitFieldAuto & | operator&= (const BitFieldAuto &mask) |
BitFieldAuto & | operator|= (const BitFieldAuto &mask) |
bool | testBits (const BitFieldAuto &) const |
BitFieldAuto | ( | ) | [inline] |
The default constructor.
Allocate a single element, so that we will have 8 * sizeof(unsigned int) bits ready to go. If you have a better size hint, use the other constructor.
: m_bits( 1 ) { }
BitFieldAuto | ( | int | resSize | ) | [inline] |
Allocate enough space for resSize bits.
None are set, and this will not change the behaviour of the class, but would potentially optimize the memory allocation.
: m_bits() { reserveSize( resSize ); }
~BitFieldAuto | ( | ) | [inline] |
{ }
BitFieldAuto | ( | const BitFieldAuto & | ) |
BitFieldAuto& operator= | ( | const BitFieldAuto & | ) |
void reserveSize | ( | int | ) |
void resetAll | ( | ) |
int maxAvailableBits | ( | ) | const |
This value will change as the bitfield grows.
BitRefAuto operator[] | ( | int | i | ) | [inline] |
Index operator that returns a reference appropriate for LHS usage.
This is why you can do "bits[8] = true;" or something like that.
{ return BitRefAuto(*this,i); }
bool operator[] | ( | int | i | ) | const [inline] |
Constant version of the index operator behaving as testBit(i).
{ return testBit(i); }
bool operator== | ( | const BitFieldAuto & | ) | const |
bool operator!= | ( | const BitFieldAuto & | rhs | ) | const [inline] |
Not-equals operator uses the operator== to reduce code duplication.
{ return !(*this == rhs); }
BitFieldAuto& setBit | ( | int | , |
bool | |||
) |
bool testBit | ( | int | i | ) | const [inline] |
Return true if the bit is set, false otherwise.
Make sure that the argument is non-negative or bad things happen. If the value of the argument is beyond the allocated bit count, we happily return false.
{ assert(i >= 0); int iEl = i / kNumberBitsInUnsignedInt; unsigned int bit = ((unsigned int)1) << (i-(iEl*kNumberBitsInUnsignedInt)); return ((iEl < m_bits.size()) && ((m_bits[iEl] & bit) == bit)); }
bool anySet | ( | ) | const |
BitFieldAuto operator^ | ( | const BitFieldAuto & | mask | ) | const |
BitFieldAuto operator& | ( | const BitFieldAuto & | mask | ) | const |
BitFieldAuto operator| | ( | const BitFieldAuto & | mask | ) | const |
BitFieldAuto& operator^= | ( | const BitFieldAuto & | mask | ) |
BitFieldAuto& operator&= | ( | const BitFieldAuto & | mask | ) |
BitFieldAuto& operator|= | ( | const BitFieldAuto & | mask | ) |
bool testBits | ( | const BitFieldAuto & | ) | const |