Hex
1.0
Hydrogen-electron collision solver
|
Go to the source code of this file.
Functions | |
template<class DefaultCallback > | |
bool | HandleSwitch (int &i, int argc, char *argv[], DefaultCallback callback) |
Command line option default hanndler. More... | |
template<class Callback , class... Params> | |
bool | HandleSwitch (int &i, int argc, char *argv[], std::string longoptname, std::string shortoptname, unsigned noptarg, Callback callback, Params...params) |
Command line option handler. More... | |
template<class... Params> | |
void | ParseCommandLine (int argc, char *argv[], Params...params) |
Parse command line. More... | |
bool HandleSwitch | ( | int & | i, |
int | argc, | ||
char * | argv[], | ||
DefaultCallback | callback | ||
) |
This function is used by the parser ParseCommandLine and it is not expected to be used on its own by the user. It is called by ParseCommandLine or by the other HandleSwitch function template if the remaining number of handlers is one – just the default callback.
i | Index of current argv[i] being parsed. On return, the value is incremented because the argv[i] will have been digested by this function. |
argc | Argc as passed to the main function. |
argv | Argv as passed to the main function. |
callback | Default callback, which is a functor accepting two std::string parameters: the unmatched option and its optarg. |
bool HandleSwitch | ( | int & | i, |
int | argc, | ||
char * | argv[], | ||
std::string | longoptname, | ||
std::string | shortoptname, | ||
unsigned | noptarg, | ||
Callback | callback, | ||
Params... | params | ||
) |
This function is used by the parser ParseCommandLine and it is not expected to be used on its own by the user.
i | Index of the option (argv[i]) to handle. On return, the value can be once or more times incremented, if more argv[i] values have been digested as optarg-s. |
argc | Argc as passed to the main function. |
argv | Argv as passed to the main function. |
longoptname | Long option name of the handler to use. |
shortoptname | Short option name of the handler to use. |
noptarg | Number of optarg-s needed for this option. |
callback | Callback function accepting std::string optarg and returning bool. |
...params | Other params that will be ignored in this pass, but may be used in the next one if argv[i] does match neither longoptname nor shortoptname. |
void ParseCommandLine | ( | int | argc, |
char * | argv[], | ||
Params... | params | ||
) |
This variadic function template can be used to parse the command line arguments. For every argv[i], i > 0, it will scan through the supplied handlers and whenever it finds a correct handler, it will call the associated callback function. A "handler" is a quartet of parameters:
A typical usage of the parser is:
The last argument is the default handler that accepts also the option name. It is used if no handler matched the option name. If any handler returns "false", it will stop the parsing of further options. The long and short options are equivalent – both are expected to be introduced by one or more dashes on the command line. Short options can't be chained (e.g. "-hs") in the present implementation. The option argument can be given with or without the equation sign.