Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

BitVector Class Reference
[Miscellaneous]

Bit vector class. More...

#include <bitVector.h>

List of all members.

Type Definitions and Constants

typedef unsigned char BlockType
typedef std::vector< BlockType > VectorType
const Size BlockSize

Storers

virtual void read (std::istream &s) throw (Exception::OutOfMemory)
 Read the values of of type bool from an istream.
virtual void write (std::ostream &s) const throw ()
 Write the values of of type bool to an ostream.
virtual void write (PersistenceManager &pm) const throw ()
 Storable write method.
virtual bool read (PersistenceManager &pm) throw (Exception::OutOfMemory)
 Storable read method.
BALL_EXPORT friend std::istream & operator>> (std::istream &s, BitVector &bit_vector) throw (Exception::OutOfMemory)
 Input operator.
BALL_EXPORT friend std::ostream & operator<< (std::ostream &s, const BitVector &bit_vector) throw ()
 Output operator.

Public Member Functions

Constructors and Destructors
 BitVector () throw ()
 Default constructor.
 BitVector (Size size) throw (Exception::OutOfMemory)
 Detailled constructor.
 BitVector (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Copy constructor.
 BitVector (const char *bit_string) throw (Exception::OutOfMemory)
 Detailled constructor from an array of char.
virtual ~BitVector () throw ()
 Destructor.
void clear () throw ()
 Clear method.
Assignment
void set (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Assignment from an other BitVector instance.
void set (const char *bit_string) throw (Exception::OutOfMemory)
 Assignment from a char string.
BitVectoroperator= (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Assignment from an other BitVector instance.
BitVectoroperator= (const char *bit_string) throw (Exception::OutOfMemory)
 Assignment from a char string.
void get (BitVector &bitvector) const throw (Exception::OutOfMemory)
 Assignment to an other BitVector.
Accessors
BitVector operator() (Index first, Index last) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 Return a sub-BitVector.
void setSize (Size size, bool keep=true) throw (Exception::OutOfMemory)
 Set the size of this instance.
Size getSize () const throw ()
 Return the size of this instance.
Size countValue (bool value) const throw ()
 Count a given bool value in this instance.
VectorType & getBitSet () throw ()
 Return a muteable pointer to the values of this instance.
const VectorType & getBitSet () const throw ()
 Return a constant pointer to the values of this instance.
Bit operator[] (Index index) throw (Exception::OutOfMemory)
 Random access to the components.
bool operator[] (Index index) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 Constant random access to the components.
void setBit (Index index, bool value=true) throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 Set the given Bit.
bool getBit (Index index) throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 Get the value of an element.
bool getBit (Index index) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 Get the value of an element (const version).
void toggleBit (Index index) throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 Toggle the value of an element.
void fill (bool value=true, Index first=0, Index last=-1) throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 Fill a part of this instance with a given value.
void toggle (Index first=0, Index last=-1) throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 Toggle the values of a part of this instance.
void setUnsignedChar (unsigned char bit_pattern) throw ()
 Set a unsigned char as the bit pattern.
unsigned char getUnsignedChar () const throw ()
 Get the bit pattern as unsigned char.
void setUnsignedShort (unsigned short bit_pattern) throw ()
 Set a unsigned short as the bit pattern.
unsigned short getUnsignedShort () const throw ()
 Get the bit pattern as unsigned short.
void setUnsignedInt (unsigned int bit_pattern) throw ()
 Set a unsigned int as the bit pattern.
unsigned int getUnsignedInt () const throw ()
 Get the bit pattern as unsigned int.
void setUnsignedLong (unsigned long bit_pattern) throw ()
 Set a unsigned long as the bit pattern.
unsigned long getUnsignedLong () const throw ()
 Get the bit pattern as unsigned long.
void bitwiseOr (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Compute {this or bit_vector}.
void bitwiseXor (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Compute {this xor bit_vector}.
void bitwiseAnd (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Compute {this and bit_vector}.
BitVector operator| (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Or Operator.
BitVectoroperator|= (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Compute {this or bit_vector}.
BitVector operator & (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 And Operator.
BitVectoroperator &= (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Compute {this and bit_vector}.
BitVector operator^ (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Xor Operator.
BitVectoroperator^= (const BitVector &bit_vector) throw (Exception::OutOfMemory)
 Compute {this xor bit_vector}.
BitVector operator~ () throw (Exception::OutOfMemory)
 Negate Operator.
Predicates
bool operator== (const BitVector &bit_vector) const throw ()
 Equality operator.
bool operator!= (const BitVector &bit_vector) const throw ()
 Inequality operator.
bool isAnyBit (bool value, Index first=0, Index last=-1) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 Test if any bit in a given range has the given value.
bool isEveryBit (bool value, Index first=0, Index last=-1) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 Test if every bit in a given range has the given value.
Debugging and Diagnostics
bool isValid () const throw ()
 Test if this instance is valid.

Protected Member Functions

void validateIndex_ (Index &index) throw (Exception::IndexUnderflow, Exception::OutOfMemory)
void validateIndex_ (Index &index) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
void validateRange_ (Index &first, Index &last) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)


Detailed Description

Bit vector class.

Indices may be given as negative arguments: start from the end -1 therefore means the last bit. Some functions resize the instance if a index greater than the size of the instance is given. Other functions throw exception in this case.


Constructor & Destructor Documentation

BitVector::BitVector const char *  bit_string  )  throw (Exception::OutOfMemory)
 

Detailled constructor from an array of char.

{Caveat:} the array of char has to be zero-terminated!


Member Function Documentation

void BitVector::bitwiseAnd const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Compute {this and bit_vector}.

The result is saved in this instance.

void BitVector::bitwiseOr const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Compute {this or bit_vector}.

The result is saved in this instance.

void BitVector::bitwiseXor const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Compute {this xor bit_vector}.

The result is saved in this instance.

void BitVector::clear  )  throw ()
 

Clear method.

This method will set the size of this instance to 0.

Size BitVector::countValue bool  value  )  const throw ()
 

Count a given bool value in this instance.

Parameters:
value the value to be counted
Returns:
Size the number of the given value

void BitVector::fill bool  value = true,
Index  first = 0,
Index  last = -1
throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 

Fill a part of this instance with a given value.

If a given index is greater than the size of this instance an exception is thrown.

Parameters:
value the value to be set
first the starting position
last the last element to be filled

bool BitVector::getBit Index  index  )  const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 

Get the value of an element (const version).

If the given index is greater than the size of this instance an exception is thrown. No resizing is done.

Parameters:
index the index of the element
Returns:
bool the value of the element

bool BitVector::getBit Index  index  )  throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 

Get the value of an element.

If the given index is greater than the size of this instance, this BitVector is increased to the given index.

Parameters:
index the index of the element
Returns:
bool the value of the element

const VectorType& BitVector::getBitSet  )  const throw ()
 

Return a constant pointer to the values of this instance.

Returns:
unsigned char* a constant pointer to the values of this instance

VectorType& BitVector::getBitSet  )  throw ()
 

Return a muteable pointer to the values of this instance.

Returns:
unsigned char* a muteable pointer to the values of this instance

Size BitVector::getSize  )  const throw ()
 

Return the size of this instance.

unsigned char BitVector::getUnsignedChar  )  const throw ()
 

Get the bit pattern as unsigned char.

For example: 00010110 => 22.

Returns:
unsigned char the bit-pattern

unsigned int BitVector::getUnsignedInt  )  const throw ()
 

Get the bit pattern as unsigned int.

See also:
getUnsignedChar

unsigned long BitVector::getUnsignedLong  )  const throw ()
 

Get the bit pattern as unsigned long.

See also:
getUnsignedChar

unsigned short BitVector::getUnsignedShort  )  const throw ()
 

Get the bit pattern as unsigned short.

See also:
getUnsignedChar

bool BitVector::isAnyBit bool  value,
Index  first = 0,
Index  last = -1
const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 

Test if any bit in a given range has the given value.

Parameters:
value the value to look for
first the index to start searching
last the index to stop searching

bool BitVector::isEveryBit bool  value,
Index  first = 0,
Index  last = -1
const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 

Test if every bit in a given range has the given value.

Parameters:
value the value to look for
first the index to start searching
last the index to stop searching

bool BitVector::isValid  )  const throw ()
 

Test if this instance is valid.

BitVector BitVector::operator & const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

And Operator.

Creates a new BitVector object and fills it with the result of {this and bit_Vector}.

BitVector& BitVector::operator &= const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Compute {this and bit_vector}.

The result is saved in this instance.

BitVector BitVector::operator() Index  first,
Index  last
const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 

Return a sub-BitVector.

A new BitVector is created and filled with elements of this instance.

Parameters:
first the index of the first element to be copied
last the index of the last element to be copied
Returns:
BitVector a partial copy of this instance

BitVector& BitVector::operator= const char *  bit_string  )  throw (Exception::OutOfMemory)
 

Assignment from a char string.

If a char is different from '0', it is interpreted as true.

bool BitVector::operator[] Index  index  )  const throw (Exception::IndexUnderflow, Exception::IndexOverflow)
 

Constant random access to the components.

If the given index is greater than the size of this instance an exception is thrown.

Returns:
bool the value of the given index

Bit BitVector::operator[] Index  index  )  throw (Exception::OutOfMemory)
 

Random access to the components.

If the given index is greater than the size of this instance, this BitVector is increased to the given index.

Returns:
Bit a Bit pointing to the given element of this instance

BitVector BitVector::operator^ const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Xor Operator.

Creates a new BitVector object and fills it with the result of {this Xor bit_vector}.

BitVector& BitVector::operator^= const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Compute {this xor bit_vector}.

The result is saved in this instance.

BitVector BitVector::operator| const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Or Operator.

Creates a new BitVector object and fills it with the result of {this or bit_Vector}.

BitVector& BitVector::operator|= const BitVector bit_vector  )  throw (Exception::OutOfMemory)
 

Compute {this or bit_vector}.

The result is saved in this instance.

BitVector BitVector::operator~  )  throw (Exception::OutOfMemory)
 

Negate Operator.

Creates a new BitVector object and fills it with the negate result of this instance.

virtual bool BitVector::read PersistenceManager pm  )  throw (Exception::OutOfMemory) [virtual]
 

Storable read method.

virtual void BitVector::read std::istream &  s  )  throw (Exception::OutOfMemory) [virtual]
 

Read the values of of type bool from an istream.

void BitVector::set const char *  bit_string  )  throw (Exception::OutOfMemory)
 

Assignment from a char string.

If a char is different from '0', it is interpreted as true. {Caveat:} the array of char has to be zero-terminated!

void BitVector::setBit Index  index,
bool  value = true
throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 

Set the given Bit.

The element at the given position is set to the given value. If the given index is greater than the size of this instance, this BitVector is increased to the given index.

Parameters:
index the index of the element
value the value to be set

void BitVector::setSize Size  size,
bool  keep = true
throw (Exception::OutOfMemory)
 

Set the size of this instance.

Parameters:
size the new size
keep ?????

void BitVector::setUnsignedChar unsigned char  bit_pattern  )  throw ()
 

Set a unsigned char as the bit pattern.

For example: 22 => 00010110.

Parameters:
bit_pattern the new pattern.

void BitVector::setUnsignedInt unsigned int  bit_pattern  )  throw ()
 

Set a unsigned int as the bit pattern.

See also:
setUnsignedChar

void BitVector::setUnsignedLong unsigned long  bit_pattern  )  throw ()
 

Set a unsigned long as the bit pattern.

See also:
setUnsignedChar

void BitVector::setUnsignedShort unsigned short  bit_pattern  )  throw ()
 

Set a unsigned short as the bit pattern.

See also:
setUnsignedChar

void BitVector::toggle Index  first = 0,
Index  last = -1
throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 

Toggle the values of a part of this instance.

If a given index is greater than the size of this instance an exception is thrown.

Parameters:
value the value to be set
first the starting position
last the last element to be filled

void BitVector::toggleBit Index  index  )  throw (Exception::IndexUnderflow, Exception::OutOfMemory)
 

Toggle the value of an element.

If the given index is greater than the size of this instance an exception is thrown.

Parameters:
index the index of the element

virtual void BitVector::write PersistenceManager pm  )  const throw () [virtual]
 

Storable write method.

virtual void BitVector::write std::ostream &  s  )  const throw () [virtual]
 

Write the values of of type bool to an ostream.


Friends And Related Function Documentation

BALL_EXPORT friend std::ostream& operator<< std::ostream &  s,
const BitVector bit_vector
throw () [friend]
 

Output operator.

Writes the values of type bool to an ostream.

BALL_EXPORT friend std::istream& operator>> std::istream &  s,
BitVector bit_vector
throw (Exception::OutOfMemory) [friend]
 

Input operator.

Reads the values of type bool from an istream.