]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
Support a --no-default-config option.
[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 class Options
39 {
40 private:
41   Options();
42   
43 public:
44   static Options* sharedInstance();
45
46   ~Options();
47   
48   /**
49    * pass command line arguments, read default config files
50    */
51   void init(int argc, char* argv[], const SGPath& appDataPath);
52   
53   /**
54     * parse a config file (eg, .fgfsrc) 
55     */
56   void readConfig(const SGPath& path);
57   
58   /**
59     * read the value for an option, if it has been set
60     */
61   std::string valueForOption(const std::string& key, const std::string& defValue = std::string()) const;
62   
63   /**
64     * return all values for a multi-valued option
65     */
66   string_list valuesForOption(const std::string& key) const;
67   
68   /**
69     * check if a particular option has been set (so far)
70     */
71   bool isOptionSet(const std::string& key) const;
72   
73   
74   /**
75     * set an option value, assuming it is not already set (or multiple values
76     * are permitted)
77     * This can be used to inject option values, eg based upon environment variables
78     */
79   int addOption(const std::string& key, const std::string& value);
80   
81   /**
82    * apply option values to the simulation state
83    * (set properties, etc)
84    */
85   void processOptions();
86   
87   /**
88    * init the aircraft options
89    */
90   void initAircraft();
91   
92   /**
93    * should defualt configuration files be loaded and processed or not?
94    * There's many configuration files we have historically read by default
95    * on startup - preferences.xml, fgfs.rc in various places and so on.
96    * --no-default-config allows this behaviour to be changed, so only
97    * expicitly listed files are read - this is useful for testing. Expose
98    * the value of the option here.
99    */
100   bool shouldLoadDefaultConfig() const;
101 private:
102   void showUsage() const;
103   
104   int parseOption(const std::string& s);
105   
106   void processArgResult(int result);
107   
108   void setupRoot();
109   
110   std::string platformDefaultRoot() const;
111   
112   class OptionsPrivate;
113   std::auto_ptr<OptionsPrivate> p;
114 };
115   
116 } // of namespace flightgear
117
118 #endif /* _OPTIONS_HXX */