home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / n / newmat06.zip / CONTROLW.H < prev    next >
C/C++ Source or Header  |  1992-06-07  |  2KB  |  46 lines

  1. //$$ controlw.h                Control word class
  2.  
  3. #ifndef CONTROL_WORD_LIB
  4. #define CONTROL_WORD_LIB 0
  5.  
  6. // for organising an int as a series of bits which indicate whether an
  7. // option is on or off.
  8.  
  9. class ControlWord
  10. {
  11. protected:
  12.    int cw;                                      // the control word
  13. public:
  14.    ControlWord() : cw(0) {}                     // do nothing
  15.    ControlWord(int i) : cw(i) {}                // load an integer
  16.  
  17.       // select specific bits (for testing at least one set)
  18.    ControlWord operator*(const ControlWord& i) const { return cw & i.cw; }
  19.    void operator*=(const ControlWord& i)  { cw &= i.cw; }
  20.  
  21.       // set bits
  22.    ControlWord operator+(const ControlWord& i) const { return cw | i.cw; }
  23.    void operator+=(const ControlWord& i)  { cw |= i.cw; }
  24.  
  25.       // reset bits
  26.    ControlWord operator-(const ControlWord& i) const
  27.       { return cw - (cw & i.cw); }
  28.    void operator-=(const ControlWord& i) { cw -= (cw & i.cw); }
  29.  
  30.       // check if all of selected bits set or reset
  31.    Boolean operator>=(const ControlWord& i) const { return (cw & i.cw) == i.cw; }
  32.    Boolean operator<=(const ControlWord& i) const { return (cw & i.cw) == cw; }
  33.  
  34.       // flip selected bits
  35.    ControlWord operator^(const ControlWord& i) const { return cw ^ i.cw; }
  36.    ControlWord operator~() const { return ~cw; }
  37.  
  38.       // convert to integer
  39.    int operator+() const { return cw; }
  40.    int operator!() const { return cw==0; }
  41.    FREE_CHECK(ControlWord)
  42. };
  43.  
  44.  
  45. #endif
  46.