controlw.h

Go to the documentation of this file.
00001 //$$ controlw.h                Control word class
00002 
00003 #ifndef CONTROL_WORD_LIB
00004 #define CONTROL_WORD_LIB 0
00005 
00006 // for organising an int as a series of bits which indicate whether an
00007 // option is on or off.
00008 
00009 class ControlWord
00010 {
00011 protected:
00012    int cw;                                      // the control word
00013 public:
00014    ControlWord() : cw(0) {}                     // do nothing
00015    ControlWord(int i) : cw(i) {}                // load an integer
00016 
00017       // select specific bits (for testing at least one set)
00018    ControlWord operator*(ControlWord i) const
00019       { return ControlWord(cw & i.cw); }
00020    void operator*=(ControlWord i)  { cw &= i.cw; }
00021 
00022       // set bits
00023    ControlWord operator+(ControlWord i) const
00024       { return ControlWord(cw | i.cw); }
00025    void operator+=(ControlWord i)  { cw |= i.cw; }
00026 
00027       // reset bits
00028    ControlWord operator-(ControlWord i) const
00029       { return ControlWord(cw - (cw & i.cw)); }
00030    void operator-=(ControlWord i) { cw -= (cw & i.cw); }
00031 
00032       // check if all of selected bits set or reset
00033    bool operator>=(ControlWord i) const { return (cw & i.cw) == i.cw; }
00034    bool operator<=(ControlWord i) const { return (cw & i.cw) == cw; }
00035 
00036       // flip selected bits
00037    ControlWord operator^(ControlWord i) const
00038       { return ControlWord(cw ^ i.cw); }
00039    ControlWord operator~() const { return ControlWord(~cw); }
00040 
00041       // convert to integer
00042    int operator+() const { return cw; }
00043    int operator!() const { return cw==0; }
00044    FREE_CHECK(ControlWord)
00045 };
00046 
00047 
00048 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1