awUtil::BitField64 acts as an array of booleans with the maximum size of 64.
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 <awUtilBitField64.h>
Public Member Functions |
|
BitField64 () | |
The default constructor. All bits set to
false. |
|
BitField64 (uint64_t) | |
Create with the bits as in the given 64-bit
integer. |
|
~BitField64 () | |
BitField64 (const BitField64 &) | |
Copy constructor. |
|
BitField64 & | operator= (const BitField64 &) |
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. |
|
BitRef64 | 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 BitField64 &) const |
Equals operator needs to compare the 64-bit
integers. |
|
bool | operator!= (const BitField64 &) const |
Not-equals operator needs to compare the
64-bit integers. |
|
BitField64 & | 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. |
|
BitField64 | operator~ () const |
Make a copy and return it. |
|
BitField64 | operator^ (const BitField64 &mask) const |
Return a copy that is a result of the ^
operation on the bits. |
|
BitField64 | operator& (const BitField64 &mask) const |
Return a copy that is a result of the &
operation on the bits. |
|
BitField64 | operator| (const BitField64 &mask) const |
Return a copy that is a result of the |
operation on the bits. |
|
BitField64 & | operator^= (const BitField64 &mask) |
Update the bits by exclusive or-ing them
with the mask bits. |
|
BitField64 & | operator&= (const BitField64 &mask) |
Update the bits by and-ing them with the
mask bits. |
|
BitField64 & | operator|= (const BitField64 &mask) |
Update the bits by or-ing them with the mask
bits. |
BitField64 | ( | ) | [inline] |
The default constructor. All bits set to false.
: m_bits(UINT64_C(0)) { }
BitField64 | ( | uint64_t | val | ) | [inline] |
Create with the bits as in the given 64-bit integer.
: m_bits(val) { }
~BitField64 | ( | ) | [inline] |
{ }
BitField64 | ( | const BitField64 & | rhs | ) | [inline] |
Copy constructor.
: m_bits(rhs.m_bits) { }
BitField64 & operator= | ( | const BitField64 & | rhs | ) | [inline] |
Assignment operator.
{ m_bits = rhs.m_bits; return *this; }
int maxAvailableBits | ( | ) | const [inline] |
Just a convenience, mostly for unit testing.
The number of bits is already encoded in the name.
{ return 8 * sizeof(uint64_t); }
void resetAll | ( | ) | [inline] |
void setAll | ( | ) | [inline] |
BitRef64 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 BitRef64(*this,i); }
bool operator[] | ( | int | i | ) | const [inline] |
Constant version of the index operator behaving as testBit(i).
{ return testBit(i); }
bool operator== | ( | const BitField64 & | rhs | ) | const [inline] |
Equals operator needs to compare the 64-bit integers.
{
return (m_bits == rhs.m_bits);
}
bool operator!= | ( | const BitField64 & | rhs | ) | const [inline] |
Not-equals operator needs to compare the 64-bit integers.
{ return !operator==(rhs); }
BitField64 & setBit | ( | int | i, |
bool | b | ||
) | [inline] |
Set the specified bit to the specified value.
Make sure that the bit argument is in [0,64) range or bad things happen.
{ assert((i >= 0) && (i < 64)); uint64_t bit = (UINT64_C(1) << (i)); if (b) m_bits |= bit; // Set bit else m_bits &= ~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,64) range or bad things happen.
{
assert((i >= 0) && (i < 64));
uint64_t bit = (UINT64_C(1) << (i));
return ((m_bits & 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);
}
bool allSet | ( | ) | const [inline] |
Return true iff all the bits are set to true.
{
return (~UINT64_C(0) == m_bits);
}
BitField64 operator~ | ( | ) | const [inline] |
Make a copy and return it.
The bits in the copy are reversed.
{ BitField64 res; res.m_bits = ~m_bits; return res; }
BitField64 operator^ | ( | const BitField64 & | mask | ) | const [inline] |
Return a copy that is a result of the ^ operation on the bits.
{ BitField64 res; res.m_bits = m_bits ^ mask.m_bits; return res; }
BitField64 operator& | ( | const BitField64 & | mask | ) | const [inline] |
Return a copy that is a result of the & operation on the bits.
{ BitField64 res( *this ); res &= mask; return res; }
BitField64 operator| | ( | const BitField64 & | mask | ) | const [inline] |
Return a copy that is a result of the | operation on the bits.
{ BitField64 res( *this ); res |= mask; return res; }
BitField64 & operator^= | ( | const BitField64 & | mask | ) | [inline] |
Update the bits by exclusive or-ing them with the mask bits.
{ m_bits ^= mask.m_bits; return *this; }
BitField64 & operator&= | ( | const BitField64 & | mask | ) | [inline] |
Update the bits by and-ing them with the mask bits.
{ m_bits &= mask.m_bits; return *this; }
BitField64 & operator|= | ( | const BitField64 & | mask | ) | [inline] |
Update the bits by or-ing them with the mask bits.
{ m_bits |= mask.m_bits; return *this; }