RWGBitVec(3C++)
RWGBitVec(size) - Rogue Wave library class
As shipped in IRIX 6.5.7. Unchanged since IRIX 6.5.
Name RWGBitVec(size) - Rogue Wave library class 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" << "" << "Vector 2" << "" << "Vector 1 xor Vector 2" << endl; for(int i = 0; i < VECSIZE; i++) cout << a[i] << "" << b[i] << "" << c[i] << endl; return 0; } Public Constructors RWGBitVec(size)(); Construct a bit vector size elements long, with all bits initialized to FALSE. RWGBitVec(size)(RWBoolean f); Construct a bit vector size elements long, with all bits initialized to f. Assignment Operators RWGBitVec(sz)& operator=(const RWGBitVec(sz)& v); Set each element of self to the corresponding bit value of v. Return a reference to self. RWGBitVec(sz)& operator=(RWBoolean f); Set all elements of self to the boolean value f. RWGBitVec(sz)& operator&=(const RWGBitVec(sz)& v); RWGBitVec(sz)& operator^=(const RWGBitVec(sz)& v); RWGBitVec(sz)& operator|=(const RWGBitVec(sz)& v); Logical assignments. Set each element of self to the logical AND, XOR, or OR, respectively, of self and the corresponding bit in v. Indexing Operators RWBitRef operator[](size_t i); Returns a reference to the ith bit of self. This reference can be used as an lvalue. The index i must be between 0 and size-1, inclusive. Bounds checking will occur. RWBitRef operator()(size_t i); Returns a reference to the ith bit of self. This reference can be used as an lvalue. The index i must be between 0 and size-1, inclusive. No bounds checking is done. Public Member Functions void clearBit(size_t i); Clears (i.e., sets to FALSE) the bit with index i. The index i must be between 0 and size-1. No bounds checking is performed. The following are equivalent, although clearBit(size_t) is slightly smaller and faster than using operator()(size_t): a(i) = FALSE; a.clearBit(i); const RWByte* data() const; Returns a const pointer to the raw data of self. Should be used with care. void setBit(size_t i); Sets (i.e., sets to TRUE) the bit with index i. The index i must be between 0 and size-1. No bounds checking is performed. The following are equivalent, although setBit(size_t) is slightly smaller and faster than using operator()(size_t): a(i) = TRUE; a.setBit(i); RWBoolean testBit(size_t i) const; Tests the bit with index i. The index i must be between 0 and size-1. No bounds checking is performed. The following are equivalent, although testBit(size_t) is slightly smaller and faster than using operator()(size_t): if( a(i) ) doSomething(); if( a.testBit(i) ) doSomething(); 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); Return the logical AND, XOR, and OR, respectively, of vectors v1 and v2. RWBoolean operator==(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2) const; Returns TRUE if each bit of v1 is set to the same value as the corresponding bit in v2. Otherwise, returns FALSE. RWBoolean operator!=(const RWGBitVec(sz)& v1, const RWGBitVec(sz)& v2) const; Returns FALSE if each bit of v1 is set to the same value as the corresponding bit in v2. Otherwise, returns TRUE.