|
| OptionsParser (int argc, const char **argv) |
|
| ~OptionsParser () |
|
template<typename T > |
void | addOption (T ¶m, const std::string &token, const std::string &description, bool optional=false) |
| Adds a single parameter to be parsed on the commandline. More...
|
|
template<typename T > |
void | addOptionSeries (T ¶m, const std::string &token, const std::string &description, unsigned minnum=0, unsigned maxnum=0) |
| Adds a series of parameters to be parsed on the commandline. More...
|
|
void | alias (const std::string &to, const std::string &from) |
| Gives an alternative name (token) to to the parameter of token from . More...
|
|
void | parse () |
| Parses the commandline arguments (argc, argv) and fills in the registered parameters variables. More...
|
|
void | check () |
| Check all needed parameters are filled in, and series numbers are OK. More...
|
|
Commandline options parser.
Usage: instantiate a parser, add parameters using addOption(), then call parse() and check().
You generally do not use OptionsParser directly, but rather a subclass of it: CartoApplication
, or AimsApplication
in aims commands.
example:
std::string input, output;
int param = 10;
app.addOption( input, "-i", "input file" );
app.addOption( output, "-o", "output file" );
app.addOption( param, "-p", "an int parameter (default value: 10)", true );
try
{
app.parse();
app.check();
}
catch( std::exception & e )
{
std::cerr << e.what();
throw;
}
Definition at line 470 of file getopt.h.
template<typename T >
void OptionsParser::addOptionSeries |
( |
T & |
param, |
|
|
const std::string & |
token, |
|
|
const std::string & |
description, |
|
|
unsigned |
minnum = 0 , |
|
|
unsigned |
maxnum = 0 |
|
) |
| |
|
inline |
Adds a series of parameters to be parsed on the commandline.
A series of parameters is a STL sequence of parameters of the same type, all given by the same commandline option switch: for instance if "-i"
is a series of parameters of type string, the commandline will accept the arguments "-i file1 -i file2"
- Parameters
-
param | the parameter variable (it will be filled automatically when parse() is called). It must be a STL-compatible sequence (like a vector or a list) with iterators (begin(), end(), rbegin() methods), a value_type type, and a push_back() insertion method. |
token | option switch used to identify this parameter on the commandline |
description | the help string for this option (displayed when invoking the commandline with the "--help" option) |
minnum | minimum admissible number of occurrences of this parameter: 0 means it it optional |
maxnum | maximum admissible number of occurrences of this parameter, the special value 0 means unlimited |
Definition at line 558 of file getopt.h.