Click on the banner to return to the Class Reference home page.

©Copyright 1996 Rogue Wave Software

RWGBitVec(size)

Synopsis

#include <rw/gbitvec.h>
declare(RWGBitVec,size)
RWGBitVec(size) a;

Description

RWGBitVec(size) is a bit vector of fixed length size. The length cannot be changed dynamically (see class RWBitVec if you need a bit vector whose length can be changed at run time). Objects of type RWGBitVec(size) are declared with macros defined in the standard C++ header file <generic.h>.

Bits are numbered from 0 through size-1, inclusive.

Persistence

None

Example

In this example, a bit vector 24 bits long is declared and exercised:

#include "rw/gbitvec.h"
#include <iostream.h>

const int VECSIZE = 8;

declare(RWGBitVec, VECSIZE)   // declare a 24 bit long vector
implement(RWGBitVec, VECSIZE) // implement the vector

main()
{ 
  RWGBitVec(VECSIZE) a, b;   // Allocate two vectors.

  a(2) = TRUE;               // Set bit 2 (the third bit) of a on.
  b(3) = TRUE;               // Set bit 3 (the fourth bit) of b on.

  RWGBitVec(VECSIZE) c = a ^ b;  // Set c to the XOR of a and b.

  cout << "Vector 1" << "\t" << "Vector 2" << "\t"
       << "Vector 1 xor Vector 2" << endl;

  for(int i = 0; i < VECSIZE; i++)
    cout << a[i] << "\t\t" << b[i] << "\t\t" << c[i] << endl;

  return 0;
}

Public Constructors

RWGBitVec(size)();
RWGBitVec(size)(RWBoolean f);

Assignment Operators

RWGBitVec(sz)&
operator=(const RWGBitVec(sz)& v);
RWGBitVec(sz)&
operator=(RWBoolean f);
RWGBitVec(sz)&
operator&=(const RWGBitVec(sz)& v);
RWGBitVec(sz)&
operator^=(const RWGBitVec(sz)& v);
RWGBitVec(sz)&
operator|=(const RWGBitVec(sz)& v);

Indexing Operators

RWBitRef
operator[](size_t i);
RWBitRef
operator()(size_t i);

Public Member Functions

void
clearBit(size_t i);
const RWByte*
data() const;
void
setBit(size_t i);
RWBoolean
testBit(size_t i) const;

Related Global Functions

RWGBitVec(sz) 
operator&(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2);
RWGBitVec(sz) 
operator^(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2);
RWGBitVec(sz) 
operator|(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2);
RWBoolean 
operator==(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2) 
           const;
RWBoolean 
operator!=(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2) 
           const;