/****************************************************************************
* gbitarray.h :
* header file for bit array.
*
* Change Log :
* Oct 28, 1998 Initial version, Liujian Qian
*
* $Id: gbitarray.h,v 1.1 1998/10/29 05:06:30 qian Exp $
***************************************************************************/
#ifndef _BITARRAY_H_
#define _BITARRAY_H_
#include <gcxx.h>
/**
* GBitArray provides an array of bits.
* The main methods are bit setting/clearing/testing.
* operator[] is only defined for read-only access, for simplicity.
*/
class GBitArray
{
unsigned char *data;
int n_bytes; //in bytes
int n_bits; //requested by client
public:
GBitArray ();
GBitArray (int size);
GBitArray (const GBitArray&);
~GBitArray ();
int size () const;
/**
* reset the size to new_size bits. If new_size is smaller
* than the current one, the memory is usually not shrinked.
* Only the size information is updated.
*/
void resize (int new_size);
/**
* fill the first 'size' bits with value 'v'. If size<0
* fill every bits in the array. If size > current size
* then only the current_size bits will be filled; the
* array will not be automatically resized to accomodate
* the bigger size.
*/
void fill (bool v, int size=-1);
/**
* test wether bit at idx is true. Return true if
* bit is true; otherwise return false.
*/
bool test (int idx) const;
/**
* set bit at idx to 1.
*/
void set (int idx);
/**
* clear bit at idx to 0.
*/
void clear (int idx);
/**
* toggle the bit. return the NEW bit value.
*/
bool toggle (int idx);
/**
* toggle every bit in the array.
*/
void toggleAll();
bool operator[] (int idx) const;
GBitArray &operator= ( const GBitArray & );
GBitArray &operator&=( const GBitArray & );
GBitArray &operator|=( const GBitArray & );
GBitArray &operator^=( const GBitArray & );
GBitArray operator~( ) const;
friend GBitArray operator&( const GBitArray &, const GBitArray & );
friend GBitArray operator|( const GBitArray &, const GBitArray & );
friend GBitArray operator^( const GBitArray &, const GBitArray & );
friend ostream& operator<<(ostream& os, const GBitArray& a);
};
#endif
Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999