BALL 1.5.0
Loading...
Searching...
No Matches
BALL::BitVector Class Reference

#include <BALL/DATATYPE/bitVector.h>

Public Member Functions

Constructors and Destructors
 BitVector ()
 
 BitVector (Size size)
 
 BitVector (const BitVector &bit_vector)
 
 BitVector (const char *bit_string)
 
virtual ~BitVector ()
 
void clear ()
 
Assignment
void set (const BitVector &bit_vector)
 
void set (const char *bit_string)
 
BitVectoroperator= (const BitVector &bit_vector)
 
BitVectoroperator= (const char *bit_string)
 
void get (BitVector &bitvector) const
 
Accessors
BitVector operator() (Index first, Index last) const
 
void setSize (Size size, bool keep=true)
 
Size getSize () const
 
Size countValue (bool value) const
 
VectorTypegetBitSet ()
 
const VectorTypegetBitSet () const
 
Bit operator[] (Index index)
 
bool operator[] (Index index) const
 
void setBit (Index index, bool value=true)
 
bool getBit (Index index)
 
bool getBit (Index index) const
 
void toggleBit (Index index)
 
void fill (bool value=true, Index first=0, Index last=-1)
 
void toggle (Index first=0, Index last=-1)
 
void setUnsignedChar (unsigned char bit_pattern)
 
unsigned char getUnsignedChar () const
 
void setUnsignedShort (unsigned short bit_pattern)
 
unsigned short getUnsignedShort () const
 
void setUnsignedInt (unsigned int bit_pattern)
 
unsigned int getUnsignedInt () const
 
void setUnsignedLong (unsigned long bit_pattern)
 
unsigned long getUnsignedLong () const
 
void bitwiseOr (const BitVector &bit_vector)
 
void bitwiseXor (const BitVector &bit_vector)
 
void bitwiseAnd (const BitVector &bit_vector)
 
BitVector operator| (const BitVector &bit_vector)
 
BitVectoroperator|= (const BitVector &bit_vector)
 
BitVector operator& (const BitVector &bit_vector)
 
BitVectoroperator&= (const BitVector &bit_vector)
 
BitVector operator^ (const BitVector &bit_vector)
 
BitVectoroperator^= (const BitVector &bit_vector)
 
BitVector operator~ ()
 
Predicates
bool operator== (const BitVector &bit_vector) const
 Equality operator.
 
bool operator!= (const BitVector &bit_vector) const
 Inequality operator.
 
bool isAnyBit (bool value, Index first=0, Index last=-1) const
 
bool isEveryBit (bool value, Index first=0, Index last=-1) const
 
Debugging and Diagnostics
bool isValid () const
 

Type Definitions and Constants

typedef unsigned char BlockType
 
typedef std::vector< BlockTypeVectorType
 
static const Size BlockSize
 
static const Size CharBits
 

Storers

virtual void read (std::istream &s)
 
virtual void write (std::ostream &s) const
 
virtual void write (PersistenceManager &pm) const
 
virtual bool read (PersistenceManager &pm)
 
BALL_EXPORT friend std::istream & operator>> (std::istream &s, BitVector &bit_vector)
 
BALL_EXPORT friend std::ostream & operator<< (std::ostream &s, const BitVector &bit_vector)
 
void validateIndex_ (Index &index)
 
void validateIndex_ (Index &index) const
 
void validateRange_ (Index &first, Index &last) const
 

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.

Definition at line 176 of file bitVector.h.

Member Typedef Documentation

◆ BlockType

Definition at line 188 of file bitVector.h.

◆ VectorType

Definition at line 190 of file bitVector.h.

Constructor & Destructor Documentation

◆ BitVector() [1/4]

BALL::BitVector::BitVector ( )

Default constructor

◆ BitVector() [2/4]

BALL::BitVector::BitVector ( Size size)

Detailed constructor

Exceptions
Exception::OutOfMemoryif a BitVector with length size could not be allocated

◆ BitVector() [3/4]

BALL::BitVector::BitVector ( const BitVector & bit_vector)

Copy constructor

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ BitVector() [4/4]

BALL::BitVector::BitVector ( const char * bit_string)

Detailled constructor from an array of char. {Caveat:} the array of char has to be zero-terminated!

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ ~BitVector()

virtual BALL::BitVector::~BitVector ( )
virtual

Destructor

Member Function Documentation

◆ bitwiseAnd()

void BALL::BitVector::bitwiseAnd ( const BitVector & bit_vector)

Compute {this and bit_vector}. The result is saved in this instance.

Exceptions
Exception::OutOfMemory

◆ bitwiseOr()

void BALL::BitVector::bitwiseOr ( const BitVector & bit_vector)

Compute {this or bit_vector}. The result is saved in this instance.

Exceptions
Exception::OutOfMemory

◆ bitwiseXor()

void BALL::BitVector::bitwiseXor ( const BitVector & bit_vector)

Compute {this xor bit_vector}. The result is saved in this instance.

Exceptions
Exception::OutOfMemory

◆ clear()

void BALL::BitVector::clear ( )

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

◆ countValue()

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

Count a given bool value in this instance.

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

◆ fill()

void BALL::BitVector::fill ( bool value = true,
Index first = 0,
Index last = -1 )

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
valuethe value to be set
firstthe starting position
lastthe last element to be filled
Exceptions
Exception::IndexUnderflow
Exception::OutOfMemory

◆ get()

void BALL::BitVector::get ( BitVector & bitvector) const

Assignment to an other BitVector.

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ getBit() [1/2]

bool BALL::BitVector::getBit ( Index index)

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
indexthe index of the element
Returns
bool the value of the element
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ getBit() [2/2]

bool BALL::BitVector::getBit ( Index index) const

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
indexthe index of the element
Returns
bool the value of the element
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ getBitSet() [1/2]

VectorType & BALL::BitVector::getBitSet ( )

Return a muteable pointer to the values of this instance.

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

◆ getBitSet() [2/2]

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

Return a constant pointer to the values of this instance.

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

◆ getSize()

Size BALL::BitVector::getSize ( ) const

Return the size of this instance.

◆ getUnsignedChar()

unsigned char BALL::BitVector::getUnsignedChar ( ) const

Get the bit pattern as unsigned char. For example: 00010110 => 22.

Returns
unsigned char the bit-pattern

◆ getUnsignedInt()

unsigned int BALL::BitVector::getUnsignedInt ( ) const

Get the bit pattern as unsigned int.

See also
getUnsignedChar

◆ getUnsignedLong()

unsigned long BALL::BitVector::getUnsignedLong ( ) const

Get the bit pattern as unsigned long.

See also
getUnsignedChar

◆ getUnsignedShort()

unsigned short BALL::BitVector::getUnsignedShort ( ) const

Get the bit pattern as unsigned short.

See also
getUnsignedChar

◆ isAnyBit()

bool BALL::BitVector::isAnyBit ( bool value,
Index first = 0,
Index last = -1 ) const

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

Parameters
valuethe value to look for
firstthe index to start searching
lastthe index to stop searching
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ isEveryBit()

bool BALL::BitVector::isEveryBit ( bool value,
Index first = 0,
Index last = -1 ) const

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

Parameters
valuethe value to look for
firstthe index to start searching
lastthe index to stop searching
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ isValid()

bool BALL::BitVector::isValid ( ) const

Test if this instance is valid.

◆ operator!=()

bool BALL::BitVector::operator!= ( const BitVector & bit_vector) const

Inequality operator.

◆ operator&()

BitVector BALL::BitVector::operator& ( const BitVector & bit_vector)

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

Exceptions
Exception::OutOfMemory

◆ operator&=()

BitVector & BALL::BitVector::operator&= ( const BitVector & bit_vector)

Compute {this and bit_vector}. The result is saved in this instance.

Exceptions
Exception::OutOfMemory

◆ operator()()

BitVector BALL::BitVector::operator() ( Index first,
Index last ) const

Return a sub-BitVector. A new BitVector is created and filled with elements of this instance.

Parameters
firstthe index of the first element to be copied
lastthe index of the last element to be copied
Returns
BitVector a partial copy of this instance
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ operator=() [1/2]

BitVector & BALL::BitVector::operator= ( const BitVector & bit_vector)

Assignment from an other BitVector instance.

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ operator=() [2/2]

BitVector & BALL::BitVector::operator= ( const char * bit_string)

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

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ operator==()

bool BALL::BitVector::operator== ( const BitVector & bit_vector) const

Equality operator.

◆ operator[]() [1/2]

Bit BALL::BitVector::operator[] ( Index index)

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
Exceptions
Exception::OutOfMemoryif the bit could not be allocated

◆ operator[]() [2/2]

bool BALL::BitVector::operator[] ( Index index) const

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
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ operator^()

BitVector BALL::BitVector::operator^ ( const BitVector & bit_vector)

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

Exceptions
Exception::OutOfMemory

◆ operator^=()

BitVector & BALL::BitVector::operator^= ( const BitVector & bit_vector)

Compute {this xor bit_vector}. The result is saved in this instance.

Exceptions
Exception::OutOfMemory

◆ operator|()

BitVector BALL::BitVector::operator| ( const BitVector & bit_vector)

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

Exceptions
Exception::OutOfMemory

◆ operator|=()

BitVector & BALL::BitVector::operator|= ( const BitVector & bit_vector)

Compute {this or bit_vector}. The result is saved in this instance.

Exceptions
Exception::OutOfMemory

◆ operator~()

BitVector BALL::BitVector::operator~ ( )

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

Exceptions
Exception::OutOfMemory

◆ read() [1/2]

virtual bool BALL::BitVector::read ( PersistenceManager & pm)
virtual

Storable read method.

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ read() [2/2]

virtual void BALL::BitVector::read ( std::istream & s)
virtual

Read the values of of type bool from an istream.

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ set() [1/2]

void BALL::BitVector::set ( const BitVector & bit_vector)

Assignment from an other BitVector instance.

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ set() [2/2]

void BALL::BitVector::set ( const char * bit_string)

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!

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ setBit()

void BALL::BitVector::setBit ( Index index,
bool value = true )

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
indexthe index of the element
valuethe value to be set
Exceptions
Exception::IndexUnderflow
Exception::IndexOverflow

◆ setSize()

void BALL::BitVector::setSize ( Size size,
bool keep = true )

Set the size of this instance.

Parameters
sizethe new size
keep?????
Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

◆ setUnsignedChar()

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

Set a unsigned char as the bit pattern. For example: 22 => 00010110.

Parameters
bit_patternthe new pattern.

◆ setUnsignedInt()

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

Set a unsigned int as the bit pattern.

See also
setUnsignedChar

◆ setUnsignedLong()

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

Set a unsigned long as the bit pattern.

See also
setUnsignedChar

◆ setUnsignedShort()

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

Set a unsigned short as the bit pattern.

See also
setUnsignedChar

◆ toggle()

void BALL::BitVector::toggle ( Index first = 0,
Index last = -1 )

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
valuethe value to be set
firstthe starting position
lastthe last element to be filled
Exceptions
Exception::IndexUnderflow
Exception::OutOfMemory

◆ toggleBit()

void BALL::BitVector::toggleBit ( Index index)

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

Parameters
indexthe index of the element
Exceptions
Exception::IndexUnderflow
Exception::OutOfMemory

◆ validateIndex_() [1/2]

void BALL::BitVector::validateIndex_ ( Index & index)
protected

◆ validateIndex_() [2/2]

void BALL::BitVector::validateIndex_ ( Index & index) const
protected

◆ validateRange_()

void BALL::BitVector::validateRange_ ( Index & first,
Index & last ) const
protected

◆ write() [1/2]

virtual void BALL::BitVector::write ( PersistenceManager & pm) const
virtual

Storable write method.

◆ write() [2/2]

virtual void BALL::BitVector::write ( std::ostream & s) const
virtual

Write the values of of type bool to an ostream.

Friends And Related Symbol Documentation

◆ operator<<

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

Output operator. Writes the values of type bool to an ostream.

◆ operator>>

BALL_EXPORT friend std::istream & operator>> ( std::istream & s,
BitVector & bit_vector )
friend

Input operator. Reads the values of type bool from an istream.

Exceptions
Exception::OutOfMemoryif a BitVector with the appropriate size could not be allocated

Member Data Documentation

◆ BlockSize

const Size BALL::BitVector::BlockSize
static

Definition at line 192 of file bitVector.h.

◆ CharBits

const Size BALL::BitVector::CharBits
static

Definition at line 194 of file bitVector.h.