SuPReMo  0.1.1
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
CommandLineParser Class Reference

#include <CommandLineParser.h>

Public Member Functions

 CommandLineParser (int &argc, char **argv, const std::map< std::string, CommandLineOption > &allowedCommandLineOptionsIn)
 
const std::string & getCmdOptionAsString (const std::string &option, int skip=0) const
 
const int getCmdOptionAsInt (const std::string &option, int skip=0) const
 
const float getCmdOptionAsFloat (const std::string &option, int skip=0) const
 
bool cmdOptionExists (const std::string &option) const
 
std::string getCommandLine () const
 
bool getAllReqreuiredParametersSet () const
 

Private Attributes

std::vector< std::string > tokens
 Vector with individual command line entries. More...
 
std::string executableName
 The executable name contained on the command line. More...
 
bool allRequiredParametersSet
 Indicates if all required parameters were found. Use the getter funciton getAllReqreuiredParametersSet(). More...
 

Detailed Description

Class implementing a simple command line parser Command line parser (heavily) adapted from http://stackoverflow.com/questions/865668/ddg#868894 credit to iain.

Constructor & Destructor Documentation

◆ 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
argcNumber of input arguments.
argvPointer ot character arrays.
allowedCommandLineOptionsInA map with all allowed command line options. Keys are the flags, each value is a CommandLineOption.

Member Function Documentation

◆ cmdOptionExists()

bool CommandLineParser::cmdOptionExists ( const std::string &  option) const

Check if an option exists at all. Typically used for simple switches.

Parameters
optionString 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
optionString with the flag that is sought.
skipDefines 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
optionString with the flag that is sought.
skipDefines 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
optionString with the flag that is sought.
skipDefines 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.

Member Data Documentation

◆ allRequiredParametersSet

bool CommandLineParser::allRequiredParametersSet
private

Indicates if all required parameters were found. Use the getter funciton getAllReqreuiredParametersSet().

◆ 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: