Loading...
Searching...
No Matches
bitVector.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_DATATYPE_BITVECTOR_H
#define BALL_DATATYPE_BITVECTOR_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_CONCEPT_PERSISTENCEMANAGER_H
# include <BALL/CONCEPT/persistenceManager.h>
#endif
#ifndef BALL_COMMON_EXCEPTION_H
# include <BALL/COMMON/exception.h>
#endif
#include <cstring>
#define BALL_BLOCK_BITS 8
#define BALL_BLOCK_MASK (BALL_BLOCK_BITS - 1)
#define BALL_BLOCK_SHIFT 3
#define BALL_BLOCK_ALL_BITS_SET 0xFF
#define BALL_BLOCK_ALL_BITS_CLEARED 0x00
#define BALL_BLOCK_SIZE(bits) (Size)(((bits) + BALL_BLOCK_BITS - 1) >> BALL_BLOCK_SHIFT)
namespace BALL
{
class BitVector;
class BALL_EXPORT Bit
{
public:
class BALL_EXPORT IllegalOperation
: public Exception::GeneralException
{
public:
IllegalOperation(const char* file, int line);
};
BALL_CREATE(Bit)
Bit();
Bit(const Bit& bit);
Bit(BitVector* bitvector, Index index = 0);
Bit(const BitVector* const bitvector, Index index = 0);
virtual ~Bit();
operator bool() const;
Bit& operator = (const Bit& bit);
Bit& operator = (const bool bit);
virtual void clear();
bool operator == (const Bit& bit) const;
bool operator == (bool bit) const;
bool operator != (const Bit& bit) const;
bool operator != (bool bit) const;
private:
// --- ATTRIBUTES
BitVector* bitvector_;
Index index_;
bool bitvector_muteable_;
};
class BALL_EXPORT BitVector
{
public:
BALL_CREATE(BitVector)
typedef unsigned char BlockType;
typedef std::vector<BlockType> VectorType;
static const Size BlockSize;
static const Size CharBits;
BitVector();
BitVector(Size size);
BitVector(const BitVector& bit_vector);
BitVector(const char* bit_string);
virtual ~BitVector();
void clear();
void set(const BitVector& bit_vector);
void set(const char* bit_string);
BitVector& operator = (const BitVector& bit_vector);
BitVector& operator = (const char *bit_string);
void get(BitVector& bitvector) const;
BitVector operator () (Index first, Index last) const;
void setSize(Size size, bool keep = true);
Size getSize() const;
Size countValue(bool value) const;
VectorType& getBitSet();
const VectorType& getBitSet() 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);
BitVector& operator |= (const BitVector& bit_vector);
BitVector operator & (const BitVector& bit_vector);
BitVector& operator &= (const BitVector& bit_vector);
BitVector operator ^ (const BitVector& bit_vector);
BitVector& operator ^= (const BitVector& bit_vector);
BitVector operator ~ ();
bool operator == (const BitVector& bit_vector) const;
bool operator != (const BitVector& bit_vector) const;
bool isAnyBit(bool value, Index first = 0, Index last = -1) const;
bool isEveryBit(bool value, Index first = 0, Index last = -1) const;
bool isValid() const;
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);
virtual void read(std::istream& s);
virtual void write(std::ostream& s) const;
virtual void write(PersistenceManager& pm) const;
virtual bool read(PersistenceManager& pm);
protected:
// @exception Exception::IndexUnderflow
// @exception Exception::OutOfMemory
void validateIndex_(Index& index);
// @exception Exception::IndexUnderflow
// @exception Exception::OutOfMemory
void validateIndex_(Index& index) const;
// @exception Exception::IndexUnderflow
// @exception Exception::IndexOverflow
void validateRange_(Index& first, Index& last) const;
private:
// @exception Exception::IndexUnderflow
// @exception Exception::OutOfMemory
Index block_(Index index);
// @exception Exception::IndexUnderflow
// @exception Exception::OutOfMemory
Index block_(Index index) const;
BlockType mask_(Index index) const;
// --- ATTRIBUTES
Size size_;
VectorType bitset_;
};
# ifndef BALL_NO_INLINE_FUNCTIONS
# include <BALL/DATATYPE/bitVector.iC>
# endif
} //namespace BALL
#endif // BALL_DATATYPE_BITVECTOR_H
exception.h
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::BitVector
Definition bitVector.h:177
BALL::BitVector::getUnsignedShort
unsigned short getUnsignedShort() const
BALL::BitVector::isValid
bool isValid() const
BALL::BitVector::BlockType
unsigned char BlockType
Definition bitVector.h:188
BALL::BitVector::BitVector
BitVector()
BALL::BitVector::toggle
void toggle(Index first=0, Index last=-1)
BALL::BitVector::validateIndex_
void validateIndex_(Index &index)
BALL::BitVector::bitwiseXor
void bitwiseXor(const BitVector &bit_vector)
BALL::BitVector::isEveryBit
bool isEveryBit(bool value, Index first=0, Index last=-1) const
BALL::BitVector::setBit
void setBit(Index index, bool value=true)
BALL::BitVector::setUnsignedChar
void setUnsignedChar(unsigned char bit_pattern)
BALL::BitVector::fill
void fill(bool value=true, Index first=0, Index last=-1)
BALL::BitVector::getBitSet
VectorType & getBitSet()
BALL::BitVector::bitwiseAnd
void bitwiseAnd(const BitVector &bit_vector)
BALL::BitVector::getUnsignedLong
unsigned long getUnsignedLong() const
BALL::BitVector::setUnsignedInt
void setUnsignedInt(unsigned int bit_pattern)
BALL::BitVector::getSize
Size getSize() const
BALL::BitVector::clear
void clear()
BALL::BitVector::get
void get(BitVector &bitvector) const
BALL::BitVector::set
void set(const BitVector &bit_vector)
BALL::BitVector::VectorType
std::vector< BlockType > VectorType
Definition bitVector.h:190
BALL::BitVector::setUnsignedLong
void setUnsignedLong(unsigned long bit_pattern)
BALL::BitVector::countValue
Size countValue(bool value) const
BALL::BitVector::setUnsignedShort
void setUnsignedShort(unsigned short bit_pattern)
BALL::BitVector::getBit
bool getBit(Index index)
BALL::BitVector::read
virtual void read(std::istream &s)
BALL::BitVector::toggleBit
void toggleBit(Index index)
BALL::BitVector::CharBits
static const Size CharBits
Definition bitVector.h:194
BALL::BitVector::getUnsignedChar
unsigned char getUnsignedChar() const
BALL::BitVector::write
virtual void write(std::ostream &s) const
BALL::BitVector::BlockSize
static const Size BlockSize
Definition bitVector.h:192
BALL::BitVector::isAnyBit
bool isAnyBit(bool value, Index first=0, Index last=-1) const
BALL::BitVector::bitwiseOr
void bitwiseOr(const BitVector &bit_vector)
BALL::BitVector::setSize
void setSize(Size size, bool keep=true)
BALL::BitVector::getUnsignedInt
unsigned int getUnsignedInt() const
BALL::BitVector::validateRange_
void validateRange_(Index &first, Index &last) const
BALL::Bit::IllegalOperation::IllegalOperation
IllegalOperation(const char *file, int line)
BALL::Bit
Definition bitVector.h:43
BALL::Bit::Bit
Bit()
BALL::Bit::clear
virtual void clear()
BALL::Exception::GeneralException
Definition COMMON/exception.h:61
BALL::PersistenceManager
Definition persistenceManager.h:73
common.h
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Index
BALL_INDEX_TYPE Index
Definition COMMON/global.h:105
std
STL namespace.
persistenceManager.h