]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
Reset, fix Nasal timers added on shutdown.
[flightgear.git] / src / Main / options.hxx
1 // options.hxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _OPTIONS_HXX
25 #define _OPTIONS_HXX
26
27 #include <memory>
28 #include <string>
29
30 #include <simgear/misc/strutils.hxx>
31
32 // forward decls
33 class SGPath;
34
35 namespace flightgear
36 {
37
38 /// option processing can have various result values
39 /// depending on what the user requested. Note processOptions only
40 /// returns a subset of these.
41 enum OptionResult
42 {
43     FG_OPTIONS_OK = 0,
44     FG_OPTIONS_HELP = 1,
45     FG_OPTIONS_ERROR = 2,
46     FG_OPTIONS_EXIT = 3,
47     FG_OPTIONS_VERBOSE_HELP = 4,
48     FG_OPTIONS_SHOW_AIRCRAFT = 5,
49     FG_OPTIONS_SHOW_SOUND_DEVICES = 6,
50     FG_OPTIONS_NO_DEFAULT_CONFIG = 7
51 };
52     
53 class Options
54 {
55 private:
56   Options();
57   
58 public:
59   static Options* sharedInstance();
60
61   ~Options();
62   
63   /**
64    * pass command line arguments, read default config files
65    */
66   void init(int argc, char* argv[], const SGPath& appDataPath);
67   
68   /**
69     * parse a config file (eg, .fgfsrc) 
70     */
71   void readConfig(const SGPath& path);
72   
73   /**
74     * read the value for an option, if it has been set
75     */
76   std::string valueForOption(const std::string& key, const std::string& defValue = std::string()) const;
77   
78   /**
79     * return all values for a multi-valued option
80     */
81   string_list valuesForOption(const std::string& key) const;
82   
83   /**
84     * check if a particular option has been set (so far)
85     */
86   bool isOptionSet(const std::string& key) const;
87   
88   
89   /**
90     * set an option value, assuming it is not already set (or multiple values
91     * are permitted)
92     * This can be used to inject option values, eg based upon environment variables
93     */
94   int addOption(const std::string& key, const std::string& value);
95   
96   /**
97    * apply option values to the simulation state
98    * (set properties, etc). 
99    */
100   OptionResult processOptions();
101   
102   /**
103    * init the aircraft options
104    */
105   void initAircraft();
106   
107   /**
108    * should defualt configuration files be loaded and processed or not?
109    * There's many configuration files we have historically read by default
110    * on startup - preferences.xml, fgfs.rc in various places and so on.
111    * --no-default-config allows this behaviour to be changed, so only
112    * expicitly listed files are read - this is useful for testing. Expose
113    * the value of the option here.
114    */
115   bool shouldLoadDefaultConfig() const;
116 private:
117   void showUsage() const;
118   
119   int parseOption(const std::string& s);
120   
121   void processArgResult(int result);
122   
123   void setupRoot();
124   
125   std::string platformDefaultRoot() const;
126   
127   class OptionsPrivate;
128   std::auto_ptr<OptionsPrivate> p;
129 };
130   
131 } // of namespace flightgear
132
133 void fgSetDefaults();
134
135 #endif /* _OPTIONS_HXX */