Main Page   Reference Manual   Compound List   File List  

libecc::bitset< n > Class Template Reference

A bitset with a fixed number of bits. More...

#include <libecc/bitset.h>

Inheritance diagram for libecc::bitset< n >:

Inheritance graph
[legend]
Collaboration diagram for libecc::bitset< n >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef bitset_iterator< n,
forwards_iterating > 
const_iterator
 Non-mutable iterator.

typedef bitset_iterator< n,
backwards_iterating > 
const_reverse_iterator
 Reverse non-mutable iterator.


Public Methods

 bitset (void)
 Construct an uninitialized bitset of n bits.

 bitset (std::string const &)
 Construct a bitset of n bits and initialize it with the string input, a hexadecimal value in ASCII representation.

 bitset (bitset_digit_t low_bits)
 Construct a bitset of which only the least significant bits are set.

 bitset (bitset_digit_t const(&v)[bitset_base< n >::digits])
 Construct a bitset directly from an array of bitset_digit_t.

template<unsigned int m, bool inverted>  bitset (bitset_invertible< m, inverted > const &)
 Copy constructor.

template<unsigned int m, bool i1, bool i2, typename OP>  bitset (Operator::bitsetExpression< m, i1, i2, OP > const &expr)
 Construct a bitset from an expression.

template<typename Expression> bitset & operator= (Expression const &)
 Assignment operator.

template<typename Expression> bitset & operator &= (Expression const &)
 Assignment operator with bitwise AND.

template<typename Expression> bitset & operator|= (Expression const &)
 Assignment operator with bitwise OR.

template<typename Expression> bitset & operator^= (Expression const &)
 Assignment operator with bitwise XOR.

template<unsigned int shift, class DIRECTION, class OPERATION> void shift_op (bitset &result) const
 Perform a shift operation followed by a bit operation.

bitset & operator<<= (unsigned int shift)
 Shift bitset shift bits to the left.  Use the faster bitset::shift_op for constant distance shifts.

bitset & operator>>= (unsigned int shift)
 Shift bitset shift bits to the right.  Use the faster bitset::shift_op for constant distance shifts.

template<unsigned int shift, class DIRECTION> void rotate (bitset &result) const
 Rotate bitset.

bool test (size_t n) const
 Test bit at position pos.

bool odd (void) const
 Returns true when the bitset contains an odd number of bits.

void set (size_t n)
 Set bit at position pos.

void clear (size_t n)
 Clear bit at position pos.

void flip (size_t n)
 Toggle bit at position pos.

bool test (bitset_index const &index) const
 Test a bit at position index.

void set (bitset_index const &index)
 Set bit at position index.

void clear (bitset_index const &index)
 Clear bit at position index.

void flip (bitset_index const &index)
 Toggle bit at position index.

template<unsigned int pos> bool test (void) const
 Test a bit at a fixed position.

template<unsigned int pos> void set (void)
 Set a bit at a fixed position.

template<unsigned int pos> void clear (void)
 Clear a bit at a fixed position.

template<unsigned int pos> void flip (void)
 Toggle a bit at a fixed position.

bitset & reset (void)
 Reset all bits to 0.

void setall (void)
 Set all bits to 1.

bool any (void) const
 Return true if any bit is set.

const_iterator begin (void) const
 Return an iterator to the first bit.

const_iterator end (void) const
 Return an iterator one past the last bit.

const_reverse_iterator rbegin (void) const
 Return a reverse iterator to bit n-1.

const_reverse_iterator rend (void) const
 Return a reverse iterator one before the first bit.

template<unsigned int m> void xor_with_zero_padded (bitset< m > const &bitset, int lsb, int msb, int shift)
 Shift bitset left or right and XOR with this bitset.


Detailed Description

template<unsigned int n>
class libecc::bitset< n >

A bitset with a fixed number of bits.

Parameters:
n  The number of bits in the bitset.


Member Typedef Documentation

template<unsigned int n>
typedef bitset_iterator<n, forwards_iterating> libecc::bitset< n >::const_iterator
 

Non-mutable iterator.

template<unsigned int n>
typedef bitset_iterator<n, backwards_iterating> libecc::bitset< n >::const_reverse_iterator
 

Reverse non-mutable iterator.


Constructor & Destructor Documentation

template<unsigned int n>
libecc::bitset< n >::bitset void    [inline]
 

Construct an uninitialized bitset of n bits.

template<unsigned int n>
libecc::bitset< n >::bitset std::string const &    input
 

Construct a bitset of n bits and initialize it with the string input, a hexadecimal value in ASCII representation.

Input is a string of alphanumeric characters ([0-9A-F]) not case sensitive. The input string is read right to left. Any non-space character that is not a hexadecimal digit will terminate reading.

Spaces will be ignored, allowing one to write for example "C20 93B0D12C F78A9001 F6E2841F 0A918FCD" instead of the less readable "C2093B0D12CF78A9001F6E2841F0A918FCD". It is common practise to let each "word" represent an internal digit (32 bits in this example).

If the value passed is larger than fits in the bitset then the most significant bits (the left most characters) are ignored as if the value did fit and then a bit-wise AND was performed with a bitset of n 1's.

Parameters:
input  A hexadecimal value in ASCII representation.

template<unsigned int n>
libecc::bitset< n >::bitset bitset_digit_t    low_bits [inline, explicit]
 

Construct a bitset of which only the least significant bits are set.

low_bits must never have more bits set than the size of the bitset n.

template<unsigned int n>
libecc::bitset< n >::bitset bitset_digit_t const &    v[bitset_base< n >::digits] [inline]
 

Construct a bitset directly from an array of bitset_digit_t.

The excess bits of the most significant digit (if any) must be zero.

template<unsigned int n>
template<unsigned int m, bool inverted>
libecc::bitset< n >::bitset bitset_invertible< m, inverted > const &    bits [inline]
 

Copy constructor.

The least significant bit (at position 0) of bits and the constructed bitset are lined up. If bits is wider than the constructed bitset then excess bits are lost; if narrower then missing bits are set to inverted. That is, set to zero when bits is not inverted and set to one when bits represents an inverted bitset.

For example, when x is "0000000010001111" (16 bits), y is "10000000" (8 bits), then

 x ^= ~y;

results in x being "1111111111110000".

template<unsigned int n>
template<unsigned int m, bool i1, bool i2, typename OP>
libecc::bitset< n >::bitset Operator::bitsetExpression< m, i1, i2, OP > const &    expr [inline]
 

Construct a bitset from an expression.

See also:
bitset::operator=


Member Function Documentation

template<unsigned int n>
bool libecc::bitset< n >::any void    const
 

Return true if any bit is set.

template<unsigned int n>
const_iterator libecc::bitset< n >::begin void    const [inline]
 

Return an iterator to the first bit.

template<unsigned int n>
template<unsigned int pos>
void libecc::bitset< n >::clear void    [inline]
 

Clear a bit at a fixed position.

template<unsigned int n>
void libecc::bitset< n >::clear bitset_index const &    index [inline]
 

Clear bit at position index.

template<unsigned int n>
void libecc::bitset< n >::clear size_t    pos [inline]
 

Clear bit at position pos.

template<unsigned int n>
const_iterator libecc::bitset< n >::end void    const [inline]
 

Return an iterator one past the last bit.

template<unsigned int n>
template<unsigned int pos>
void libecc::bitset< n >::flip void    [inline]
 

Toggle a bit at a fixed position.

template<unsigned int n>
void libecc::bitset< n >::flip bitset_index const &    index [inline]
 

Toggle bit at position index.

template<unsigned int n>
void libecc::bitset< n >::flip size_t    pos [inline]
 

Toggle bit at position pos.

template<unsigned int n>
bool libecc::bitset< n >::odd void    const
 

Returns true when the bitset contains an odd number of bits.

template<unsigned int n>
template<typename Expression>
bitset< n > & libecc::bitset< n >::operator &= Expression const &    expr [inline]
 

Assignment operator with bitwise AND.

See also:
bitset::operator=

template<unsigned int n>
bitset< n > & libecc::bitset< n >::operator<<= unsigned int    shift
 

Shift bitset shift bits to the left.  Use the faster bitset::shift_op for constant distance shifts.

template<unsigned int n>
template<typename Expression>
bitset< n > & libecc::bitset< n >::operator= Expression const &    expr [inline]
 

Assignment operator.

The least significant bits (at position 0) of expr and this bitset are lined up. If expr is wider than this bitset then excess bits are lost; if narrower then missing bits are set to zero or one depending on whether the expression contains inversion bits.

For example, when x is "0000000010001111" (16 bits), y is "10000000" (8 bits) and z is "11110110" (8 bits), then

 x ^= ~y;

results in x being "1111111111110000". And

 x |= ~y ^ ~z;

results in x being "0000000001110110".

template<unsigned int n>
bitset< n > & libecc::bitset< n >::operator>>= unsigned int    shift
 

Shift bitset shift bits to the right.  Use the faster bitset::shift_op for constant distance shifts.

template<unsigned int n>
template<typename Expression>
bitset< n > & libecc::bitset< n >::operator^= Expression const &    expr [inline]
 

Assignment operator with bitwise XOR.

See also:
bitset::operator=

template<unsigned int n>
template<typename Expression>
bitset< n > & libecc::bitset< n >::operator|= Expression const &    expr [inline]
 

Assignment operator with bitwise OR.

See also:
bitset::operator=

template<unsigned int n>
const_reverse_iterator libecc::bitset< n >::rbegin void    const [inline]
 

Return a reverse iterator to bit n-1.

template<unsigned int n>
const_reverse_iterator libecc::bitset< n >::rend void    const [inline]
 

Return a reverse iterator one before the first bit.

template<unsigned int n>
bitset< n > & libecc::bitset< n >::reset void   
 

Reset all bits to 0.

template<unsigned int n>
template<unsigned int shift, class DIRECTION>
void libecc::bitset< n >::rotate bitset< n > &    result const
 

Rotate bitset.

Rotate bitset shift bits in DIRECTION.

Parameters:
shift  The number of bits to rotate this bitset.
DIRECTION  The direction into which this bitset must be rotated, can be libecc::left or libecc::right.
result  The result of the rotation.

template<unsigned int n>
template<unsigned int pos>
void libecc::bitset< n >::set void    [inline]
 

Set a bit at a fixed position.

template<unsigned int n>
void libecc::bitset< n >::set bitset_index const &    index [inline]
 

Set bit at position index.

template<unsigned int n>
void libecc::bitset< n >::set size_t    pos [inline]
 

Set bit at position pos.

template<unsigned int n>
void libecc::bitset< n >::setall void   
 

Set all bits to 1.

template<unsigned int n>
template<unsigned int shift, class DIRECTION, class OPERATION>
void libecc::bitset< n >::shift_op bitset< n > &    result const
 

Perform a shift operation followed by a bit operation.

Shift this object shift bits in DIRECTION and then perform operation OPERATION on result with it.

Parameters:
shift  the number of bits to shift this object.
DIRECTION  can be libecc::left or libecc::right.
OPERATION  can be either libecc::assign or libecc::exor.
result  The bitset that is used to XOR with, or to assign to.

template<unsigned int n>
template<unsigned int pos>
bool libecc::bitset< n >::test void    const [inline]
 

Test a bit at a fixed position.

template<unsigned int n>
bool libecc::bitset< n >::test bitset_index const &    index const [inline]
 

Test a bit at position index.

template<unsigned int n>
bool libecc::bitset< n >::test size_t    pos const [inline]
 

Test bit at position pos.

template<unsigned int n>
template<unsigned int m>
libecc::bitset< n >::xor_with_zero_padded bitset< m > const &    bitset,
int    lsb,
int    msb,
int    shift
 

Shift bitset left or right and XOR with this bitset.

Parameters:
bitset  The input bitset.
lsb  The Least Significant set bit of bitset.
msb  The Most Significant set bit in bitset.
shift  The distance to shift to the left, may be negative in which case bitset is shifted right.
Bit lsb up till and including bit msb of bitset are shifted left over a distance shift (or shifted right if shift is negative) and then bitwise exclusive-OR-ed with this bitset. No range checking for this bitset is being done; it is the responsibility of the caller to make sure that it will fit. Moreover, it is assumed that all bits in the same digit but left of msb and and right of lsb are zero and that that there is at least one fully zeroed digit left and right of the bitset.

Copyright © 2002 Carlo Wood.  All rights reserved.