DCCL v3
dccl::Bitset Class Reference

A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy. Similar to set::bitset but can be resized at runtime and has the ability to have parent Bitsets that can give bits to their children. More...

#include <dccl/bitset.h>

Inheritance diagram for dccl::Bitset:
[legend]

## Public Member Functions

Bitset (Bitset *parent=0)
Construct an empty Bitset. More...

Bitset (size_type num_bits, unsigned long value=0, Bitset *parent=0)
Construct a Bitset of a certain initial size and value. More...

void get_more_bits (size_type num_bits)
Retrieve more bits from the parent Bitset. More...

Bitsetoperator&= (const Bitset &rhs)
Logical AND in place. More...

Bitsetoperator|= (const Bitset &rhs)
Logical OR in place. More...

Bitsetoperator^= (const Bitset &rhs)
Logical XOR in place. More...

Bitsetoperator<<= (size_type n)
Left shift in place. More...

Bitsetoperator>>= (size_type n)
Right shift in place. More...

Bitset operator<< (size_type n) const
Left shift. More...

Bitset operator>> (size_type n) const
Right shift. More...

Bitsetset (size_type n, bool val=true)
Set a bit to a given value. More...

Bitsetset ()
Set all bits true. More...

Bitsetreset (size_type n)
Reset a bit (i.e. set it to false) More...

Bitsetreset ()
Set all bits false. More...

Bitsetflip (size_type n)
Flip (toggle) a bit. More...

Bitsetflip ()
Flip (toggle) all bits. More...

bool test (size_type n) const
Test a bit (return its value) More...

template<typename IntType >
void from (IntType value, size_type num_bits=std::numeric_limits< IntType >::digits)
Sets value of the Bitset to the contents of an integer. More...

void from_ulong (unsigned long value, size_type num_bits=std::numeric_limits< unsigned long >::digits)
Sets value of the Bitset to the contents of an unsigned long integer. Equivalent to from<unsigned long>()

template<typename IntType >
IntType to () const
Returns the value of the Bitset as a integer. More...

unsigned long to_ulong () const
Returns the value of the Bitset as an unsigned long integer. Equivalent to to<unsigned long>().

std::string to_string () const
Returns the value of the Bitset as a printable string, where each bit is represented by '1' or '0'. The msb is written into the zero index of the string, so it is printed msb to lsb (as is standard for writing numbers).

std::string to_byte_string ()
Returns the value of the Bitset to a byte string, where each character represents 8 bits of the Bitset. The string is used as a byte container, and is not intended to be printed. More...

size_t to_byte_string (char *buf, size_t max_len)
Generate a byte string representation of the Bitset, where each character represents 8 bits of the Bitset. The string is used as a byte container, and is not intended to be printed. More...

void from_byte_string (const std::string &s)
Sets the value of the Bitset to the contents of a byte string, where each character represents 8 bits of the Bitset. More...

template<typename CharIterator >
void from_byte_stream (CharIterator begin, CharIterator end)
Sets the value of the Bitset to the contents of a byte string, where each character represents 8 bits of the Bitset. A string container the values where the least signficant byte in string[0] and the most significant byte in string[size()-1]. More...

Bitsetprepend (const Bitset &bits)
Adds the bitset to the little end.

Bitsetappend (const Bitset &bits)
Adds the bitset to the big end.

## Detailed Description

A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy. Similar to set::bitset but can be resized at runtime and has the ability to have parent Bitsets that can give bits to their children.

This is the class used within DCCL hold the encoded message as it is created. The front() of the deque represents the least significant bit (lsb) and the back() is the most significant bit (msb). DCCL messages are encoded and decoded starting with the lsb and ending at the msb. The hierarchy is used to represent parent bit pools from which the child can pull more bits from to decode. The top level Bitset represents the entire encoded message, whereas the children are the message fields.

Definition at line 38 of file bitset.h.

## Constructor & Destructor Documentation

 dccl::Bitset::Bitset ( Bitset * parent = 0 )
inlineexplicit

Construct an empty Bitset.

Parameters
 parent Pointer to a bitset that should be consider this Bitset's parent for calls to get_more_bits()

Definition at line 44 of file bitset.h.

 dccl::Bitset::Bitset ( size_type num_bits, unsigned long value = 0, Bitset * parent = 0 )
inlineexplicit

Construct a Bitset of a certain initial size and value.

Parameters
 num_bits Initial size of this Bitset value Initial value of the bits in this Bitset parent Pointer to a bitset that should be consider this Bitset's parent for calls to get_more_bits()

Definition at line 53 of file bitset.h.

## Member Function Documentation

 Bitset& dccl::Bitset::flip ( size_type n )
inline

Flip (toggle) a bit.

Parameters
 n bit to flip
Returns
A reference to the resulting Bitset

Definition at line 213 of file bitset.h.

 Bitset& dccl::Bitset::flip ( )
inline

Flip (toggle) all bits.

Returns
A reference to the resulting Bitset

Definition at line 219 of file bitset.h.

template<typename IntType >
 void dccl::Bitset::from ( IntType value, size_type num_bits = std::numeric_limits::digits )
inline

Sets value of the Bitset to the contents of an integer.

Parameters
 value Value to give the Bitset. num_bits The resulting size of the Bitset.

Definition at line 245 of file bitset.h.

template<typename CharIterator >
 void dccl::Bitset::from_byte_stream ( CharIterator begin, CharIterator end )
inline

Sets the value of the Bitset to the contents of a byte string, where each character represents 8 bits of the Bitset. A string container the values where the least signficant byte in string[0] and the most significant byte in string[size()-1].

Parameters
 begin Iterator pointing to the begining of the input buffer end Iterator pointing to the end of the input bufer

Definition at line 358 of file bitset.h.

 void dccl::Bitset::from_byte_string ( const std::string & s )
inline

Sets the value of the Bitset to the contents of a byte string, where each character represents 8 bits of the Bitset.

Parameters
 s A string container the values where the least signficant byte in string[0] and the most significant byte in string[size()-1]

Definition at line 348 of file bitset.h.

 void dccl::Bitset::get_more_bits ( size_type num_bits )
inline

Retrieve more bits from the parent Bitset.

Get (and remove) bits from the little end of the parent bitset and add them to the big end of our bitset, (the parent will request from their parent if required).

Parameters
 num_bits Number of bits to get.
Exceptions
 Exception The parent (and up the hierarchy, if applicable) do not have num_bits to give up.

Definition at line 447 of file bitset.h.

 Bitset& dccl::Bitset::operator&= ( const Bitset & rhs )
inline

Logical AND in place.

Apply the result of a logical AND of this Bitset and another to this Bitset.

Parameters
 rhs The Bitset to perform the operation on with this Bitset.
Returns
A reference to the resulting Bitset
Exceptions
 Exception The size of the two Bitsets are not equal.

Definition at line 74 of file bitset.h.

 Bitset dccl::Bitset::operator<< ( size_type n ) const
inline

Left shift.

Same as operator<<=() but does not modify this Bitset.

Definition at line 154 of file bitset.h.

 Bitset& dccl::Bitset::operator<<= ( size_type n )
inline

Left shift in place.

Shifts the Bitset to the left and inserts false (0) to the new least significant bits and discards any bits that come off the most significant end. This operation does not change the size of the Bitset.

Parameters
 n The number of bits to shift. This is equivalent to multiplying the Bitset by 2^n if the Bitset can hold the result
Returns
A reference to the resulting Bitset

Definition at line 125 of file bitset.h.

 Bitset dccl::Bitset::operator>> ( size_type n ) const
inline

Right shift.

Same as operator>>=() but does not modify this Bitset.

Definition at line 164 of file bitset.h.

 Bitset& dccl::Bitset::operator>>= ( size_type n )
inline

Right shift in place.

Shifts the Bitset to the right and inserts false (0) to the new most significant bits and discards any bits that come off the least significant end. This operation does not change the size of the Bitset.

Parameters
 n The number of bits to shift. This is equivalent to dividing the Bitset by 2^n
Returns
A reference to the resulting Bitset

Definition at line 141 of file bitset.h.

 Bitset& dccl::Bitset::operator^= ( const Bitset & rhs )
inline

Logical XOR in place.

Apply the result of a logical XOR of this Bitset and another to this Bitset.

Parameters
 rhs The Bitset to perform the operation on with this Bitset.
Returns
A reference to the resulting Bitset
Exceptions
 Exception The size of the two Bitsets are not equal.

Definition at line 106 of file bitset.h.

 Bitset& dccl::Bitset::operator|= ( const Bitset & rhs )
inline

Logical OR in place.

Apply the result of a logical OR of this Bitset and another to this Bitset.

Parameters
 rhs The Bitset to perform the operation on with this Bitset.
Returns
A reference to the resulting Bitset
Exceptions
 Exception The size of the two Bitsets are not equal.

Definition at line 90 of file bitset.h.

 Bitset& dccl::Bitset::reset ( size_type n )
inline

Reset a bit (i.e. set it to false)

Parameters
 n bit to reset
Returns
A reference to the resulting Bitset

Definition at line 196 of file bitset.h.

 Bitset& dccl::Bitset::reset ( )
inline

Set all bits false.

Returns
A reference to the resulting Bitset

Definition at line 202 of file bitset.h.

 Bitset& dccl::Bitset::set ( size_type n, bool val = true )
inline

Set a bit to a given value.

Parameters
 n bit to set val value to set the bit to
Returns
A reference to the resulting Bitset

Definition at line 176 of file bitset.h.

 Bitset& dccl::Bitset::set ( )
inline

Set all bits true.

Returns
A reference to the resulting Bitset

Definition at line 185 of file bitset.h.

 bool dccl::Bitset::test ( size_type n ) const
inline

Test a bit (return its value)

Parameters
 n bit to test
Returns
value of the bit

Definition at line 230 of file bitset.h.

template<typename IntType >
 IntType dccl::Bitset::to ( ) const
inline

Returns the value of the Bitset as a integer.

Returns
Value of the bitset
Exceptions
 Exception The integer type cannot represent the current Bitset.

Definition at line 267 of file bitset.h.

 std::string dccl::Bitset::to_byte_string ( )
inline

Returns the value of the Bitset to a byte string, where each character represents 8 bits of the Bitset. The string is used as a byte container, and is not intended to be printed.

Returns
A string containing the value of the Bitset, with the least signficant byte in string[0] and the most significant byte in string[size()-1]

Definition at line 310 of file bitset.h.

 size_t dccl::Bitset::to_byte_string ( char * buf, size_t max_len )
inline

Generate a byte string representation of the Bitset, where each character represents 8 bits of the Bitset. The string is used as a byte container, and is not intended to be printed.

Parameters
 buf An output string containing the value of the Bitset, with the least signficant byte in string[0] and the most significant byte in string[size()-1] max_len Maximum length of buf
Returns
number of bytes written to buf
Exceptions
 std::length_error if max_len < encoded length.

Definition at line 326 of file bitset.h.

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