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 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 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::expression< 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.

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.

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.

template<unsigned int pos> void digitset (unsigned int d, bool value)
 Set or reset a bit in digit d.

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.


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.


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 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::expression< 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>
template<unsigned int pos>
void libecc::bitset< n >::clear void   
 

Clear a bit at a fixed position.

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

Clear bit at position pos.

template<unsigned int n>
template<unsigned int pos>
void libecc::bitset< n >::digitset unsigned int    d,
bool    value
 

Set or reset a bit in digit d.

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

Toggle a bit at a fixed position.

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

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>
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>
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>
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   
 

Set a bit at a fixed position.

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

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
 

Test a bit at a fixed position.

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

Test bit at position pos.

Copyright © 2002 Carlo Wood.  All rights reserved.