]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.hxx
VS2015 compatability fixes.
[flightgear.git] / src / Main / options.hxx
index 4ad8b133d335e1f3292fc3c12122411171a724ce..4f618213b55c45afc80bca1df8171f012f261e9f 100644 (file)
 #ifndef _OPTIONS_HXX
 #define _OPTIONS_HXX
 
+#include <memory>
+#include <string>
 
-#ifndef __cplusplus
-# error This library requires C++
-#endif
+#include <simgear/misc/strutils.hxx>
 
-extern void fgSetDefaults ();
-extern void fgParseArgs (int argc, char ** argv);
-extern void fgParseOptions (const string &file_path);
-extern void fgUsage (bool verbose = false);
+// forward decls
+class SGPath;
+
+namespace flightgear
+{
+
+    /**
+     * return the default platform dependant download directory.
+     * This must be a user-writeable location, the question is if it should
+     * be a user visible location. On Windows we default to a subdir of
+     * Documents (FlightGear), on Unixes we default to FG_HOME, which is
+     * typically invisible.
+     */
+    std::string defaultDownloadDir();
+
+/// option processing can have various result values
+/// depending on what the user requested. Note processOptions only
+/// returns a subset of these.
+enum OptionResult
+{
+    FG_OPTIONS_OK = 0,
+    FG_OPTIONS_HELP = 1,
+    FG_OPTIONS_ERROR = 2,
+    FG_OPTIONS_EXIT = 3,
+    FG_OPTIONS_VERBOSE_HELP = 4,
+    FG_OPTIONS_SHOW_AIRCRAFT = 5,
+    FG_OPTIONS_SHOW_SOUND_DEVICES = 6,
+    FG_OPTIONS_NO_DEFAULT_CONFIG = 7
+};
+    
+class Options
+{
+private:
+  Options();
+  
+public:
+  static Options* sharedInstance();
+
+  ~Options();
+  
+  /**
+   * pass command line arguments, read default config files
+   */
+  void init(int argc, char* argv[], const SGPath& appDataPath);
+  
+  /**
+    * parse a config file (eg, .fgfsrc) 
+    */
+  void readConfig(const SGPath& path);
+  
+  /**
+    * read the value for an option, if it has been set
+    */
+  std::string valueForOption(const std::string& key, const std::string& defValue = std::string()) const;
+  
+  /**
+    * return all values for a multi-valued option
+    */
+  string_list valuesForOption(const std::string& key) const;
+  
+  /**
+    * check if a particular option has been set (so far)
+    */
+  bool isOptionSet(const std::string& key) const;
+  
+  
+  /**
+    * set an option value, assuming it is not already set (or multiple values
+    * are permitted)
+    * This can be used to inject option values, eg based upon environment variables
+    */
+  int addOption(const std::string& key, const std::string& value);
+
+  /**
+   * set an option, overwriting any existing value which might be set
+   */
+  int setOption(const std::string& key, const std::string& value);
+
+  void clearOption(const std::string& key);
+
+  /**
+   * apply option values to the simulation state
+   * (set properties, etc). 
+   */
+  OptionResult processOptions();
+
+    /**
+     * process command line options relating to scenery / aircraft / data paths
+     */
+    void initPaths();
+
+  /**
+   * init the aircraft options
+   */
+  void initAircraft();
+  
+  /**
+   * should defualt configuration files be loaded and processed or not?
+   * There's many configuration files we have historically read by default
+   * on startup - preferences.xml, fgfs.rc in various places and so on.
+   * --no-default-config allows this behaviour to be changed, so only
+   * expicitly listed files are read - this is useful for testing. Expose
+   * the value of the option here.
+   */
+  bool shouldLoadDefaultConfig() const;
+
+  /**
+   * check if the arguments array contains a particular string (with a '--' or
+   * '-' prefix).
+   * Used by early startup code before Options object is created
+   */
+  static bool checkForArg(int argc, char* argv[], const char* arg);
+
+      std::string platformDefaultRoot() const;
+private:
+  void showUsage() const;
+  
+  int parseOption(const std::string& s);
+  
+  void processArgResult(int result);
+
+    /**
+     * Setup the root base, and check it's valid. Bails out with exit(-1) if
+     * the root package was not found or is the incorrect version. Argv/argv
+     * are passed since we might potentially show a GUI dialog at this point
+     * to help the user our (finding a base package), and hence need to init Qt.
+     */
+  void setupRoot(int argc, char **argv);
+
+  
+  class OptionsPrivate;
+  std::auto_ptr<OptionsPrivate> p;
+};
+  
+} // of namespace flightgear
+
+void fgSetDefaults();
 
 #endif /* _OPTIONS_HXX */