]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.hxx
e680f26d1ac5f85a961c64d8f09a6df34d81d7e1
[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     /**
39      * return the default platform dependant download directory.
40      * This must be a user-writeable location, the question is if it should
41      * be a user visible location. On Windows we default to a subdir of
42      * Documents (FlightGear), on Unixes we default to FG_HOME, which is
43      * typically invisible.
44      */
45     SGPath defaultDownloadDir();
46
47 /// option processing can have various result values
48 /// depending on what the user requested. Note processOptions only
49 /// returns a subset of these.
50 enum OptionResult
51 {
52     FG_OPTIONS_OK = 0,
53     FG_OPTIONS_HELP = 1,
54     FG_OPTIONS_ERROR = 2,
55     FG_OPTIONS_EXIT = 3,
56     FG_OPTIONS_VERBOSE_HELP = 4,
57     FG_OPTIONS_SHOW_AIRCRAFT = 5,
58     FG_OPTIONS_SHOW_SOUND_DEVICES = 6,
59     FG_OPTIONS_NO_DEFAULT_CONFIG = 7
60 };
61     
62 class Options
63 {
64 private:
65   Options();
66   
67 public:
68   static Options* sharedInstance();
69
70   ~Options();
71   
72   /**
73    * pass command line arguments, read default config files
74    */
75   void init(int argc, char* argv[], const SGPath& appDataPath);
76   
77   /**
78     * parse a config file (eg, .fgfsrc) 
79     */
80   void readConfig(const SGPath& path);
81   
82   /**
83     * read the value for an option, if it has been set
84     */
85   std::string valueForOption(const std::string& key, const std::string& defValue = std::string()) const;
86   
87   /**
88     * return all values for a multi-valued option
89     */
90   string_list valuesForOption(const std::string& key) const;
91   
92   /**
93     * check if a particular option has been set (so far)
94     */
95   bool isOptionSet(const std::string& key) const;
96   
97   
98   /**
99     * set an option value, assuming it is not already set (or multiple values
100     * are permitted)
101     * This can be used to inject option values, eg based upon environment variables
102     */
103   int addOption(const std::string& key, const std::string& value);
104
105   /**
106    * set an option, overwriting any existing value which might be set
107    */
108   int setOption(const std::string& key, const std::string& value);
109
110   void clearOption(const std::string& key);
111
112   /**
113    * apply option values to the simulation state
114    * (set properties, etc). 
115    */
116   OptionResult processOptions();
117
118     /**
119      * process command line options relating to scenery / aircraft / data paths
120      */
121     void initPaths();
122
123   /**
124    * init the aircraft options
125    */
126   void initAircraft();
127   
128   /**
129    * should defualt configuration files be loaded and processed or not?
130    * There's many configuration files we have historically read by default
131    * on startup - fgfs.rc in various places and so on.
132    * --no-default-config allows this behaviour to be changed, so only
133    * expicitly listed files are read Expose
134    * the value of the option here.
135    */
136   bool shouldLoadDefaultConfig() const;
137
138     /**
139      * when using the built-in launcher, we disable the default config files.
140      * explicitly loaded confg files are still permitted.
141      */
142     void setShouldLoadDefaultConfig(bool load);
143
144   /**
145    * check if the arguments array contains a particular string (with a '--' or
146    * '-' prefix).
147    * Used by early startup code before Options object is created
148    */
149   static bool checkForArg(int argc, char* argv[], const char* arg);
150
151       SGPath platformDefaultRoot() const;
152 private:
153   void showUsage() const;
154   
155   int parseOption(const std::string& s);
156   
157   void processArgResult(int result);
158
159     /**
160      * Setup the root base, and check it's valid. Bails out with exit(-1) if
161      * the root package was not found or is the incorrect version. Argv/argv
162      * are passed since we might potentially show a GUI dialog at this point
163      * to help the user our (finding a base package), and hence need to init Qt.
164      */
165   void setupRoot(int argc, char **argv);
166
167   
168   class OptionsPrivate;
169   std::auto_ptr<OptionsPrivate> p;
170 };
171   
172 } // of namespace flightgear
173
174 void fgSetDefaults();
175
176 #endif /* _OPTIONS_HXX */