Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
orxonox::CommandLineParser Class Reference

Global interface to command line options. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/commandline/CommandLineParser.h>

Inheritance diagram for orxonox::CommandLineParser:
orxonox::Singleton< CommandLineParser >

Public Member Functions

 CommandLineParser ()
 Constructor initialises bFirstTimeParse_ with true. More...
 
 ~CommandLineParser ()
 Destructor destroys all CommandLineArguments with it. More...
 

Static Public Member Functions

static void addArgument (CommandLineArgument *argument)
 Adds a new CommandLineArgument to the internal map. More...
 
static bool existsArgument (const std::string &name)
 
static void generateDoc (std::ofstream &file)
 
static const CommandLineArgumentgetArgument (const std::string &name)
 Retrieves a CommandLineArgument. More...
 
static std::string getUsageInformation ()
 
template<class T >
static void getValue (const std::string &name, T *value)
 Writes the argument value in the given parameter. More...
 
static const MultiTypegetValue (const std::string &name)
 
static void parse (const std::string &cmdLine)
 Parse redirection to internal member method. More...
 
static void removeArgument (CommandLineArgument *argument)
 Removes a CommandLineArgument from the internal map. More...
 
- Static Public Member Functions inherited from orxonox::Singleton< CommandLineParser >
static bool exists ()
 Tells whether the singleton has been created. More...
 
static CommandLineParsergetInstance ()
 Returns a reference to the singleton instance. More...
 

Private Member Functions

 CommandLineParser (const CommandLineParser &instance)
 Undefined copy constructor. More...
 
void _parse (const std::string &cmdLine)
 Parses the command line string for arguments and stores these. More...
 
void checkFullArgument (const std::string &name, const std::string &value)
 Parses an argument based on its full name. More...
 
void checkShortcut (const std::string &shortcut, const std::string &value)
 Parses an argument based on its shortcut. More...
 

Private Attributes

bool bFirstTimeParse_
 Tells whether we parsed for the first time. More...
 
std::map< std::string, CommandLineArgument * > cmdLineArgs_
 Holds all pointers to the arguments and serves as a search map by name. More...
 
std::map< std::string, CommandLineArgument * > cmdLineArgsShortcut_
 Search map by shortcut for the arguments. More...
 

Static Private Attributes

static CommandLineParsersingletonPtr_s = nullptr
 

Friends

class Singleton< CommandLineParser >
 

Additional Inherited Members

- Protected Member Functions inherited from orxonox::Singleton< CommandLineParser >
 Singleton ()
 Constructor sets the singleton instance pointer. More...
 
virtual ~Singleton ()
 Destructor resets the singleton instance pointer. More...
 

Detailed Description

Global interface to command line options.

Allows to add and retrieve command line arguments. Also does the parsing.

Note
Internally it is a Singleton, but the public interface is static.
See also
CommandLineArgument

Constructor & Destructor Documentation

orxonox::CommandLineParser::CommandLineParser ( )
inline

Constructor initialises bFirstTimeParse_ with true.

orxonox::CommandLineParser::~CommandLineParser ( )

Destructor destroys all CommandLineArguments with it.

orxonox::CommandLineParser::CommandLineParser ( const CommandLineParser instance)
private

Undefined copy constructor.

Member Function Documentation

void orxonox::CommandLineParser::_parse ( const std::string &  cmdLine)
private

Parses the command line string for arguments and stores these.

Note
The reason that you have to provide the string to be parsed as space separated list is because of argc and argv. If you only have a whole string, simply use getAllStrings() of SubString.
Parameters
cmdLineCommand line string WITHOUT the execution path.
void orxonox::CommandLineParser::addArgument ( CommandLineArgument argument)
static

Adds a new CommandLineArgument to the internal map.

Note that only such arguments are actually valid.

void orxonox::CommandLineParser::checkFullArgument ( const std::string &  name,
const std::string &  value 
)
private

Parses an argument based on its full name.

Parameters
nameFull name of the argument
valueString containing the value
void orxonox::CommandLineParser::checkShortcut ( const std::string &  shortcut,
const std::string &  value 
)
private

Parses an argument based on its shortcut.

Parameters
shortcutShortcut to the argument
valueString containing the value
static bool orxonox::CommandLineParser::existsArgument ( const std::string &  name)
inlinestatic
void orxonox::CommandLineParser::generateDoc ( std::ofstream &  file)
static
const CommandLineArgument * orxonox::CommandLineParser::getArgument ( const std::string &  name)
static

Retrieves a CommandLineArgument.

The method throws an exception if 'name' was not found or the value could not be converted.

Note
You should of course not call this method before the command line has been parsed.
std::string orxonox::CommandLineParser::getUsageInformation ( )
static
template<class T >
static void orxonox::CommandLineParser::getValue ( const std::string &  name,
T *  value 
)
inlinestatic

Writes the argument value in the given parameter.

static const MultiType& orxonox::CommandLineParser::getValue ( const std::string &  name)
inlinestatic
static void orxonox::CommandLineParser::parse ( const std::string &  cmdLine)
inlinestatic

Parse redirection to internal member method.

void orxonox::CommandLineParser::removeArgument ( CommandLineArgument argument)
static

Removes a CommandLineArgument from the internal map.

Friends And Related Function Documentation

friend class Singleton< CommandLineParser >
friend

Member Data Documentation

bool orxonox::CommandLineParser::bFirstTimeParse_
private

Tells whether we parsed for the first time.

The CommmandLineArguments are added before main(). So when we call parse() the first time, we need to create a map with all shortcuts since these get added after addCommandLineArgument().

std::map<std::string, CommandLineArgument*> orxonox::CommandLineParser::cmdLineArgs_
private

Holds all pointers to the arguments and serves as a search map by name.

std::map<std::string, CommandLineArgument*> orxonox::CommandLineParser::cmdLineArgsShortcut_
private

Search map by shortcut for the arguments.

CommandLineParser * orxonox::CommandLineParser::singletonPtr_s = nullptr
staticprivate

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