SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OptionsParser Class Reference

Parses command line arguments. More...

#include <OptionsParser.h>

Static Public Member Functions

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

Static Private Member Functions

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

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 56 of file OptionsParser.h.

Member Function Documentation

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 78 of file OptionsParser.cpp.

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

Referenced by parse().

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 155 of file OptionsParser.cpp.

References WRITE_ERROR.

Referenced by check().

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 171 of file OptionsParser.cpp.

Referenced by check(), and processNonBooleanSingleSwitch().

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 178 of file OptionsParser.cpp.

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 165 of file OptionsParser.cpp.

Referenced by check().

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 50 of file OptionsParser.cpp.

References check(), and WRITE_ERROR.

Referenced by OptionsIO::getOptions().

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