SatAndLight
2.2.2-hubble
Simulation toolkit for space telescopes
|
Parse user options from the command line. More...
#include <Options.h>
Public Member Functions | |
double | GetValueD (const E_OPTIONS_ID aId) |
Returns option value (double). More... | |
int | GetValueI (const E_OPTIONS_ID aId) |
Returns option value (integer). More... | |
string | GetValueS (const E_OPTIONS_ID aId) |
Returns option value (string). More... | |
unsigned int | GetValueUI (const E_OPTIONS_ID aId) |
Returns option value (unsigned 32b integer). More... | |
unsigned long int | GetValueULI (const E_OPTIONS_ID aId) |
Returns option value (unsigned 64b integer). More... | |
vector< double > | GetValueVector (const E_OPTIONS_ID aId) |
Returns the option value as a vector of double values. More... | |
vector< string > | GetValueVectorS (const E_OPTIONS_ID aId) |
Returns the option value as a vector of sub-strings. More... | |
void | PrintUsage (void) |
Prints program usage. More... | |
int | Scan (int argc, char *argv[]) |
Parse the command line arguments. More... | |
void | SelectOption (const E_OPTIONS_ID aId, const string aDefaultValue, const bool aRequired=true, const string aExtraDescription="") |
Selects an option. More... | |
Constructors and destructors | |
SnlProg (const string aName, const string aDescription="", const string aDocPage="") | |
Constructor of the SnlProg class. More... | |
virtual | ~SnlProg (void) |
Destructor of the SnlProg class. More... | |
Private Member Functions | |
E_ERROR_CODE | CheckOpt (const E_OPTIONS_ID aId) |
Checks the sanity of user input values. More... | |
void | SaveValue (const string aKeyWord, const string aValue) |
Saves option value. More... | |
Private Attributes | |
string | desc |
Program description. More... | |
string | doc |
Link to documentation page. More... | |
string | name |
Program name. More... | |
SnlOpt * | opt [OPTIONS_ID_N] |
List of options. More... | |
bool | required [OPTIONS_ID_N] |
List of required options. More... | |
bool | selected [OPTIONS_ID_N] |
List of selected options. More... | |
bool | used [OPTIONS_ID_N] |
List of used options. More... | |
Parse user options from the command line.
The SnlProg class is designed to manage user options given to a SNL program in the command line. All SNL applications can be given options with the following format:
snl-program keyword1=value1 keyword2=value2 ...
The SnlProg class is used to parse the command line arguments and extract user parameters. It is based on a pre-defined list of possible options defined by an ID (_E_OPTIONS_ID). Each option is given:
Moreover options can be given attributes:
This class internally manages the usage message of a program (PrintUsage()). It also checks the sanity of input parameters (CheckOpt()).
The use of this class is simple. First the user must specify the list of options and attributes by calling SelectOption(). Then call Scan() to scan the list of user options.
SnlProg::SnlProg | ( | const string | aName, |
const string | aDescription = "" , |
||
const string | aDocPage = "" |
||
) |
Constructor of the SnlProg class.
The SNL options (_E_OPTIONS_ID) are initialized. By default none of the options listed in ::_E_OPTIONS_ID are selected. All of them are set to an "optional" mode. Use SelectOption() to select and configure an option.
[in] | aName | Name of the program. |
[in] | aDescription | Program description. |
[in] | aDocPage | Link to a documentation page. |
|
virtual |
Destructor of the SnlProg class.
|
private |
Checks the sanity of user input values.
Several sanity checks are implemented depending on the option ID:
[in] | aId | Option ID. |
|
inline |
Returns option value (double).
[in] | aId | Option ID. |
|
inline |
Returns option value (integer).
[in] | aId | Option ID. |
|
inline |
Returns option value (string).
[in] | aId | Option ID. |
|
inline |
Returns option value (unsigned 32b integer).
[in] | aId | Option ID. |
|
inline |
Returns option value (unsigned 64b integer).
[in] | aId | Option ID. |
vector< double > SnlProg::GetValueVector | ( | const E_OPTIONS_ID | aId | ) |
Returns the option value as a vector of double values.
Sometimes it can be convenient to use an option as a sequence of numbers. This function returns this sequence of numbers in a vector.
This only works if the option type is OPTIONS_TYPE_STRING. The character ';' is then used to seprate the numbers in the option value. For example if the option is given as:
keyword=2.3;5;3e45
This function returns 2.3, 5 and 3e45 in a vector of doubles.
[in] | aId | Option ID. |
|
inline |
Returns the option value as a vector of sub-strings.
Sometimes it can be convenient to use an option as a sequence of words. This function returns this sequence of words in a vector.
This only works if the character ';' is used to seprate the words in the option value. For example if the option is given as:
keyword=val1;val2;val3
This function returns "val1", "val2" and "val3" in a vector of strings.
[in] | aId | Option ID. |
void SnlProg::PrintUsage | ( | void | ) |
Prints program usage.
|
private |
Saves option value.
The option keyword is checked against the dictionary OPTIONS_KEY.
[in] | aKeyWord | Option keyword. |
[in] | aValue | Option value. |
int SnlProg::Scan | ( | int | argc, |
char * | argv[] | ||
) |
Parse the command line arguments.
The program command line is scanned:
In a second step, the user inputs are checked:
[in] | argc | Number of arguments in the program. |
[in] | argv | List of arguments in the program. |
void SnlProg::SelectOption | ( | const E_OPTIONS_ID | aId, |
const string | aDefaultValue, | ||
const bool | aRequired = true , |
||
const string | aExtraDescription = "" |
||
) |
Selects an option.
The option, identified by its ID, is activated and given attributes.
[in] | aId | Option ID. |
[in] | aDefaultValue | Option default value. |
[in] | aRequired | Option required flag: true = the option is required. false = the option is optional. |
[in] | aExtraDescription | Option extra description. |
|
private |
Program description.
|
private |
Link to documentation page.
|
private |
Program name.
|
private |
List of options.
|
private |
List of required options.
|
private |
List of selected options.
|
private |
List of used options.