home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MAGAZINE / MISC / PCTV2N6.ZIP / BITVECT.ZIP / BITVECT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-14  |  1.3 KB  |  40 lines

  1. // Listing 1: bitvect.h
  2. // Header file for the bit vector class.
  3. // Copyright (C) 1991 by Nicholas Wilt.  All rights reserved.
  4.  
  5. class BitVect {
  6.   unsigned char *vect;        // Vector that contains the bits
  7.   int numbytes;         // Number of bytes in vect
  8.   long numbits;         // Number of bits in vector
  9.  
  10. public:
  11.   // Copy constructor.
  12.   BitVect(const BitVect&);
  13.  
  14.   // Constructor takes the number of elements in the bit vector.
  15.   BitVect(long n);
  16.  
  17.   // Constructor takes the number of elements in the bit vector
  18.   // and the initial value to give all the bits.
  19.   BitVect(long n, int val);
  20.  
  21.   ~BitVect();
  22.  
  23.   // Functions to extract bits out of the vector.
  24.   int operator[] (long);    // Subscripts into the bit vector
  25.   int GetBit(long);        // Same as overloaded [].
  26.  
  27.   // Sets bit to 1 or 0 (1 if val is nonzero, 0 otherwise).
  28.   void SetBit(long inx, int val);
  29.   void SetRange(long min, long max, int val);
  30.  
  31.   // Boolean operations on bit vectors using overloaded operators.
  32.   BitVect operator~ ();
  33.   BitVect& operator|= (BitVect& x);
  34.   BitVect& operator&= (BitVect& x);
  35.   BitVect& operator-= (BitVect& x);
  36.   friend BitVect operator| (BitVect& x, BitVect& y);
  37.   friend BitVect operator& (BitVect& x, BitVect& y);
  38.   friend BitVect operator- (BitVect& x, BitVect& y);
  39. };
  40.