SPH
|
Provides functions for parsing command-line arguments. More...
#include <ArgsParser.h>
Public Member Functions | |
ArgParser (ArrayView< const ArgDesc > args) | |
Creates a parser, given a set of parameter descriptors. More... | |
void | parse (const int argc, char **argv) |
Parses the input arguments and stored the parsed values. More... | |
void | printHelp (ILogger &logger) |
Prints the help information into given logger. More... | |
template<typename TValue > | |
TValue | getArg (const std::string &name) const |
Returns the value of an argument, given its short name (without the dash). More... | |
template<typename TValue > | |
Optional< TValue > | tryGetArg (const std::string &name) const |
Returns the value of an argument or NOTHING if the argument was not parsed. More... | |
template<typename TEnum , typename TConvertor > | |
bool | tryStore (Settings< TEnum > &settings, const std::string &name, const TEnum idx, TConvertor &&conv) |
Stores the value of given argument into an instance of Settings. More... | |
template<typename TEnum > | |
bool | tryStore (Settings< TEnum > &settings, const std::string &name, const TEnum idx) |
Stores the value of given argument into an instance of Settings. More... | |
template<typename TFunctor > | |
void | forEach (const TFunctor &functor) |
Enumerates all parsed arguments and executes a generic functor with parsed values. More... | |
Size | size () const |
Returns the number of parsed arguments. More... | |
bool | empty () const |
Returns true if no arguments have been parsed. More... | |
Provides functions for parsing command-line arguments.
Definition at line 62 of file ArgsParser.h.
|
explicit |
Creates a parser, given a set of parameter descriptors.
The "help" parameter (-h or –help) is automatically added into the set. It can be used to print the program help, using data provided in the descriptors.
Definition at line 6 of file ArgsParser.cpp.
|
inline |
Returns true if no arguments have been parsed.
Definition at line 175 of file ArgsParser.h.
|
inline |
Enumerates all parsed arguments and executes a generic functor with parsed values.
Functor must be either generic lambda, or it must overload operator() for each parsed type, as listed in enum ArgEnum. The operator must have signature void(std::string, Type). The arguments are identified using its short name, without the dash.
Definition at line 163 of file ArgsParser.h.
|
inline |
Returns the value of an argument, given its short name (without the dash).
ArgError | if the argument was not been parsed or it has different type. |
Definition at line 95 of file ArgsParser.h.
void ArgParser::parse | ( | const int | argc, |
char ** | argv | ||
) |
Parses the input arguments and stored the parsed values.
Parsed values can be later queried using getArg or forEach functions. Previous values are removed.
ArgError | if the input is not valid. |
Definition at line 16 of file ArgsParser.cpp.
void ArgParser::printHelp | ( | ILogger & | logger | ) |
Prints the help information into given logger.
This is automatically called when parse is called with argument -h or –help.
Definition at line 51 of file ArgsParser.cpp.
|
inline |
Returns the number of parsed arguments.
Definition at line 170 of file ArgsParser.h.
|
inline |
Returns the value of an argument or NOTHING if the argument was not parsed.
ArgError | if the name does not match any argument descriptor or it has different type. |
Definition at line 110 of file ArgsParser.h.
|
inline |
Stores the value of given argument into an instance of Settings.
Overload without value convertor.
Definition at line 153 of file ArgsParser.h.
|
inline |
Stores the value of given argument into an instance of Settings.
If the value was not parsed, no value is stored and function returns false. Otherwise, true is returned.
settings | Settings object where the parsed value is stored (if present). |
name | Short name identifying the argument. |
idx | Index of the target entry in Settings. |
conv | Generic value convertor, applied on value saved to Settings. Applied only on float arguments. |
ArgError | if the name does not match any argument descriptor. |
Definition at line 134 of file ArgsParser.h.