#include <CommandLineParser.h>
Class implementing a simple command line parser Command line parser (heavily) adapted from http://stackoverflow.com/questions/865668/ddg#868894 credit to iain.
◆ CommandLineParser()
CommandLineParser::CommandLineParser |
( |
int & |
argc, |
|
|
char ** |
argv, |
|
|
const std::map< std::string, CommandLineOption > & |
allowedCommandLineOptionsIn |
|
) |
| |
Constructor. Saves each item of the command line in the tokens member variable and the executable name in executableName
- Parameters
-
argc | Number of input arguments. |
argv | Pointer ot character arrays. |
allowedCommandLineOptionsIn | A map with all allowed command line options. Keys are the flags, each value is a CommandLineOption. |
◆ cmdOptionExists()
bool CommandLineParser::cmdOptionExists |
( |
const std::string & |
option | ) |
const |
Check if an option exists at all. Typically used for simple switches.
- Parameters
-
option | String containing the sought option. |
◆ getAllReqreuiredParametersSet()
bool CommandLineParser::getAllReqreuiredParametersSet |
( |
| ) |
const |
|
inline |
Returs true if all required parameters were set in the command line, false otherwise.
◆ getCmdOptionAsFloat()
const float CommandLineParser::getCmdOptionAsFloat |
( |
const std::string & |
option, |
|
|
int |
skip = 0 |
|
) |
| const |
Get an option associated with a certain flag as a float. For an example see getCmdOptionAsString.
- Parameters
-
option | String with the flag that is sought. |
skip | Defines how many tokens to skip after flag before selecting return value. |
- Returns
- Integer with the specified option. Will exit if option does not exist as conversion is undefined in this case.
◆ getCmdOptionAsInt()
const int CommandLineParser::getCmdOptionAsInt |
( |
const std::string & |
option, |
|
|
int |
skip = 0 |
|
) |
| const |
Get an option associated with a certain flag as an integer. For an example see getCmdOptionAsString.
- Parameters
-
option | String with the flag that is sought. |
skip | Defines how many tokens to skip after flag before selecting return value. |
- Returns
- Integer with the specified option. Will exit if option does not exist as conversion is undefined in this case.
◆ getCmdOptionAsString()
const std::string & CommandLineParser::getCmdOptionAsString |
( |
const std::string & |
option, |
|
|
int |
skip = 0 |
|
) |
| const |
Get an option associated with a certain flag.
Example
If the application was called like
application.exe -f fileName.nii.gz -dynamic 150 textFile.txt
then
CommandLineParser.getCmdOption("-f")
returns "fileName.nii.gz", and
CommandLineParser.getCmdOption("-dynamic", 0)
returns "150", and
CommandLineParser.getCmdOption("-dynamic", 1)
returns "textFile.txt",
- Parameters
-
option | String with the flag that is sought. |
skip | Defines how many tokens to skip after flag before selecting return value. |
- Returns
- String with the specified option. Will be empty if option does not exist.
◆ getCommandLine()
std::string CommandLineParser::getCommandLine |
( |
| ) |
const |
Returns the complete (reconstructed) command line.
- Returns
- String containing executable name and command line tokens.
◆ allRequiredParametersSet
bool CommandLineParser::allRequiredParametersSet |
|
private |
◆ executableName
std::string CommandLineParser::executableName |
|
private |
The executable name contained on the command line.
◆ tokens
std::vector<std::string> CommandLineParser::tokens |
|
private |
Vector with individual command line entries.
The documentation for this class was generated from the following files: