Eclipse SUMO - Simulation of Urban MObility
OptionsParser Class Reference

Parses command line arguments. More...

#include <OptionsParser.h>

Collaboration diagram for OptionsParser:

Static Public Member Functions

static bool parse (int argc, char **argv)
 Parses the given command line arguments. More...
 

Static Private Member Functions

static int check (const char *arg1, const char *arg2, bool &ok)
 parses the previous arguments More...
 
static bool checkParameter (const char *arg1)
 Returns the whether the given token is an option. More...
 
static std::string convert (char abbr)
 converts char to string More...
 
static std::string convert (const char *arg)
 Converts char* to string. More...
 
static bool isAbbreviation (const char *arg1)
 returns the whether the given token is an abbreviation More...
 
static bool processNonBooleanSingleSwitch (OptionsCont &oc, const char *arg)
 Extracts the parameter directly attached to an option. More...
 

Detailed Description

Parses command line arguments.

The only public method parses the given list of arguments. It returns false when something failed. This may happen if the syntax of the arguments is invalid, a value is tried to be set several times or an unknown option is tried to be set.

The class assumes all options are unset or using default values only.

Definition at line 48 of file OptionsParser.h.

Member Function Documentation

◆ check()

int OptionsParser::check ( const char *  arg1,
const char *  arg2,
bool &  ok 
)
staticprivate

parses the previous arguments

Parameters
[in]arg1The first token to parse
[in]arg2The second token to parse, 0 if there is none
[in,out]okWhether the parsing was successfull
Returns
Number of read tokens (1 or 2)
Exceptions
InvalidArgumentIf a performed setting of an option failed (see Option::set)

Definition at line 61 of file OptionsParser.cpp.

References checkParameter(), convert(), OptionsCont::getOptions(), isAbbreviation(), OptionsCont::isBool(), processNonBooleanSingleSwitch(), and OptionsCont::set().

Referenced by parse().

◆ checkParameter()

bool OptionsParser::checkParameter ( const char *  arg1)
staticprivate

Returns the whether the given token is an option.

The given token is assumed to be an option if it starts with a '-'.

Parameters
[in]arg1The token to check
Returns
Whether the token is an option

Definition at line 138 of file OptionsParser.cpp.

References WRITE_ERROR.

Referenced by check().

◆ convert() [1/2]

std::string OptionsParser::convert ( char  abbr)
staticprivate

converts char to string

Parameters
[in]abbrThe char to convert
Returns
The char converted into a std::string

Definition at line 161 of file OptionsParser.cpp.

◆ convert() [2/2]

std::string OptionsParser::convert ( const char *  arg)
staticprivate

Converts char* to string.

Parameters
[in]argThe c-string to convert
Returns
The string converted into a std::string

Definition at line 154 of file OptionsParser.cpp.

Referenced by check(), and processNonBooleanSingleSwitch().

◆ isAbbreviation()

bool OptionsParser::isAbbreviation ( const char *  arg1)
staticprivate

returns the whether the given token is an abbreviation

The given token is assumed to be an option if it starts with two '-'.

Parameters
[in]arg1The token to check
Returns
Whether the token is an abbreviation

Definition at line 148 of file OptionsParser.cpp.

Referenced by check().

◆ parse()

bool OptionsParser::parse ( int  argc,
char **  argv 
)
static

Parses the given command line arguments.

Parameters
[in]ocThe options container to fill
[in]argcThe number of given command line arguments
[in]argvThe command line arguments
Returns
Whether the parsing was successfull
Exceptions
InvalidArgumentIf a performed setting of an option failed (see Option::set)

Definition at line 38 of file OptionsParser.cpp.

References check(), and WRITE_ERROR.

Referenced by OptionsIO::getOptions().

◆ processNonBooleanSingleSwitch()

bool OptionsParser::processNonBooleanSingleSwitch ( OptionsCont oc,
const char *  arg 
)
staticprivate

Extracts the parameter directly attached to an option.

Parses single tokens which contain an option and the parameter (like -c=myconfig.cfg)

Parameters
[in]ocThe container to store the result into
[in]argThe token to parse
Exceptions
InvalidArgumentIf a performed setting of an option failed (see Option::set)

Definition at line 118 of file OptionsParser.cpp.

References convert(), OptionsCont::set(), and WRITE_ERROR.

Referenced by check().


The documentation for this class was generated from the following files: