Main Page   Namespace List   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

RazorBack::Bits_ Class Reference

Bits_ : A bit-array class. More...

#include <Bits.hh>

List of all members.

Public Methods

 Bits_ (unsigned int N=0, bool Val=false)
 Inits to hold N bits (default 0). More...

 Bits_ (const Bits_ &Bits)
 copy constructor.

 Bits_ (const char *Str)
 Inits by a string Str which should have the format "110101001", 0 for "false", 1 for "true", 1st char is MSB, last is LSB. More...

 ~Bits_ ()
 destructor.

Bits_& operator= (const Bits_ &Rhs)
 assignment.

bool operator== (const Bits_ &Other) const
 Two Bits_ arrays are equal if they have the same number of bits and all bits are set in the same way.

bool operator!= (const Bits_ &Other) const
 Non-equality.

unsigned int cno () const
 The number of uints used in storing the bit array.

bool get_bit (unsigned int Idx) const
 get_bit(): returns the Boolean value of the Idx-th bit. More...

bool set_bit (unsigned int Idx, bool Value=true)
 set_bit(): sets the Idx-th bit to Value (default is true). More...

void set_values (bool Value=true)
 set_values(): sets all bits to Value (default is true).

unsigned int len () const
 Returns the number of bits in the array.

unsigned int len (unsigned int Len)
 len(Len): adjusts the size of the bit array to Len. More...

unsigned int on_no () const
 Returns the number of bits that are set to true.

unsigned int off_no () const
 Returns the number of bits that are set to false.

Bits_& operator~ ()
 The following overlaid operators (~,&,|,^) perform exactly the same bitwise operations as their standard counterparts. More...

Bits_& operator &= (const Bits_ &Bits)
Bits_& operator|= (const Bits_ &Bits)
Bits_& operator^= (const Bits_ &Bits)
Bits_ operator & (const Bits_ &Bits) const
Bits_ operator| (const Bits_ &Bits) const
Bits_ operator^ (const Bits_ &Bits) const
Bits_& operator<<= (unsigned int Shift)
 The following operators (<<,<<=,>>,>>=) do exactly the same things as their original C counterparts. More...

Bits_& operator>>= (unsigned int Shift)
Bits_ operator<< (unsigned int Shift) const
Bits_ operator>> (unsigned int Shift) const

Protected Methods

unsigned int zero_mask () const

Static Protected Methods

unsigned int uints_needed (unsigned int Bitno)
 hidden methods.

unsigned int get_mask (unsigned int Idx, unsigned int &Offs)
unsigned int* alloc_arr (unsigned int Size, const unsigned int *Arr=NULL)

Private Methods

unsigned int read_dataline (istream &In, char *Buffer)

Private Attributes

unsigned int* B
 the bit array.

size_t Cs
size_t Bs
 no. of uints and bits.


Static Private Attributes

const size_t BITS_PER_CHAR
 bits per char.

const size_t BITS_PER_UINT
 bits per unsigned int.


Friends

istream& operator>> (istream &In, Bits_ &Bits)
 Read a bit array from stream In. More...

ostream& operator<< (ostream &Out, const Bits_ &Bits)
 Writes a bit array to stream Out.


Detailed Description

Bits_ : A bit-array class.

Bits are stored in an array of unsigned ints. Individual bits can be set and tested and global bitwise Boolean operations can be performed.

Definition at line 42 of file Bits.hh.


Constructor & Destructor Documentation

RazorBack::Bits_::Bits_ ( unsigned int N = 0,
bool Val = false ) [explicit]
 

Inits to hold N bits (default 0).

Set all bits to Val (false by default).

RazorBack::Bits_::Bits_ ( const Bits_ & Bits )
 

copy constructor.

RazorBack::Bits_::Bits_ ( const char * Str ) [explicit]
 

Inits by a string Str which should have the format "110101001", 0 for "false", 1 for "true", 1st char is MSB, last is LSB.

Any char other than '0' or '1' will elicit a warning and will be interpreted as "true". if Str==NULL or if it is the empty string "" then an empty object will be created.

RazorBack::Bits_::~Bits_ ( ) [inline]
 

destructor.

Definition at line 75 of file Bits.hh.


Member Function Documentation

Bits_ & RazorBack::Bits_::operator= ( const Bits_ & Rhs )
 

assignment.

bool RazorBack::Bits_::operator== ( const Bits_ & Other ) const
 

Two Bits_ arrays are equal if they have the same number of bits and all bits are set in the same way.

bool RazorBack::Bits_::operator!= ( const Bits_ & Other ) const
 

Non-equality.

unsigned int RazorBack::Bits_::cno ( ) const [inline]
 

The number of uints used in storing the bit array.

Definition at line 90 of file Bits.hh.

bool RazorBack::Bits_::get_bit ( unsigned int Idx ) const
 

get_bit(): returns the Boolean value of the Idx-th bit.

Throws Indexrangexc_ if Idx is out of range. Throws Emptyexc_ if the calling object is empty.

bool RazorBack::Bits_::set_bit ( unsigned int Idx,
bool Value = true )
 

set_bit(): sets the Idx-th bit to Value (default is true).

Returns old value. Throws Indexrangexc_ if Idx is out of range. Throws Emptyexc_ if the calling object is empty.

void RazorBack::Bits_::set_values ( bool Value = true )
 

set_values(): sets all bits to Value (default is true).

unsigned int RazorBack::Bits_::len ( ) const [inline]
 

Returns the number of bits in the array.

Definition at line 111 of file Bits.hh.

unsigned int RazorBack::Bits_::len ( unsigned int Len )
 

len(Len): adjusts the size of the bit array to Len.

If Len==Bs, no action is taken, if Len<Bs then the tail of the array is lost, if Len>Bs then the tail of the new array will be filled with false values (0). Returns the old length.

unsigned int RazorBack::Bits_::on_no ( ) const
 

Returns the number of bits that are set to true.

unsigned int RazorBack::Bits_::off_no ( ) const
 

Returns the number of bits that are set to false.

Bits_ & RazorBack::Bits_::operator~ ( )
 

The following overlaid operators (~,&,|,^) perform exactly the same bitwise operations as their standard counterparts.

The bit array sizes must be the same otherwise a Dimexc_ exception is thrown.

Bits_& RazorBack::Bits_::operator &= ( const Bits_ & Bits )
 

Bits_& RazorBack::Bits_::operator|= ( const Bits_ & Bits )
 

Bits_& RazorBack::Bits_::operator^= ( const Bits_ & Bits )
 

Bits_ RazorBack::Bits_::operator & ( const Bits_ & Bits ) const
 

Bits_ RazorBack::Bits_::operator| ( const Bits_ & Bits ) const
 

Bits_ RazorBack::Bits_::operator^ ( const Bits_ & Bits ) const
 

Bits_ & RazorBack::Bits_::operator<<= ( unsigned int Shift )
 

The following operators (<<,<<=,>>,>>=) do exactly the same things as their original C counterparts.

For << and <<=, 0 bits are shifted in at the right; for >> and >>=, 0 bits are shifted in from the left. Empty bit-vectors will be filled up with Shift 0-s.

Bits_& RazorBack::Bits_::operator>>= ( unsigned int Shift )
 

Bits_ RazorBack::Bits_::operator<< ( unsigned int Shift ) const
 

Bits_ RazorBack::Bits_::operator>> ( unsigned int Shift ) const
 

unsigned int RazorBack::Bits_::uints_needed ( unsigned int Bitno ) [static, protected]
 

hidden methods.

unsigned int RazorBack::Bits_::get_mask ( unsigned int Idx,
unsigned int & Offs ) [static, protected]
 

unsigned int* RazorBack::Bits_::alloc_arr ( unsigned int Size,
const unsigned int * Arr = NULL ) [static, protected]
 

unsigned int RazorBack::Bits_::zero_mask ( ) const [protected]
 

unsigned int RazorBack::Bits_::read_dataline ( istream & In,
char * Buffer ) [private]
 


Friends And Related Function Documentation

istream & operator>> ( istream & In,
Bits_ & Bits ) [friend]
 

Read a bit array from stream In.

The ASCII format of a Bits_ object is:-

      ------------------------------------
                           00000 00100110 [76..64]
      00000000 00000000 00000000 00000000 [63..32]
      00000011 11111111 11111111 11111111 [31..0]
      ====================================
      

ostream & operator<< ( ostream & Out,
const Bits_ & Bits ) [friend]
 

Writes a bit array to stream Out.


Member Data Documentation

const size_t RazorBack::Bits_::BITS_PER_CHAR [static, private]
 

bits per char.

Definition at line 47 of file Bits.hh.

const size_t RazorBack::Bits_::BITS_PER_UINT [static, private]
 

bits per unsigned int.

Definition at line 48 of file Bits.hh.

unsigned int * RazorBack::Bits_::B [private]
 

the bit array.

Definition at line 50 of file Bits.hh.

size_t RazorBack::Bits_::Cs [private]
 

Definition at line 51 of file Bits.hh.

size_t RazorBack::Bits_::Bs [private]
 

no. of uints and bits.

Definition at line 51 of file Bits.hh.


The documentation for this class was generated from the following file:
Generated at Wed Aug 21 09:33:41 2002 for The Razorback C++ Library: Miscellaneous by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001