nidas
v1.2-1520
|
A class for holding bits. More...
#include <BitArray.h>
Public Member Functions | |
BitArray (int lenbits) | |
Constructor, all bits will be initialized to 0. More... | |
BitArray (const BitArray &ba) | |
Copy constructor. More... | |
BitArray & | operator= (const BitArray &ba) |
Assignment operator. More... | |
~BitArray () | |
void | setBits (bool value) |
Set all bits to 1 if value is true, otherwise set all to 0. More... | |
void | setBit (int num, bool value) |
Set a bit, in range 0:(length()-1) to 1 if value is true, otherwise false. More... | |
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. More... | |
void | setBits64 (int begin, int end, unsigned long long bitmask) |
bool | getBit (int num) const |
Get value of a bit. More... | |
unsigned int | getBits (int begin, int end) |
Return a integer of bits. More... | |
long long | getBits64 (int begin, int end) |
Return a long long of bits. More... | |
unsigned char * | getPtr () |
Return pointer to first byte of BitArray. More... | |
const unsigned char * | getConstPtr () const |
Return const pointer to first byte of BitArray. More... | |
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. More... | |
int | getLengthInBytes () const |
Length of array, in bytes. More... | |
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. More... | |
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().
Referenced by nidas::dynld::raf::CVIProcessor::receive().
|
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(), 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().
Referenced by main().
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^(), nidas::util::operator^(), operator^=(), operator|(), nidas::util::operator|(), and operator|=().
|
inline |
Length of array, in bits.
References lenBits.
Referenced by all(), any(), getBit(), getBits(), getBits64(), operator&(), nidas::util::operator&(), operator&=(), nidas::util::operator==(), operator^(), nidas::util::operator^(), operator^=(), operator|(), nidas::util::operator|(), operator|=(), setBits(), setBits64(), and toString().
|
inline |
Length of array, in bytes.
References lenBytes.
Referenced by operator&(), nidas::util::operator&(), operator&=(), nidas::util::operator==(), operator^(), nidas::util::operator^(), operator^=(), operator|(), nidas::util::operator|(), operator|=(), setBit(), 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 getConstPtr(), getLength(), getLengthInBytes(), and getPtr().
References getConstPtr(), getLength(), and getLengthInBytes().
References getConstPtr(), getLength(), getLengthInBytes(), and getPtr().
References getConstPtr(), getLength(), and getLengthInBytes().
References getConstPtr(), 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 getLengthInBytes().
Referenced by main(), nidas::dynld::raf::CVIProcessor::receive(), 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(), nidas::dynld::IR104_Relays::getInputs(), nidas::dynld::ViperDIO::getInputs(), nidas::dynld::IR104_Relays::getOutputs(), nidas::dynld::ViperDIO::getOutputs(), and main().
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(), getBit(), getBits(), getBits64(), getConstPtr(), getPtr(), operator=(), setBit(), setBits(), and ~BitArray().
|
protected |
Referenced by getLength(), and operator=().
|
protected |
Referenced by BitArray(), getLengthInBytes(), and operator=().