| | | | | |

Defining Class BitVector - 5: Review

namespace fsu
{
  class BitVector
  {
  public:
    void Set   (size_t index);        // make index bit = 1
    void Set   ();                    // make all bits = 1
    void Unset (size_t index);        // make index bit = 0
    void Unset ();                    // make all bits = 0
    void Flip  (size_t index);        // flip index bit (change value of bit)
    void Flip  ();                    // flip all bits 
    bool Test  (size_t index) const;  // return index bit value

             BitVector  ();           // construct a default BitVector
    explicit BitVector  (size_t);     // construct a BitVector with specified size
             BitVector  (const BitVector&); // copy constructor      
             ~BitVector ();           // destructor
    BitVector& operator = (const BitVector& a);  // assignment operator

    size_t Size () const;             // return size of bitvector in bits
    void   Expand (size_t newsize);   // increase number of bits, retaining current values
    void   Dump   (std::ostream& os) const; // developer's assistant
   
    bool   operator[] (size_t i) const { return Test(i); }

  private:
    // data
    uint8_t *  byteArray_;
    size_t     byteArraySize_;

    // methods
    size_t           ByteNumber (size_t indx) const;
    static uint8_t   Mask       (size_t indx) const;
  };
} // namespace fsu

| | Top of Page | 7. A BitVector Class - 8 of 14