Orxonox: orxonox::CommandLine Class Reference

# orxonox::CommandLine Class Reference

Global interface to command line options. Allows to add and retrieve command line arguments. Also does the parsing. More...

`#include <src/core/CommandLine.h>`

List of all members.

## Static Public Member Functions

template<class T>
static CommandLineArgument & | addArgument (const std::string &name, T defaultValue, bool bCommandLineOnly)
| Adds a new CommandLineArgument to the internal map. Note that only such arguments are actually valid.
static void | destroyAllArguments ()
| Destroys all command line arguments. This should be called at the end of main. Do not use before that.
static bool | existsArgument (const std::string &name)
static const CommandLineArgument * | getArgument (const std::string &name)
| Retrieves a CommandLineArgument. The method throws an exception if 'name' was not found or the value could not be converted.
static std::string | getUsageInformation ()
static MultiType | getValue (const std::string &name)
template<class T>
static void | getValue (const std::string &name, T *value)
| Writes the argument value in the given parameter.
static void | parseCommandLine (int argc, char **argv)
| Parse redirection to internal member method.
static void | parseFile ()

## Private Member Functions

void | _parse (const std::vector< std::string > &arguments, bool bParsingFile)
| Reads the command line parses the values of each argument. It is then stored in the corresponding CommandLineArgument.
void | _parseCommandLine (int argc, char **argv)
| Parses only the command line for CommandLineArguments.
void | _parseFile ()
| Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
void | checkFullArgument (const std::string &name, const std::string &value, bool bParsingFile)
| Parses an argument based on its full name.
void | checkShortcut (const std::string &shortcut, const std::string &value, bool bParsingFile)
| Parses an argument based on its shortcut.
| CommandLine (const CommandLine &instance)
| Undefined copy constructor.
| CommandLine ()
| Constructor initialises bFirstTimeParse_ with true.
| ~CommandLine ()
| Destructor destroys all CommandLineArguments with it.

## Static Private Member Functions

static CommandLine & | _getInstance ()
| Returns a unique instance (Meyers Singleton).

## Private Attributes

bool | bFirstTimeParse_
std::map< std::string, CommandLineArgument * > | cmdLineArgs_
| Holds all pointers to the arguments and serves as a search map by name.
std::map< std::string, CommandLineArgument * > | cmdLineArgsShortcut_
| Search map by shortcut for the arguments.

## 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::CommandLine::CommandLine | ( |  | ) | `[inline, private]`

Constructor initialises bFirstTimeParse_ with true.

orxonox::CommandLine::CommandLine | ( | const CommandLine & | instance | ) | `[private]`

Undefined copy constructor.

orxonox::CommandLine::~CommandLine | ( |  | ) | `[private]`

Destructor destroys all CommandLineArguments with it.

References destroyAllArguments().

## Member Function Documentation

CommandLine & orxonox::CommandLine::_getInstance | ( |  | ) | `[static, private]`

Returns a unique instance (Meyers Singleton).

Referenced by addArgument(), destroyAllArguments(), getArgument(), and getUsageInformation().

void orxonox::CommandLine::_parse | ( | const std::vector< std::string > & | arguments,
|  | bool | bParsingFile |
| ) |  |  | `[private]`

Reads the command line parses the values of each argument. It is then stored in the corresponding CommandLineArgument.

Note:
  The reason that you have to provide the string to be parsed as space separted list is because of argc and argv. If you only have a whole string, simply use getAllStrings() of SubString.

Parameters:

  | arguments | Vector of space separated strings.

References bFirstTimeParse_, checkFullArgument(), checkShortcut(), cmdLineArgs_, cmdLineArgsShortcut_, COUT, getUsageInformation(), OrxAssert, orxonox::removeTrailingWhitespaces(), and ThrowException.

Referenced by _parseCommandLine(), and _parseFile().

void orxonox::CommandLine::_parseCommandLine | ( | int | argc,
|  | char ** | argv |
| ) |  |  | `[private]`

Parses only the command line for CommandLineArguments.

References _parse().

void orxonox::CommandLine::_parseFile | ( |  | ) | `[private]`

Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.

References _parse(), orxonox::Core::getConfigPath(), getValue(), orxonox::removeTrailingWhitespaces(), and orxonox::SubString::size().

template<class T>

CommandLineArgument & orxonox::CommandLine::addArgument | ( | const std::string & | name,
|  | T | defaultValue,
|  | bool | bCommandLineOnly |
| ) |  |  | `[inline, static]`

Adds a new CommandLineArgument to the internal map. Note that only such arguments are actually valid.

Parameters:

  | name | Name of the argument. Shortcut can be added later.
  | defaultValue | Default value that is used when argument was not given.

References _getInstance(), orxonox::MT_Type::Bool, cmdLineArgs_, existsArgument(), and OrxAssert.

void orxonox::CommandLine::checkFullArgument | ( | const std::string & | name,
|  | const std::string & | value,
|  | bool | bParsingFile |
| ) |  |  | `[private]`

Parses an argument based on its full name.

Parameters:

  | name | Full name of the argument
  | value | String containing the value

References cmdLineArgs_, and ThrowException.

Referenced by _parse().

void orxonox::CommandLine::checkShortcut | ( | const std::string & | shortcut,
|  | const std::string & | value,
|  | bool | bParsingFile |
| ) |  |  | `[private]`

Parses an argument based on its shortcut.

Parameters:

  | shortcut | Shotcut to the argument
  | value | String containing the value

References cmdLineArgsShortcut_, and ThrowException.

Referenced by _parse().

void orxonox::CommandLine::destroyAllArguments | ( |  | ) | `[static]`

Destroys all command line arguments. This should be called at the end of main. Do not use before that.

References _getInstance(), and cmdLineArgs_.

Referenced by ~CommandLine(), and orxonox::Core::~Core().

static bool orxonox::CommandLine::existsArgument | ( | const std::string & | name | ) | `[inline, static]`

Referenced by addArgument().

const CommandLineArgument * orxonox::CommandLine::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 shold of course not call this method before the command line has been parsed.

References _getInstance(), cmdLineArgs_, and ThrowException.

Referenced by orxonox::Core::checkDevBuild(), and orxonox::CoreConfiguration::initialise().

std::string orxonox::CommandLine::getUsageInformation | ( |  | ) | `[static]`

References _getInstance(), orxonox::MT_Type::Bool, and cmdLineArgs_.

Referenced by _parse().

static MultiType orxonox::CommandLine::getValue | ( | const std::string & | name | ) | `[inline, static]`

template<class T>

static void orxonox::CommandLine::getValue | ( | const std::string & | name,
|  | T * | value |
| ) |  |  | `[inline, static]`

Writes the argument value in the given parameter.

References orxonox::KeyCode::T.

Referenced by _parseFile(), orxonox::GSRoot::activate(), orxonox::GSDedicated::activate(), orxonox::GSClient::activate(), orxonox::Core::checkDevBuild(), orxonox::Core::Core(), orxonox::InputManager::initialise(), and orxonox::CoreConfiguration::initialise().

static void orxonox::CommandLine::parseCommandLine | ( | int | argc,
|  | char ** | argv |
| ) |  |  | `[inline, static]`

Parse redirection to internal member method.

Referenced by orxonox::Core::Core().

static void orxonox::CommandLine::parseFile | ( |  | ) | `[inline, static]`

Referenced by orxonox::Core::Core().

## Member Data Documentation

bool orxonox::CommandLine::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().

Referenced by _parse().

std::map<std::string, CommandLineArgument*> orxonox::CommandLine::cmdLineArgs_`[private]`

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

Referenced by _parse(), addArgument(), checkFullArgument(), destroyAllArguments(), getArgument(), and getUsageInformation().

std::map<std::string, CommandLineArgument*> orxonox::CommandLine::cmdLineArgsShortcut_`[private]`

Search map by shortcut for the arguments.

Referenced by _parse(), and checkShortcut().

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

- src/core/CommandLine.h
- src/core/CommandLine.cc