Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
OptionsParser Class Reference

Parses command line arguments. More...

#include <OptionsParser.h>

Static Public Member Functions

static bool parse (const std::vector< std::string > &args, const bool ignoreAppenders=false)
 Parses the given command line arguments.
 

Static Private Member Functions

static int check (const std::string &arg1, const std::string *const arg2, bool &ok, const bool ignoreAppenders)
 parses the previous arguments
 
static bool checkParameter (const std::string &arg1)
 Returns the whether the given token is an option.
 
static bool processNonBooleanSingleSwitch (OptionsCont &oc, const std::string &arg, const bool append)
 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 46 of file OptionsParser.h.

Member Function Documentation

◆ check()

int OptionsParser::check ( const std::string &  arg1,
const std::string *const  arg2,
bool &  ok,
const bool  ignoreAppenders 
)
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(), OptionsCont::getOptions(), OptionsCont::isBool(), processNonBooleanSingleSwitch(), and OptionsCont::set().

Referenced by parse().

Here is the caller graph for this function:

◆ checkParameter()

bool OptionsParser::checkParameter ( const std::string &  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 '-' or a '+'.

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

Definition at line 144 of file OptionsParser.cpp.

References TL, and WRITE_ERRORF.

Referenced by check().

Here is the caller graph for this function:

◆ parse()

bool OptionsParser::parse ( const std::vector< std::string > &  args,
const bool  ignoreAppenders = false 
)
static

Parses the given command line arguments.

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

Definition at line 37 of file OptionsParser.cpp.

References check(), and WRITE_ERROR.

Referenced by OptionsIO::getOptions(), and OptionsIO::loadConfiguration().

Here is the caller graph for this function:

◆ processNonBooleanSingleSwitch()

bool OptionsParser::processNonBooleanSingleSwitch ( OptionsCont oc,
const std::string &  arg,
const bool  append 
)
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 124 of file OptionsParser.cpp.

References OptionsCont::set(), TL, and WRITE_ERRORF.

Referenced by check().

Here is the caller graph for this function:

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