[493c477] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[2dd068] | 2 | |
---|
| 3 | #ifndef INCL_CF_SWITCHES_H |
---|
| 4 | #define INCL_CF_SWITCHES_H |
---|
| 5 | |
---|
[e743b3] | 6 | //{{{ docu |
---|
| 7 | // |
---|
| 8 | // cf_switches.h - header to cf_switches.cc. |
---|
| 9 | // |
---|
| 10 | //}}} |
---|
| 11 | |
---|
[e4fe2b] | 12 | // #include "config.h" |
---|
[b973c0] | 13 | |
---|
[e743b3] | 14 | //{{{ const int CFSwitchesMax |
---|
| 15 | //{{{ docu |
---|
| 16 | // |
---|
| 17 | // const CFSwitchesMax - maximum number of switches. |
---|
| 18 | // |
---|
| 19 | //}}} |
---|
[e16f7d] | 20 | const int CFSwitchesMax = 13; |
---|
[e743b3] | 21 | //}}} |
---|
[2dd068] | 22 | |
---|
[e743b3] | 23 | //{{{ class CFSwitches |
---|
| 24 | //{{{ docu |
---|
| 25 | // |
---|
| 26 | // class CFSwitches - manages boolean switches. |
---|
| 27 | // |
---|
[a2952c] | 28 | // An object of class `CFSwitches' is simply an array of booleans |
---|
| 29 | // with some comfortable access methods (`On()', `isOn()', etc.). |
---|
| 30 | // Each object may contain `CFSwitchesMax' switches. When a new |
---|
| 31 | // object of type `CFSwitches' is created, all its switches are |
---|
| 32 | // turned off. |
---|
[e743b3] | 33 | // |
---|
| 34 | // Note: No range checking is done when accessing switches. |
---|
| 35 | // |
---|
| 36 | // switches: the switches |
---|
| 37 | // |
---|
| 38 | //}}} |
---|
| 39 | //{{{ inline method docu |
---|
| 40 | // |
---|
[5586f4] | 41 | // void On ( int s ) |
---|
| 42 | // void Off ( int s ) |
---|
[f6590b9] | 43 | // bool isOn ( int s ) const |
---|
| 44 | // bool isOff ( int s ) const |
---|
[e743b3] | 45 | // |
---|
[a2952c] | 46 | // On(), Off() - switch `s' on or off, resp. |
---|
[e743b3] | 47 | // |
---|
[a2952c] | 48 | // isOn(), isOff() - return true iff `s' is on or off, resp. |
---|
[e743b3] | 49 | // |
---|
| 50 | //}}} |
---|
[2dd068] | 51 | class CFSwitches |
---|
| 52 | { |
---|
| 53 | private: |
---|
[e743b3] | 54 | bool switches [CFSwitchesMax]; |
---|
[a2952c] | 55 | |
---|
[64b9bf] | 56 | CFSwitches (); |
---|
[2dd068] | 57 | public: |
---|
[a2952c] | 58 | // constructors, destructors |
---|
[5586f4] | 59 | ~CFSwitches () {} |
---|
[e743b3] | 60 | |
---|
[1ba7d5] | 61 | static inline CFSwitches& getInstance() |
---|
[64b9bf] | 62 | { |
---|
| 63 | static CFSwitches singleton; |
---|
| 64 | return singleton; |
---|
| 65 | } |
---|
[a2952c] | 66 | // selectors |
---|
[5586f4] | 67 | void On ( int s ) { switches[s] = true; } |
---|
| 68 | void Off ( int s ) { switches[s] = false; } |
---|
| 69 | bool isOn ( int s ) const { return switches[s]; } |
---|
| 70 | bool isOff ( int s ) const { return ! switches[s]; } |
---|
[2dd068] | 71 | }; |
---|
[e743b3] | 72 | //}}} |
---|
[64b9bf] | 73 | //{{{ CFSwitches cf_glob_switches; |
---|
| 74 | //{{{ docu |
---|
| 75 | // |
---|
| 76 | // cf_glob_switches - factory switches. |
---|
| 77 | // |
---|
| 78 | // This is the only object of type CFSwitches in factory. It is |
---|
| 79 | // used either directly in the low level algorithms or by the |
---|
| 80 | // functions On(), Off(), isOn() defined in canonicalform.cc. |
---|
| 81 | // |
---|
| 82 | //}}} |
---|
| 83 | // extern CFSwitches& cf_glob_switches; |
---|
| 84 | // CFSwitches& cf_glob_switches = CFSwitches::getInstance(); |
---|
| 85 | #define cf_glob_switches (CFSwitches::getInstance()) |
---|
| 86 | //}}} |
---|
[2dd068] | 87 | |
---|
[493c477] | 88 | #endif /* ! INCL_CF_SWITCHES_H */ |
---|