Settings Class Reference

This class parses command line parameters, and keep runtime settings. More...

#include <settings.h>

List of all members.

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 SettingsGetGlobalSettings ()
 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.


Detailed Description

This class parses command line parameters, and keep runtime settings.

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.

Author:
Dan Torres 2008/12/09

Definition at line 62 of file settings.h.


Member Enumeration Documentation

Defines all boolean settings.

Enumerator:
Setting_Output_Verbose  PARAM(v|verbose) If true, dump strings with everything we do.
Setting_Python_OutputToFile  PARAM(l|logs) Redirect Python output to files instead of stdout.
Setting_Invalid  Invalid setting. Count of boolean options.

Definition at line 87 of file settings.h.

Defines all numeric settings.

Enumerator:
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.

Enumerator:
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.


Constructor & Destructor Documentation

Settings::Settings ( int  a_nArgCount,
char *  a_pArgValues[] 
)

Extended constructor.

Parameters:
a_nArgCount Number of arguments provided
a_pArgValues Array with argument value strings


Member Function Documentation

bool Settings::CanContinue (  )  [inline]

Tells if we have enough data to run our program.

Returns:
True if the program has enough information to continue

Definition at line 170 of file settings.h.

int Settings::Get ( eNumericSetting  a_nSetting  ) 

Returns the requested numberic setting.

Parameters:
a_nSetting A member of the eNumericSetting enumeration

char* Settings::Get ( eStringSetting  a_nSetting  ) 

Returns the requested string setting.

Parameters:
a_nSetting A member of the eStringSetting enumeration

bool Settings::Get ( eBooleanSetting  a_nSetting  ) 

Returns the requested boolean setting.

Parameters:
a_nSetting A member of the eBooleanSetting enumeration
Returns:
The value of the requested setting

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.

Returns:
A pointer to the current global settings, or NULL if unset

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

Parameters:
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.

Parameters:
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.

Parameters:
a_pSettings A pointer to a valid settings object

Definition at line 183 of file settings.h.


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

Generated on Tue Jan 20 17:58:00 2009 for EclipseRay by  doxygen 1.5.7.1