#include <settings.h>
Public Types | |
enum | eBooleanSetting { Setting_Output_Verbose, Setting_Python_OutputToFile, Setting_Invalid } |
Defines all boolean settings. More... | |
enum | eStringSetting { Setting_ProgramName, Setting_MainScript, Setting_PluginDir } |
Defines all string settings. More... | |
enum | eNumericSetting { Setting_ErrorHeapSize, Setting_CPUCores } |
Defines all numeric settings. More... | |
Public Member Functions | |
Settings () | |
Default constructor. | |
Settings (int a_nArgCount, char *a_pArgValues[]) | |
Extended constructor. | |
~Settings () | |
Default destructor. | |
void | Parse (int a_nArgCount, char *a_pArgValues[]) |
Parses settings from the provided string array Parameters are translated on the GetSettingFromString function. | |
void | Set (eBooleanSetting a_nSetting, bool a_bValue) |
Sets the value of a boolean setting. | |
bool | Get (eBooleanSetting a_nSetting) |
Returns the requested boolean setting. | |
char * | Get (eStringSetting a_nSetting) |
Returns the requested string setting. | |
int | Get (eNumericSetting a_nSetting) |
Returns the requested numberic setting. | |
bool | CanContinue () |
Tells if we have enough data to run our program. | |
void | PrintSettingsHelp () |
Prints help strings to stdout. | |
Static Public Member Functions | |
static void | SetGlobalSettings (Settings *a_pSettings) |
Sets the global settings pointer Note that this class is never responsible for the ownership of globally accessible settings. | |
static Settings * | GetGlobalSettings () |
Retrieves the global settings, or null if no settings have been set This function will simply return whatever settings have been assigned as the global settings object. |
A simple object that keeps different runtime settings and parsers arguments.
Command line parsing follows this syntax:
program.exe [PARAMS] filename.py
PARAMS are prefixed with '-', and enable configuration switches. The filename specifies a python script file with the code to execute. If no filename is identified and the parameters don't contain enough information to tell the program what to do, a help string is displayed.
About global settings
You can use two functions to set and retrieve a temporary Settings object, to be accessible from anywhere in the engine. Do this with caution, though, and make sure you reset it to NULL if the settings object is destroyed or goes out of context. Otherwise, callers that depend on it will encounter an invalid object.
About setting types
We could had created an abstract interface for setting values that hid their underlying type (i.e., something like ISetting), but in the spirit of simplicity, we are just declaring three types and three polymorphic functions.
Definition at line 62 of file settings.h.
Defines all boolean settings.
Definition at line 87 of file settings.h.
Defines all numeric settings.
Setting_ErrorHeapSize | Number of errors to keep in our heap. |
Setting_CPUCores | Number of CPU cores available. |
Definition at line 112 of file settings.h.
Defines all string settings.
Setting_ProgramName | Name of this application. |
Setting_MainScript | Name of the program or script to run. |
Setting_PluginDir | Path to the YR plugins. |
Definition at line 100 of file settings.h.
Settings::Settings | ( | int | a_nArgCount, | |
char * | a_pArgValues[] | |||
) |
Extended constructor.
a_nArgCount | Number of arguments provided | |
a_pArgValues | Array with argument value strings |
bool Settings::CanContinue | ( | ) | [inline] |
Tells if we have enough data to run our program.
Definition at line 170 of file settings.h.
int Settings::Get | ( | eNumericSetting | a_nSetting | ) |
Returns the requested numberic setting.
a_nSetting | A member of the eNumericSetting enumeration |
char* Settings::Get | ( | eStringSetting | a_nSetting | ) |
Returns the requested string setting.
a_nSetting | A member of the eStringSetting enumeration |
bool Settings::Get | ( | eBooleanSetting | a_nSetting | ) |
Returns the requested boolean setting.
a_nSetting | A member of the eBooleanSetting enumeration |
static Settings* Settings::GetGlobalSettings | ( | ) | [inline, static] |
Retrieves the global settings, or null if no settings have been set This function will simply return whatever settings have been assigned as the global settings object.
It does not test to see if they are valid, so use it with care. See class declaration notes for more info.
Definition at line 192 of file settings.h.
void Settings::Parse | ( | int | a_nArgCount, | |
char * | a_pArgValues[] | |||
) |
Parses settings from the provided string array Parameters are translated on the GetSettingFromString function.
Values are translated on the GetValueFromString function. For a description of what is expected here, look at both of them. In general, a setting=value set of strings is expected for non-booleans, and the presence of a setting name implies a
a_nArgCount | Number of arguments provided | |
a_pArgValues | Array with argument value strings |
void Settings::Set | ( | eBooleanSetting | a_nSetting, | |
bool | a_bValue | |||
) |
Sets the value of a boolean setting.
a_nSetting | A member of the eBooleanSetting enumeration | |
a_bValue | The value to set |
static void Settings::SetGlobalSettings | ( | Settings * | a_pSettings | ) | [inline, static] |
Sets the global settings pointer Note that this class is never responsible for the ownership of globally accessible settings.
The caller owns the actual settings object.
a_pSettings | A pointer to a valid settings object |
Definition at line 183 of file settings.h.