FlightGear next
flightgear::Options Class Reference

#include <options.hxx>

Classes

class  OptionsPrivate
 

Public Member Functions

 ~Options ()
 
OptionResult init (int argc, char *argv[], const SGPath &appDataPath)
 pass command line arguments, read default config files
 
void readConfig (const SGPath &path)
 parse a config file (eg, .fgfsrc)
 
std::string valueForOption (const std::string &key, const std::string &defValue=std::string()) const
 read the value for an option, if it has been set
 
string_list valuesForOption (const std::string &key) const
 return all values for a multi-valued option
 
bool isOptionSet (const std::string &key) const
 Check if a particular option has been set (so far).
 
std::optional< bool > checkBoolOptionSet (const std::string &key) const
 Check if the user has specified a given boolean option.
 
bool isBoolOptionEnable (const std::string &key) const
 An overlay on checkBoolOptionSet, except that when the user has not used the option at all then false is returned.
 
bool isBoolOptionDisable (const std::string &key) const
 An overlay on checkBoolOptionSet, to check whether user used the option with explicitly disable it.
 
int addOption (const std::string &key, const std::string &value)
 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 setOption (const std::string &key, const std::string &value)
 set an option, overwriting any existing value which might be set
 
void clearOption (const std::string &key)
 
OptionResult processOptions ()
 apply option values to the simulation state (set properties, etc).
 
void initPaths ()
 process command line options relating to scenery / aircraft / data paths
 
OptionResult initAircraft ()
 init the aircraft options
 
bool shouldLoadDefaultConfig () const
 should defualt configuration files be loaded and processed or not?
 
void setShouldLoadDefaultConfig (bool load)
 when using the built-in launcher, we disable the default config files.
 
SGPath platformDefaultRoot () const
 
string_list extractOptions () const
 extractOptions - extract the currently set options as a string array.
 
SGPath actualDownloadDir ()
 the actual download dir in use, which may be the default or a user-supplied value
 

Static Public Member Functions

static OptionssharedInstance ()
 
static void reset ()
 Delete the entire options object.
 
static bool checkForArg (int argc, char *argv[], const char *arg)
 Check if the arguments array contains a particular string (with a '–' or '-' prefix).
 
static std::optional< bool > checkForBoolArg (int argc, char *argv[], const std::string &checkArg)
 Check if the user has specified a given boolean option.
 
static bool checkForArgEnable (int argc, char *argv[], const std::string &checkArg)
 Return true when user explicitly enabled boolean option, otherwise false.
 
static bool checkForArgDisable (int argc, char *argv[], const std::string &checkArg)
 Return true when user explicitly disabled boolean option by set false value.
 
static std::string getArgValue (int argc, char *argv[], const char *checkArg)
 getArgValue - get the value of an argument if it exists, or an empty string otherwise
 
static bool paramToBool (const std::string &param)
 Convert string to bool for boolean options.
 

Detailed Description

Definition at line 64 of file options.hxx.

Constructor & Destructor Documentation

◆ ~Options()

flightgear::Options::~Options ( )

Definition at line 2377 of file options.cxx.

Member Function Documentation

◆ actualDownloadDir()

SGPath flightgear::Options::actualDownloadDir ( )

the actual download dir in use, which may be the default or a user-supplied value

Definition at line 3010 of file options.cxx.

◆ addOption()

int flightgear::Options::addOption ( const std::string & key,
const std::string & value )

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

Definition at line 2859 of file options.cxx.

◆ checkBoolOptionSet()

std::optional< bool > flightgear::Options::checkBoolOptionSet ( const std::string & key) const

Check if the user has specified a given boolean option.

We need to return 3 states:

  • 1 - the user has explicitly enabled the option,
  • 0 - the user has explicitly disabled the option,
  • -1 - the user has not used the specified option at all.

User provided options => Using the method => Result –enable-fullscreen => checkBoolOptionSet("fullscreen") => true –disable-fullscreen => checkBoolOptionSet("fullscreen") => false –fullscreen => checkBoolOptionSet("fullscreen") => true –fullscreen true => checkBoolOptionSet("fullscreen") => true –fullscreen false => checkBoolOptionSet("fullscreen") => false –fullscreen 1 => checkBoolOptionSet("fullscreen") => true –fullscreen 0 => checkBoolOptionSet("fullscreen") => false –fullscreen yes => checkBoolOptionSet("fullscreen") => true –fullscreen no => checkBoolOptionSet("fullscreen") => false {none of the above} => checkBoolOptionSet("fullscreen") => no value

Definition at line 2961 of file options.cxx.

◆ checkForArg()

bool flightgear::Options::checkForArg ( int argc,
char * argv[],
const char * arg )
static

Check if the arguments array contains a particular string (with a '–' or '-' prefix).

Used by early startup code before Options object is created. For boolean option please use checkForBoolArg or checkForArgEnable/checkForArgDisable.

Definition at line 3603 of file options.cxx.

◆ checkForArgDisable()

bool flightgear::Options::checkForArgDisable ( int argc,
char * argv[],
const std::string & checkArg )
static

Return true when user explicitly disabled boolean option by set false value.

Used by early startup code before Options object is created.

Definition at line 3687 of file options.cxx.

◆ checkForArgEnable()

bool flightgear::Options::checkForArgEnable ( int argc,
char * argv[],
const std::string & checkArg )
static

Return true when user explicitly enabled boolean option, otherwise false.

Used by early startup code before Options object is created.

Definition at line 3681 of file options.cxx.

◆ checkForBoolArg()

std::optional< bool > flightgear::Options::checkForBoolArg ( int argc,
char * argv[],
const std::string & checkArg )
static

Check if the user has specified a given boolean option.

Used by early startup code before Options object is created. We need to return 3 states:

  • 1 - the user has explicitly enabled the option,
  • 0 - the user has explicitly disabled the option,
  • -1 - the user has not used the specified option at all.

User provided options => Using the method => Result –enable-fullscreen => checkForBoolArg(argc, argv, "fullscreen") => true –disable-fullscreen => checkForBoolArg(argc, argv, "fullscreen") => false –fullscreen => checkForBoolArg(argc, argv, "fullscreen") => true –fullscreen true => checkForBoolArg(argc, argv, "fullscreen") => true –fullscreen false => checkForBoolArg(argc, argv, "fullscreen") => false –fullscreen 1 => checkForBoolArg(argc, argv, "fullscreen") => true –fullscreen 0 => checkForBoolArg(argc, argv, "fullscreen") => false –fullscreen yes => checkForBoolArg(argc, argv, "fullscreen") => true –fullscreen no => checkForBoolArg(argc, argv, "fullscreen") => false {none of the above} => checkForBoolArg(argc, argv, "fullscreen") => no value

Definition at line 3628 of file options.cxx.

◆ clearOption()

void flightgear::Options::clearOption ( const std::string & key)

Definition at line 2916 of file options.cxx.

◆ extractOptions()

string_list flightgear::Options::extractOptions ( ) const

extractOptions - extract the currently set options as a string array.

This can be used to examine what options were requested / set so far.

Returns

Definition at line 3490 of file options.cxx.

◆ getArgValue()

std::string flightgear::Options::getArgValue ( int argc,
char * argv[],
const char * checkArg )
static

getArgValue - get the value of an argument if it exists, or an empty string otherwise

Parameters
argc
argv
checkArg: arg to look for, with '–' prefix
Returns
value following '=' until the next white space

Definition at line 3693 of file options.cxx.

◆ init()

OptionResult flightgear::Options::init ( int argc,
char * argv[],
const SGPath & appDataPath )

pass command line arguments, read default config files

Definition at line 2381 of file options.cxx.

◆ initAircraft()

OptionResult flightgear::Options::initAircraft ( )

init the aircraft options

Definition at line 2583 of file options.cxx.

◆ initPaths()

void flightgear::Options::initPaths ( )

process command line options relating to scenery / aircraft / data paths

Definition at line 2569 of file options.cxx.

◆ isBoolOptionDisable()

bool flightgear::Options::isBoolOptionDisable ( const std::string & key) const

An overlay on checkBoolOptionSet, to check whether user used the option with explicitly disable it.

For non-boolean option please use isOptionSet.

Definition at line 2995 of file options.cxx.

◆ isBoolOptionEnable()

bool flightgear::Options::isBoolOptionEnable ( const std::string & key) const

An overlay on checkBoolOptionSet, except that when the user has not used the option at all then false is returned.

For non-boolean option please use isOptionSet.

Definition at line 2989 of file options.cxx.

◆ isOptionSet()

bool flightgear::Options::isOptionSet ( const std::string & key) const

Check if a particular option has been set (so far).

For boolean option please use isBoolOptionEnable or isBoolOptionDisable.

Definition at line 2924 of file options.cxx.

◆ paramToBool()

bool flightgear::Options::paramToBool ( const std::string & param)
static

Convert string to bool for boolean options.

When param cannot be recognized as bool then the true is returned.

Definition at line 2738 of file options.cxx.

◆ platformDefaultRoot()

SGPath flightgear::Options::platformDefaultRoot ( ) const

Definition at line 3483 of file options.cxx.

◆ processOptions()

OptionResult flightgear::Options::processOptions ( )

apply option values to the simulation state (set properties, etc).

Definition at line 3025 of file options.cxx.

◆ readConfig()

void flightgear::Options::readConfig ( const SGPath & path)

parse a config file (eg, .fgfsrc)

Definition at line 2691 of file options.cxx.

◆ reset()

void flightgear::Options::reset ( )
static

Delete the entire options object.

Use with a degree of care, no code should ever be caching the Options pointer but this has not actually been checked across the whole code :)

Definition at line 2354 of file options.cxx.

◆ setOption()

int flightgear::Options::setOption ( const std::string & key,
const std::string & value )

set an option, overwriting any existing value which might be set

Definition at line 2896 of file options.cxx.

◆ setShouldLoadDefaultConfig()

void flightgear::Options::setShouldLoadDefaultConfig ( bool load)

when using the built-in launcher, we disable the default config files.

explicitly loaded confg files are still permitted.

Definition at line 3598 of file options.cxx.

◆ sharedInstance()

Options * flightgear::Options::sharedInstance ( )
static

Definition at line 2345 of file options.cxx.

◆ shouldLoadDefaultConfig()

bool flightgear::Options::shouldLoadDefaultConfig ( ) const

should defualt configuration files be loaded and processed or not?

There's many configuration files we have historically read by default on startup - fgfs.rc in various places and so on. –no-default-config allows this behaviour to be changed, so only expicitly listed files are read Expose the value of the option here.

Definition at line 3593 of file options.cxx.

◆ valueForOption()

string flightgear::Options::valueForOption ( const std::string & key,
const std::string & defValue = std::string() ) const

read the value for an option, if it has been set

Definition at line 2934 of file options.cxx.

◆ valuesForOption()

string_list flightgear::Options::valuesForOption ( const std::string & key) const

return all values for a multi-valued option

Definition at line 2944 of file options.cxx.


The documentation for this class was generated from the following files: