Last change
on this file since 10389 was 9434, checked in by stuerze, 4 years ago |
newmat is reverted to its stable version 10 because version 11beta was not working with mac compilers
|
File size:
1.5 KB
|
Rev | Line | |
---|
[9434] | 1 | /// \ingroup newmat
|
---|
| 2 | ///@{
|
---|
| 3 |
|
---|
| 4 | /// \file controlw.h
|
---|
| 5 | /// Control word class.
|
---|
| 6 | /// Manipulate bits used for setting options.
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | #ifndef CONTROL_WORD_LIB
|
---|
| 10 | #define CONTROL_WORD_LIB 0
|
---|
| 11 |
|
---|
| 12 | /// Organise an int as a series of bits to set options.
|
---|
| 13 | /// \internal
|
---|
| 14 | class ControlWord
|
---|
| 15 | {
|
---|
| 16 | protected:
|
---|
| 17 | int cw; // the control word
|
---|
| 18 | public:
|
---|
| 19 | ControlWord() : cw(0) {} // do nothing
|
---|
| 20 | ControlWord(int i) : cw(i) {} // load an integer
|
---|
| 21 |
|
---|
| 22 | // select specific bits (for testing at least one set)
|
---|
| 23 | ControlWord operator*(ControlWord i) const
|
---|
| 24 | { return ControlWord(cw & i.cw); }
|
---|
| 25 | void operator*=(ControlWord i) { cw &= i.cw; }
|
---|
| 26 |
|
---|
| 27 | // set bits
|
---|
| 28 | ControlWord operator+(ControlWord i) const
|
---|
| 29 | { return ControlWord(cw | i.cw); }
|
---|
| 30 | void operator+=(ControlWord i) { cw |= i.cw; }
|
---|
| 31 |
|
---|
| 32 | // reset bits
|
---|
| 33 | ControlWord operator-(ControlWord i) const
|
---|
| 34 | { return ControlWord(cw - (cw & i.cw)); }
|
---|
| 35 | void operator-=(ControlWord i) { cw -= (cw & i.cw); }
|
---|
| 36 |
|
---|
| 37 | // check if all of selected bits set or reset
|
---|
| 38 | bool operator>=(ControlWord i) const { return (cw & i.cw) == i.cw; }
|
---|
| 39 | bool operator<=(ControlWord i) const { return (cw & i.cw) == cw; }
|
---|
| 40 |
|
---|
| 41 | // flip selected bits
|
---|
| 42 | ControlWord operator^(ControlWord i) const
|
---|
| 43 | { return ControlWord(cw ^ i.cw); }
|
---|
| 44 | ControlWord operator~() const { return ControlWord(~cw); }
|
---|
| 45 |
|
---|
| 46 | // convert to integer
|
---|
| 47 | int operator+() const { return cw; }
|
---|
| 48 | int operator!() const { return cw==0; }
|
---|
| 49 | FREE_CHECK(ControlWord)
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
| 55 | ///@}
|
---|
| 56 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.