library of assembled shared sources |
http://lass.cocamware.com |
Functions | |
template<typename T > | |
void | lass::util::setBit (T &a_bits, unsigned a_bit) |
Set a bit high. | |
template<typename T > | |
void | lass::util::clearBit (T &a_bits, unsigned a_bit) |
set a bit low. | |
template<typename T > | |
void | lass::util::flipBit (T &a_bits, unsigned a_bit) |
flip state of a bit (low->high, high->low). | |
template<typename T > | |
void | lass::util::setBitIf (T &a_bits, unsigned a_bit, bool a_condition) |
set a bit high if (and only if) a condition is fullfilled. | |
template<typename T > | |
void | lass::util::clearBitIf (T &a_bits, unsigned a_bit, bool a_condition) |
set a bit low if (and only if) a condition is fullfilled is true. | |
template<typename T > | |
void | lass::util::flipBitIf (T &a_bits, unsigned a_bit, bool a_condition) |
flip a bit if (and only if) a condition is fullfilled (low->high, high->low). | |
template<typename T > | |
void | lass::util::setBitTo (T &a_bits, unsigned a_bit, bool a_state) |
set a bit to a given state. | |
template<typename T > | |
bool | lass::util::checkBit (T a_bits, unsigned a_bit) |
return true if a bit is set high. | |
template<typename T > | |
void | lass::util::setMasked (T &a_bits, const T &a_mask) |
Set masked bits high. | |
template<typename T > | |
void | lass::util::clearMasked (T &a_bits, const T &a_mask) |
Set masked bits low. | |
template<typename T > | |
void | lass::util::flipMasked (T &a_bits, const T &a_mask) |
flip masked bits. | |
template<typename T > | |
void | lass::util::setMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Set masked bits high if (and only if) a condition is fullfilled. | |
template<typename T > | |
void | lass::util::clearMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Set masked bits low if (and only if) a condition is fullfilled. | |
template<typename T > | |
void | lass::util::flipMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Flip the masked bits if (and only if) a condition is fullfilled. | |
template<typename T > | |
void | lass::util::setMaskedTo (T &a_bits, const T &a_mask, bool a_state) |
Set the masked bits to a given state if (and only if) a condition is fullfilled. | |
template<typename T > | |
bool | lass::util::checkMaskedAll (T a_bits, const T &a_mask) |
Check the masked bits and return true if they are ALL set. | |
template<typename T > | |
bool | lass::util::checkMaskedSome (T a_bits, const T &a_mask) |
Check the masked bits and return true if at least one is set. | |
template<typename T > | |
const size_t | lass::util::countBits (T bits) |
returns number of set bits in bits | |
Variables | |
const size_t | lass::util::impl::bitsInByte [256] |
lookup table of number of bits in a byte |
int
, char
, unsigned
, ...
The functions are split in two groups. The bit routines (with the word Bit
in their names :) and the mask routines (with the word Mask
). The groups are very alike, except in the way you address the bits to affect. With the bit group you will address one single bit at one time, and you will indicate it by its index in the bit field (i.e. bit 0 is 0x01, bit 1 is 0x02, bit 2 is 0x04, ...). With the mask group, you can address multiple bits at once by setting these bits in the mask (e.g. to address bits 0 and 2, you'll use 0x05 as mask). These mask must be of the same type of the bitfield.
With the routines you can set bits to 1; clear bits to 0; flip bits (0 becomes 1, 1 becomes 0); set, clear or flip bits if a condition is fullfilled; set a bit to a given value (0 or 1); check if a bit is set. For all these operations you'll find a function in both the bit
group as in the mask
group, except for the last operation: to check if a bit is set. In the bit
group you'll find one function checkBit which will return true if the addressed bit is set. In the mask
group you'll find two: checkMaskedAll and checkMaskedSome. the former only returns true if all bits addressed by the mask are set (an and operation), the latter already returns true if at least some of the addressed bits are set (an or operation).
void lass::util::setBit | ( | T & | a_bits, | |
unsigned | a_bit | |||
) | [inline] |
Set a bit high.
a_bits | the bitfield of which a bit must be set high. | |
a_bit | the index of the bit to be set high (0 => 0x1, 1 => 0x2, ...) |
Definition at line 66 of file bit_manip.inl.
void lass::util::clearBit | ( | T & | a_bits, | |
unsigned | a_bit | |||
) | [inline] |
set a bit low.
a_bits | the bitfield of which a bit must be set low. | |
a_bit | the index of the bit to be set low (0 => 0x1, 1 => 0x2, ...) |
Definition at line 80 of file bit_manip.inl.
Referenced by lass::util::setBitTo().
void lass::util::flipBit | ( | T & | a_bits, | |
unsigned | a_bit | |||
) | [inline] |
flip state of a bit (low->high, high->low).
a_bits | the bitfield of which a bit must be flipped. | |
a_bit | the index of the bit to be flipped (0 => 0x1, 1 => 0x2, ...) |
Definition at line 94 of file bit_manip.inl.
void lass::util::setBitIf | ( | T & | a_bits, | |
unsigned | a_bit, | |||
bool | a_condition | |||
) | [inline] |
set a bit high if (and only if) a condition is fullfilled.
a_bits | the bitfield of which a bit must be set high. | |
a_bit | the index of the bit to be set high (0 => 0x1, 1 => 0x2, ...) | |
a_condition | true if the bit must be set high, false if not. |
Definition at line 109 of file bit_manip.inl.
References lass::util::setMasked().
Referenced by lass::util::setBitTo().
void lass::util::clearBitIf | ( | T & | a_bits, | |
unsigned | a_bit, | |||
bool | a_condition | |||
) | [inline] |
set a bit low if (and only if) a condition is fullfilled is true.
a_bits | the bitfield of which a bit must be set low. | |
a_bit | the index of the bit to be set low (0 => 0x1, 1 => 0x2, ...) | |
a_condition | true if the bit must be set low, false if not. |
Definition at line 124 of file bit_manip.inl.
References lass::util::clearMasked().
void lass::util::flipBitIf | ( | T & | a_bits, | |
unsigned | a_bit, | |||
bool | a_condition | |||
) | [inline] |
flip a bit if (and only if) a condition is fullfilled (low->high, high->low).
a_bits | the bitfield of which a bit must be flipped. | |
a_bit | the index of the bit to be flipped (0 => 0x1, 1 => 0x2, ...) | |
a_condition | true if the bit must be flipped, false if not. |
Definition at line 139 of file bit_manip.inl.
References lass::util::flipMasked().
void lass::util::setBitTo | ( | T & | a_bits, | |
unsigned | a_bit, | |||
bool | a_state | |||
) | [inline] |
set a bit to a given state.
a_bits | the bitfield of which a bit must be set. | |
a_bit | the index of the bit to be set (0 => 0x1, 1 => 0x2, ...) | |
a_state | the state to which the bit must be set: true for high, false for low. |
Definition at line 154 of file bit_manip.inl.
References lass::util::clearBit(), and lass::util::setBitIf().
bool lass::util::checkBit | ( | T | a_bits, | |
unsigned | a_bit | |||
) | [inline] |
return true if a bit is set high.
a_bits | the bitfield of which a bit must be checked. | |
a_bit | the index of the bit to be checked (0 => 0x1, 1 => 0x2, ...) |
Definition at line 169 of file bit_manip.inl.
void lass::util::setMasked | ( | T & | a_bits, | |
const T & | a_mask | |||
) | [inline] |
Set masked bits high.
a_bits | the bitfield of which some bits must be set high. | |
a_mask | mask indicating the bits that must be set high. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 187 of file bit_manip.inl.
Referenced by lass::util::setBitIf(), and lass::util::setMaskedIf().
void lass::util::clearMasked | ( | T & | a_bits, | |
const T & | a_mask | |||
) | [inline] |
Set masked bits low.
a_bits | the bitfield of which some bits must be set low. | |
a_mask | mask indicating the bits that must be set low. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 204 of file bit_manip.inl.
Referenced by lass::util::clearBitIf(), lass::util::clearMaskedIf(), and lass::util::setMaskedTo().
void lass::util::flipMasked | ( | T & | a_bits, | |
const T & | a_mask | |||
) | [inline] |
flip masked bits.
a_bits | the bitfield of which some bits must be flipped. | |
a_mask | mask indicating the bits that must be flipped. The high bits in the mask indicate the bits in the bitfield to be flipped, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 221 of file bit_manip.inl.
Referenced by lass::util::flipBitIf(), and lass::util::flipMaskedIf().
void lass::util::setMaskedIf | ( | T & | a_bits, | |
const T & | a_mask, | |||
bool | a_condition | |||
) | [inline] |
Set masked bits high if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set high. | |
a_mask | mask indicating the bits that must be set high. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. | |
a_condition | true if the bits must be set, false if not. |
Definition at line 239 of file bit_manip.inl.
References lass::util::setMasked(), and lass::stde::T.
Referenced by lass::util::setMaskedTo().
void lass::util::clearMaskedIf | ( | T & | a_bits, | |
const T & | a_mask, | |||
bool | a_condition | |||
) | [inline] |
Set masked bits low if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set low. | |
a_mask | mask indicating the bits that must be set low. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. | |
a_condition | true if the bits must be set, false if not. |
Definition at line 257 of file bit_manip.inl.
References lass::util::clearMasked(), and lass::stde::T.
void lass::util::flipMaskedIf | ( | T & | a_bits, | |
const T & | a_mask, | |||
bool | a_condition | |||
) | [inline] |
Flip the masked bits if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be flipped. | |
a_mask | mask indicating the bits that must be flipped. The high bits in the mask indicate the bits in the bitfield to be flipped, the low bits in the mask indicate the bits in the bitfield to be left untouched. | |
a_condition | true if the bits must be flipped, false if not. |
Definition at line 275 of file bit_manip.inl.
References lass::util::flipMasked(), and lass::stde::T.
void lass::util::setMaskedTo | ( | T & | a_bits, | |
const T & | a_mask, | |||
bool | a_state | |||
) | [inline] |
Set the masked bits to a given state if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set. | |
a_mask | mask indicating the bits that must be set. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. | |
a_state | the state to which the bits must be set: true for high, false for low. |
Definition at line 293 of file bit_manip.inl.
References lass::util::clearMasked(), and lass::util::setMaskedIf().
bool lass::util::checkMaskedAll | ( | T | a_bits, | |
const T & | a_mask | |||
) | [inline] |
Check the masked bits and return true if they are ALL set.
a_bits | the bitfield of which some bits must be checked. | |
a_mask | mask indicating the bits that must be checked. The high bits in the mask indicate the bits in the bitfield to be checked, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 313 of file bit_manip.inl.
bool lass::util::checkMaskedSome | ( | T | a_bits, | |
const T & | a_mask | |||
) | [inline] |
Check the masked bits and return true if at least one is set.
a_bits | the bitfield of which some bits must be checked. | |
a_mask | mask indicating the bits that must be checked. The high bits in the mask indicate the bits in the bitfield to be checked, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 331 of file bit_manip.inl.
Referenced by lass::io::ProxyOStream::Lock::operator<<().
const size_t lass::util::countBits | ( | T | bits | ) | [inline] |
const size_t lass::util::impl::bitsInByte[256] |
Initial value:
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }
Definition at line 344 of file bit_manip.inl.
Referenced by lass::util::impl::BitCounter< 8 >::count(), lass::util::impl::BitCounter< 4 >::count(), lass::util::impl::BitCounter< 2 >::count(), and lass::util::impl::BitCounter< 1 >::count().
Generated on Mon Nov 10 14:22:06 2008 for Library of Assembled Shared Sources by 1.5.7.1 |