awUtil::BitField128 acts as an array of booleans with the maximum size of 128.
Note that we do not need to export this class as it is completelly inlined. If you add non-inline methods, you will need to export it.
#include <awUtilBitField128.h>
Public Member Functions |
|
BitField128 () | |
The default constructor. All bits set to
false. |
|
~BitField128 () | |
BitField128 (const BitField128 &) | |
Copy constructor. |
|
BitField128 & | operator= (const BitField128 &) |
Assignment operator. |
|
int | maxAvailableBits () const |
Just a convenience, mostly for unit testing.
|
|
void | resetAll () |
Set all the bits to false. |
|
void | setAll () |
Set all the bits to true. |
|
BitRef128 | 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 BitField128 &) const |
Equals operator needs to compare both 64-bit
integers. |
|
bool | operator!= (const BitField128 &) const |
Not-equals operator needs to compare both
64-bit integers. |
|
BitField128 & | setBit (int, bool) |
Set the specified bit to the specified
value. |
|
bool | testBit (int) const |
Return true if the bit is set, false
otherwise. |
|
bool | anySet () const |
Return true if any of the bits are set to
true, false otherwise. |
|
bool | allSet () const |
Return true iff all the bits are set to
true. |
|
BitField128 | operator~ () const |
Make a copy and return it. |
|
BitField128 | operator^ (const BitField128 &mask) const |
Return a copy that is a result of the ^=
operation with the mask. |
|
BitField128 | operator& (const BitField128 &mask) const |
Return a copy that is a result of the &=
operation with the mask. |
|
BitField128 | operator| (const BitField128 &mask) const |
Return a copy that is a result of the |=
operation with the mask. |
|
BitField128 & | operator^= (const BitField128 &mask) |
Update the bits by exclusive or-ing them
with the mask bits. |
|
BitField128 & | operator&= (const BitField128 &mask) |
Update the bits by and-ing them with the
mask bits. |
|
BitField128 & | operator|= (const BitField128 &mask) |
Update the bits by or-ing them with the mask
bits. |
BitField128 | ( | ) | [inline] |
The default constructor. All bits set to false.
{ m_bits[0] = UINT64_C(0); m_bits[1] = UINT64_C(0); }
~BitField128 | ( | ) | [inline] |
{ }
BitField128 | ( | const BitField128 & | rhs | ) | [inline] |
Copy constructor.
{ m_bits[0] = rhs.m_bits[0]; m_bits[1] = rhs.m_bits[1]; }
BitField128 & operator= | ( | const BitField128 & | rhs | ) | [inline] |
Assignment operator.
{ m_bits[0] = rhs.m_bits[0]; m_bits[1] = rhs.m_bits[1]; return *this; }
int maxAvailableBits | ( | ) | const [inline] |
Just a convenience, mostly for unit testing.
The number of bits is already encoded in the name.
{
return 2 * kNumberBitsInUint64;
}
void resetAll | ( | ) | [inline] |
Set all the bits to false.
{ m_bits[0] = UINT64_C(0); m_bits[1] = UINT64_C(0); }
void setAll | ( | ) | [inline] |
Set all the bits to true.
{ m_bits[0] = ~UINT64_C(0); m_bits[1] = ~UINT64_C(0); }
BitRef128 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 BitRef128(*this,i); }
bool operator[] | ( | int | i | ) | const [inline] |
Constant version of the index operator behaving as testBit(i).
{ return testBit(i); }
bool operator== | ( | const BitField128 & | rhs | ) | const [inline] |
Equals operator needs to compare both 64-bit integers.
{
return ((m_bits[0] == rhs.m_bits[0]) &&
(m_bits[1] == rhs.m_bits[1]));
}
bool operator!= | ( | const BitField128 & | rhs | ) | const [inline] |
Not-equals operator needs to compare both 64-bit integers.
{ return !operator==(rhs); }
BitField128 & setBit | ( | int | i, |
bool | b | ||
) | [inline] |
Set the specified bit to the specified value.
Make sure that the bit argument is in [0,128) range or bad things happen.
{ assert((i >= 0) && (i < 128)); int iEl = i / kNumberBitsInUint64; uint64_t bit = UINT64_C(1) << (i-(iEl*kNumberBitsInUint64)); if (b) m_bits[iEl] |= bit; // Set bit else m_bits[iEl] &= ~bit; // Clear bit return *this; }
bool testBit | ( | int | i | ) | const [inline] |
Return true if the bit is set, false otherwise.
Make sure that the argument is in [0,128) range or bad things happen.
{ assert((i >= 0) && (i < 128)); int iEl = i / kNumberBitsInUint64; uint64_t bit = UINT64_C(1) << (i-(iEl*kNumberBitsInUint64)); return ((m_bits[iEl] & bit) == bit); }
bool anySet | ( | ) | const [inline] |
Return true if any of the bits are set to true, false otherwise.
{
return ((UINT64_C(0) != m_bits[0]) ||
(UINT64_C(0) != m_bits[1]));
}
bool allSet | ( | ) | const [inline] |
Return true iff all the bits are set to true.
{
return ((~UINT64_C(0) == m_bits[0]) &&
(~UINT64_C(0) == m_bits[1]));
}
BitField128 operator~ | ( | ) | const [inline] |
Make a copy and return it.
The bits in the copy are reversed.
{ BitField128 res; res.m_bits[0] = ~m_bits[0]; res.m_bits[1] = ~m_bits[1]; return res; }
BitField128 operator^ | ( | const BitField128 & | mask | ) | const [inline] |
Return a copy that is a result of the ^= operation with the mask.
{ BitField128 res( *this ); res ^= mask; return res; }
BitField128 operator& | ( | const BitField128 & | mask | ) | const [inline] |
Return a copy that is a result of the &= operation with the mask.
{ BitField128 res( *this ); res &= mask; return res; }
BitField128 operator| | ( | const BitField128 & | mask | ) | const [inline] |
Return a copy that is a result of the |= operation with the mask.
{ BitField128 res( *this ); res |= mask; return res; }
BitField128 & operator^= | ( | const BitField128 & | mask | ) | [inline] |
Update the bits by exclusive or-ing them with the mask bits.
{ m_bits[0] ^= mask.m_bits[0]; m_bits[1] ^= mask.m_bits[1]; return *this; }
BitField128 & operator&= | ( | const BitField128 & | mask | ) | [inline] |
Update the bits by and-ing them with the mask bits.
{ m_bits[0] &= mask.m_bits[0]; m_bits[1] &= mask.m_bits[1]; return *this; }
BitField128 & operator|= | ( | const BitField128 & | mask | ) | [inline] |
Update the bits by or-ing them with the mask bits.
{ m_bits[0] |= mask.m_bits[0]; m_bits[1] |= mask.m_bits[1]; return *this; }