nidas  v1.2-1520
Public Member Functions | Protected Attributes | List of all members
nidas::util::BitArray Class Reference

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...
 
BitArrayoperator= (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
 
BitArrayoperator|= (const BitArray &x)
 
BitArray operator| (const BitArray &x)
 
BitArrayoperator&= (const BitArray &x)
 
BitArray operator& (const BitArray &x)
 
BitArrayoperator^= (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
 

Detailed Description

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.

Constructor & Destructor Documentation

BitArray::BitArray ( int  lenbits)

Constructor, all bits will be initialized to 0.

References bits, lenBytes, and setBits().

BitArray::BitArray ( const BitArray ba)

Copy constructor.

References bits, and lenBytes.

BitArray::~BitArray ( )

References bits.

Member Function Documentation

bool nidas::util::BitArray::all ( ) const
inline

References getBit(), and getLength().

bool nidas::util::BitArray::all ( int  begin,
int  end 
) const
inline

References getBit(), and getLength().

bool nidas::util::BitArray::any ( ) const
inline
bool nidas::util::BitArray::any ( int  begin,
int  end 
) const
inline

References getBit(), and getLength().

bool nidas::util::BitArray::getBit ( int  num) const
inline

Get value of a bit.

Parameters
numIndex 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().

const unsigned char* nidas::util::BitArray::getConstPtr ( ) const
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|=().

int nidas::util::BitArray::getLength ( ) const
inline
int nidas::util::BitArray::getLengthInBytes ( ) const
inline
unsigned char* nidas::util::BitArray::getPtr ( )
inline

Return pointer to first byte of BitArray.

This will contain bits 0-7.

References bits.

Referenced by operator&=(), operator^=(), and operator|=().

BitArray BitArray::operator& ( const BitArray x)
BitArray & BitArray::operator&= ( const BitArray x)
BitArray & BitArray::operator= ( const BitArray ba)

Assignment operator.

References bits, lenBits, and lenBytes.

BitArray BitArray::operator^ ( const BitArray x)
BitArray & BitArray::operator^= ( const BitArray x)
BitArray BitArray::operator| ( const BitArray x)
BitArray & BitArray::operator|= ( const BitArray x)
void nidas::util::BitArray::setBit ( int  num,
bool  value 
)
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)
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.

Parameters
beginIndex of first bit, from 0, up to getLength()-1.
endIndex of last bit, from begin, up to getLength()-1.
bitmaskinteger 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().

Member Data Documentation

unsigned char* nidas::util::BitArray::bits
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().

int nidas::util::BitArray::lenBits
protected

Referenced by getLength(), and operator=().

int nidas::util::BitArray::lenBytes
protected

The documentation for this class was generated from the following files: