|
nidas v1.2.3
|
A class for holding bits. More...
#include <BitArray.h>
Public Member Functions | |
| BitArray (int lenbits) | |
| Constructor, all bits will be initialized to 0. | |
| BitArray (const BitArray &ba) | |
| Copy constructor. | |
| BitArray & | operator= (const BitArray &ba) |
| Assignment operator. | |
| ~BitArray () | |
| void | setBits (bool value) |
| Set all bits to 1 if value is true, otherwise set all to 0. | |
| void | setBit (int num, bool value) |
| Set a bit, in range 0:(length()-1) to 1 if value is true, otherwise false. | |
| void | setBits (int begin, int end, unsigned int bitmask) |
| Set all bits from begin, up to, but not including, end, to the corresponding bits in bitmask. | |
| void | setBits64 (int begin, int end, unsigned long long bitmask) |
| bool | getBit (int num) const |
| Get value of a bit. | |
| unsigned int | getBits (int begin, int end) |
| Return a integer of bits. | |
| long long | getBits64 (int begin, int end) |
| Return a long long of bits. | |
| unsigned char * | getPtr () |
| Return pointer to first byte of BitArray. | |
| const unsigned char * | getConstPtr () const |
| Return const pointer to first byte of BitArray. | |
| bool | any () const |
| bool | all () const |
| bool | any (int begin, int end) const |
| bool | all (int begin, int end) const |
| int | getLength () const |
| Length of array, in bits. | |
| int | getLengthInBytes () const |
| Length of array, in bytes. | |
| std::string | toString () const |
| BitArray & | operator|= (const BitArray &x) |
| BitArray | operator| (const BitArray &x) |
| BitArray & | operator&= (const BitArray &x) |
| BitArray | operator& (const BitArray &x) |
| BitArray & | operator^= (const BitArray &x) |
| BitArray | operator^ (const BitArray &x) |
Protected Attributes | |
| unsigned char * | bits |
| To make things portable across different machine endiannesses we represent the bits in an array of chars, rather than in integers. | |
| int | lenBits |
| int | lenBytes |
A class for holding bits.
Supports setting/getting individual bits in an array. Could be used by an object that is setting/getting relays, for example.
| BitArray::BitArray | ( | int | lenbits | ) |
| BitArray::~BitArray | ( | ) |
References bits.
|
inline |
References getBit(), and getLength().
|
inline |
References getBit(), and getLength().
|
inline |
References getBit(), and getLength().
|
inline |
References getBit(), and getLength().
|
inline |
Get value of a bit.
| num | Index of bit, in range 0:(getLength()-1). Does not check for indices outside of range. |
References bits, and getLength().
Referenced by all(), all(), any(), any(), getBits(), getBits64(), main(), and toString().
| unsigned int BitArray::getBits | ( | int | begin, |
| int | end ) |
Return a integer of bits.
Low order bits in the results will contain the low bits.
References bits, getBit(), and getLength().
| long long BitArray::getBits64 | ( | int | begin, |
| int | end ) |
Return a long long of bits.
Low order bits in the results will contain the low bits.
References bits, getBit(), and getLength().
|
inline |
Return const pointer to first byte of BitArray.
This will contain bits 0-7.
References bits.
Referenced by operator&(), nidas::util::operator&(), operator^(), nidas::util::operator^(), operator|(), and nidas::util::operator|().
|
inline |
Length of array, in bits.
References lenBits.
Referenced by all(), all(), any(), any(), getBit(), getBits(), getBits64(), operator&(), operator&=(), operator^(), operator^=(), operator|(), operator|=(), setBit(), setBits(), setBits(), setBits64(), and toString().
|
inline |
Length of array, in bytes.
References lenBytes.
Referenced by operator&(), operator&=(), operator^(), operator^=(), operator|(), operator|=(), and setBits().
|
inline |
Return pointer to first byte of BitArray.
This will contain bits 0-7.
References bits.
Referenced by operator&=(), operator^=(), and operator|=().
References getConstPtr(), getLength(), and getLengthInBytes().
References getLength(), getLengthInBytes(), and getPtr().
References getConstPtr(), getLength(), and getLengthInBytes().
References getLength(), getLengthInBytes(), and getPtr().
References getConstPtr(), getLength(), and getLengthInBytes().
References getLength(), getLengthInBytes(), and getPtr().
|
inline |
Set a bit, in range 0:(length()-1) to 1 if value is true, otherwise false.
Silently ignores requests out of range.
References bits, and getLength().
Referenced by setBits(), setBits(), and setBits64().
| void BitArray::setBits | ( | bool | value | ) |
Set all bits to 1 if value is true, otherwise set all to 0.
References bits, getLength(), getLengthInBytes(), and setBit().
Referenced by BitArray().
| void BitArray::setBits | ( | int | begin, |
| int | end, | ||
| unsigned int | bitmask ) |
Set all bits from begin, up to, but not including, end, to the corresponding bits in bitmask.
Bit 0 from bitmask is copied to begin, bit 1 to begin+1, etc.
| begin | Index of first bit, from 0, up to getLength()-1. |
| end | Index of last bit, from begin, up to getLength()-1. |
| bitmask | integer containing source bits to be copied, with bit 0 in the least significant byte. If (end - begin) is greater than 32, then end is silently adjusted to begin+32. |
References getLength(), and setBit().
| void BitArray::setBits64 | ( | int | begin, |
| int | end, | ||
| unsigned long long | bitmask ) |
References getLength(), and setBit().
| std::string BitArray::toString | ( | ) | const |
References getBit(), and getLength().
|
protected |
To make things portable across different machine endiannesses we represent the bits in an array of chars, rather than in integers.
Bits 0-7 are in bits[0], 8-15 in bits[1], etc.
Referenced by BitArray(), BitArray(), getBit(), getBits(), getBits64(), getConstPtr(), getPtr(), operator=(), setBit(), setBits(), and ~BitArray().
|
protected |
Referenced by getLength(), and operator=().
|
protected |
Referenced by BitArray(), BitArray(), getLengthInBytes(), and operator=().