My Project
Public Member Functions | Protected Attributes | List of all members
Bitset Class Reference

Bitset is a basic class for handling bit sequences More...

#include <Bitset.h>

Inheritance diagram for Bitset:
BitsetExt

Public Member Functions

int Length ()
 The length of the Bitset.
 
std::ostream & Output (std::ostream &os) const
 Output the bits to selected ostream. More...
 
void clear ()
 Clear the bits.
 
void push_back (const bool bit)
 Push back one bit. More...
 
void push_back (const unsigned char b, const int bit_count=8)
 Push back bit_count bits from 'byte' b. More...
 
void push_back (const unsigned short s, const int bit_count=16)
 Push back bit_count bits from 'short' s. More...
 
void push_back (const unsigned long l, const int bit_count=32)
 Push back bit_count bits from 'long' l. More...
 
void push_back_meaningful (const unsigned long l)
 Push back meaningful bits from 'long' l. More...
 
void fill_zeros_left (const size_t bit_count)
 Fill the Bitset with non-meaningful zeros. More...
 
void push_back (std::string s)
 Push back a string of characters. More...
 
bool pop_front ()
 Pop the front bit.
 
bool pop_back ()
 Pop the back bit.
 
void flip (size_t pos)
 Flip the selected bit. More...
 
std::string hex ()
 The Bitset as a hex string.
 
unsigned long ulong ()
 The Bitset as 'unsigned long'.
 
unsigned char uchar ()
 The Bitset as 'unsigned char'.
 
std::deque< bool > & GetBits ()
 The Bitset as 'deque<bool>'.
 

Protected Attributes

std::deque< bool > bits
 

Detailed Description

Bitset is a basic class for handling bit sequences

The bits are stored internally using deque<bool> (See http://osdir.com/ml/gis.geos.devel/2006-04/msg00142.html). The bitset is assumed to have most significant bits left i.e. the push_back() methods add to the least significant end of the bit sequence. The usage is clarified by the following example.

Usage

Bitset b;
b.push_back(true);
b.push_back(false);
b.push_back(false);
b.push_back(false);
b.push_back(8, 4);
b.push_back(0x88, 8);
b.fill_zeros_left(32);
b.Output(std::cout); // b contains now: 00000000 00000000 10001000 10001000

Definition at line 63 of file Bitset.h.

Member Function Documentation

◆ fill_zeros_left()

void fill_zeros_left ( const size_t  bit_count)

Fill the Bitset with non-meaningful zeros.

Parameters
bit_countNon-meaningful zeros are added until this given bit_count is reached.

◆ flip()

void flip ( size_t  pos)

Flip the selected bit.

Parameters
posThe bit in this given position is flipped.

◆ Output()

std::ostream& Output ( std::ostream &  os) const

Output the bits to selected ostream.

Parameters
osThe output stream to be used for outputting e.g. std::cout

◆ push_back() [1/5]

void push_back ( const bool  bit)

Push back one bit.

Parameters
bitBoolean (true/false) to be pushed to the end of bit sequence.

◆ push_back() [2/5]

void push_back ( const unsigned char  b,
const int  bit_count = 8 
)

Push back bit_count bits from 'byte' b.

Parameters
bUnsigned character (8-bits) to be pushed to the end of bit sequence.
bit_countNumber of bits to be pushed (default/max is 8 bits)

◆ push_back() [3/5]

void push_back ( const unsigned long  l,
const int  bit_count = 32 
)

Push back bit_count bits from 'long' l.

Parameters
lUnsigned long (32-bits) to be pushed to the end of bit sequence.
bit_countNumber of bits to be pushed (default/max is 32 bits)

◆ push_back() [4/5]

void push_back ( const unsigned short  s,
const int  bit_count = 16 
)

Push back bit_count bits from 'short' s.

Parameters
sUnsigned short (16-bits) to be pushed to the end of bit sequence.
bit_countNumber of bits to be pushed (default/max is 16 bits)

◆ push_back() [5/5]

void push_back ( std::string  s)

Push back a string of characters.

Parameters
sString of characters to be pushed to the end of bit sequence.

◆ push_back_meaningful()

void push_back_meaningful ( const unsigned long  l)

Push back meaningful bits from 'long' l.

Parameters
lThe meaningful bits of the given unsigned long (32-bits) are pushed to the end of bit sequence.

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