Singleton class for management of command-line options.
More...
#include <FFaCmdLineArg.H>
|
template<class T > |
void | addOption (const std::string &identifier, const T &value, const std::string &helpText, bool showToAll=true) |
| Defines a new command-line option of arbitrary type. More...
|
|
void | addOption (const std::string &identifier, const char *value, const std::string &helpText, bool showToAll=true) |
| Defines a new command-line option of string type. More...
|
|
template<class T > |
bool | getValue (const std::string &identifier, T &aVal) |
| Returns the actual value of the specified command-line option. More...
|
|
bool | setValue (const std::string &identifier, const std::string &value) |
| Assigns a new value to the specified command-line option. More...
|
|
void | composeHelpText (std::string &report, bool all=false) const |
| Creates a multi-line string with a list of all defined options. More...
|
|
void | composeSingleLineHelpText (std::string &report, bool all=false) const |
| Same as composeHelpText(), but with each option as a single line. More...
|
|
void | listOptions (bool noDefaults=false) const |
| Prints out all specified command-line options. More...
|
|
bool | isOptionSetOnCmdLine (const std::string &identifier) |
| Checks if an option identifier is specified on the command-line. More...
|
|
bool | readOptionsFile (const std::string &fileName) |
| Reads command-line option values from the file fileName. More...
|
|
|
static void | init (int argc, char **argv) |
| Initializes the command-line options singleton object. More...
|
|
static bool | empty () |
| Returns true if no command-line options have been defined. More...
|
|
static FFaCmdLineArg * | instance () |
| Returns the one and only instance of this class. More...
|
|
static void | removeInstance () |
| Deletes the dynamically allocated instance. More...
|
|
|
static std::string | additionalHelpText |
| This text is printed after the option list itself when using "-help". More...
|
|
static bool | mute = false |
| If true, error messages are muted. More...
|
|
Singleton class for management of command-line options.
All options are in the standard form <switch word>[ ]<option>, and each switch word must be prefixed with either '-' or '/'. (only '-' is valid on UNIX)
The command argument parser can be used this way:
int main(
int argc,
char** argv)
{
double rate;
std::cout << rate << std::endl;
...
}
static FFaCmdLineArg * instance()
Returns the one and only instance of this class.
Definition: FFaCmdLineArgImplementation.C:89
static void init(int argc, char **argv)
Initializes the command-line options singleton object.
Definition: FFaCmdLineArg.H:135
void addOption(const std::string &identifier, const T &value, const std::string &helpText, bool showToAll=true)
Defines a new command-line option of arbitrary type.
Definition: FFaCmdLineArg.H:148
bool getValue(const std::string &identifier, T &aVal)
Returns the actual value of the specified command-line option.
Definition: FFaCmdLineArg.H:177
int main(int argc, char **argv)
Main program for the FEDEM dynamics solver.
Definition: main.C:36
- Author
- Jens Lien
◆ OptionMap
Data type for the command-line options container.
◆ FFaCmdLineArg()
FFaCmdLineArg::FFaCmdLineArg |
( |
| ) |
|
|
private |
The default constructor is private to avoid other instances.
◆ ~FFaCmdLineArg()
FFaCmdLineArg::~FFaCmdLineArg |
( |
| ) |
|
|
private |
◆ addOption() [1/2]
void FFaCmdLineArg::addOption |
( |
const std::string & |
identifier, |
|
|
const char * |
value, |
|
|
const std::string & |
helpText, |
|
|
bool |
showToAll = true |
|
) |
| |
|
inline |
Defines a new command-line option of string type.
- Parameters
-
[in] | identifier | The actual option is "-<identifier>" |
[in] | value | Default value of this option |
[in] | helpText | Textual decription printed via the option "-help" |
[in] | showToAll | true if this option is public |
◆ addOption() [2/2]
template<class T >
void FFaCmdLineArg::addOption |
( |
const std::string & |
identifier, |
|
|
const T & |
value, |
|
|
const std::string & |
helpText, |
|
|
bool |
showToAll = true |
|
) |
| |
|
inline |
Defines a new command-line option of arbitrary type.
- Parameters
-
[in] | identifier | The actual option is "-<identifier>" |
[in] | value | Default value of this option |
[in] | helpText | Textual decription printed via the option "-help" |
[in] | showToAll | true if this option is public |
◆ composeHelpText()
void FFaCmdLineArg::composeHelpText |
( |
std::string & |
report, |
|
|
bool |
all = false |
|
) |
| const |
Creates a multi-line string with a list of all defined options.
- Parameters
-
[out] | report | A report with option descriptions and default values |
[in] | all | If true, include also private (normally hidden) options |
◆ composeSingleLineHelpText()
void FFaCmdLineArg::composeSingleLineHelpText |
( |
std::string & |
report, |
|
|
bool |
all = false |
|
) |
| const |
◆ empty()
bool FFaCmdLineArg::empty |
( |
| ) |
|
|
static |
Returns true if no command-line options have been defined.
◆ evaluate()
void FFaCmdLineArg::evaluate |
( |
| ) |
|
|
private |
Processes the temporary command-line option list myArgs.
◆ getValue()
template<class T >
bool FFaCmdLineArg::getValue |
( |
const std::string & |
identifier, |
|
|
T & |
aVal |
|
) |
| |
|
inline |
Returns the actual value of the specified command-line option.
- Parameters
-
[in] | identifier | The option to return the value for |
[out] | aVal | The actual value of the command-line option |
- Returns
- true if the specified option was defined, otherwise false
◆ init()
static void FFaCmdLineArg::init |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
|
inlinestatic |
Initializes the command-line options singleton object.
◆ initArgs()
void FFaCmdLineArg::initArgs |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
|
private |
Copies all command-line arguments into a temporary container.
◆ instance()
Returns the one and only instance of this class.
◆ isOptionSetOnCmdLine()
bool FFaCmdLineArg::isOptionSetOnCmdLine |
( |
const std::string & |
identifier | ) |
|
Checks if an option identifier is specified on the command-line.
Returns true if the option is specified, and false if it is not set. If the option is undefined, return false and print a warning to std::cerr.
◆ listOptions()
void FFaCmdLineArg::listOptions |
( |
bool |
noDefaults = false | ) |
const |
Prints out all specified command-line options.
- Parameters
-
[in] | noDefaults | If true, print out all defined options |
◆ readOptionsFile()
bool FFaCmdLineArg::readOptionsFile |
( |
const std::string & |
fileName | ) |
|
Reads command-line option values from the file fileName.
◆ removeInstance()
void FFaCmdLineArg::removeInstance |
( |
| ) |
|
|
static |
Deletes the dynamically allocated instance.
◆ setValue()
bool FFaCmdLineArg::setValue |
( |
const std::string & |
identifier, |
|
|
const std::string & |
value |
|
) |
| |
Assigns a new value to the specified command-line option.
- Parameters
-
[in] | identifier | The option to assign new value for |
[in] | value | New value of this option |
- Returns
- true if the specified option was defined, otherwise false
◆ additionalHelpText
std::string FFaCmdLineArg::additionalHelpText |
|
static |
This text is printed after the option list itself when using "-help".
◆ mute
bool FFaCmdLineArg::mute = false |
|
static |
If true, error messages are muted.
◆ myArgs
std::vector<std::string> FFaCmdLineArg::myArgs |
|
private |
Temporary command-line option storage.
◆ myInstance
The actual instance of this class.
◆ myOptions
Command-line options container.
The documentation for this class was generated from the following files: