1 #ifndef __OPTIONS_H__
2 #define __OPTIONS_H__
3 
4 /*
5  * Options.h (c) Noah Roberts
6  *
7  * The Options class is in change of tracking all definable states within the game.
8  * Such states include things such as interface settings, computer color, time limits,
9  * max ply, and any other thing we wish to provide settings for.  This class will be
10  * passed command line options at the start of the program and will be in charge of
11  * parsing those options into settings.  Some commands will alter the settings this
12  * class is in charge of, those commands will be passed to this class for processing.
13  */
14 #include	<map>
15 #include	<list>
16 #include	<string>
17 #include	<iostream>
18 
19 // Observer pattern superclass
20 class OptionsObserver
21 {
22  public:
optionChanged(std::string which)23   virtual void optionChanged(std::string which)
24     { std::cerr << "optionChanged() is a subclass responsibility!!\n"; }
25 };
26 
27 class Options
28 {
29  private:
30   typedef std::map<std::string, std::string>	OptionMap;
31   typedef OptionMap::value_type			OptionPair;
32 
33   OptionMap	_options;
34 
35   void loadDefaults();
36 
37   static Options	_defaultOptions;
38   Options();
39 
40   std::list<OptionsObserver*>	observers;
41   void dispatchChangeNotice(std::string whatChanged);
42   void setOption(std::string optionText);
43  public:
defaultOptions()44   static Options *defaultOptions() { return &_defaultOptions; }
45   void decipherCommandArgs(int argc, char **argv);
46   std::string getValue(std::string option);
47   void setValue(std::string option, std::string value);
48   bool isOption(std::string commandText); // if it is an option returns true, also deals with
49   // it.
50 
51   // Observer pattern
52   void addObserver(OptionsObserver *observer);
53 };
54 
55 #endif
56