source: git/factory/cf_switches.h @ 1ba7d5

spielwiese
Last change on this file since 1ba7d5 was 1ba7d5, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Turn CFSwitches::getInstance() into a static inline method
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifndef INCL_CF_SWITCHES_H
4#define INCL_CF_SWITCHES_H
5
6//{{{ docu
7//
8// cf_switches.h - header to cf_switches.cc.
9//
10//}}}
11
12// #include "config.h"
13
14//{{{ const int CFSwitchesMax
15//{{{ docu
16//
17// const CFSwitchesMax - maximum number of switches.
18//
19//}}}
20const int CFSwitchesMax = 13;
21//}}}
22
23//{{{ class CFSwitches
24//{{{ docu
25//
26// class CFSwitches - manages boolean switches.
27//
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.
33//
34// Note: No range checking is done when accessing switches.
35//
36// switches: the switches
37//
38//}}}
39//{{{ inline method docu
40//
41// void On ( int s )
42// void Off ( int s )
43// bool isOn ( int s ) const
44// bool isOff ( int s ) const
45//
46// On(), Off() - switch `s' on or off, resp.
47//
48// isOn(), isOff() - return true iff `s' is on or off, resp.
49//
50//}}}
51class CFSwitches
52{
53private:
54    bool switches [CFSwitchesMax];
55
56    CFSwitches ();
57public:
58    // constructors, destructors
59    ~CFSwitches () {}
60
61    static inline CFSwitches& getInstance() 
62    {
63       static CFSwitches singleton;
64       return singleton;
65    }
66    // selectors
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]; }
71};
72//}}}
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//}}}
87
88#endif /* ! INCL_CF_SWITCHES_H */
Note: See TracBrowser for help on using the repository browser.