navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 5 (modified by landauf, 12 years ago) (diff)

CommandLine and CommandLineArgument


These classes serve as a platform to easily declare command line arguments and retrieve them later. By 'later' the code before orxonox starts is being referred which means that we have to declare the possible arguments even before that. I have decided to do it before main via static variable initialisation.


If you would like to retrieve the value of a command line argument, you will have to declare it first anywhere in the source (the macro creates a dummy variable in order allow for code execution via function).

namespace orxonox
    SetCommandLineArgument(name, defaultValue).setShortcut('char')

'name' is the argument name (without quotation marks) and defaultValue deduces the type.

Retrieving a value

Getting the values is quite easy via the static interface of the CommandLine class. Use getArgument(name) to retrieve the entire argument including the information whether the default value was used or not (i.e. argument given in command line or not). And use getValue(name, *value) to get the value directly.
Be careful with the types. If you declare an argument as (int), you will have to retrieve it with an (int)-type variable. An example:

int myVar;
CommandLine::getValue("port", &myVar);

CommandLineArgument<int>* myArg = CommandLine::getArgument<int>("port);

Passing command line parameters

You can either use full argument names or shortcuts like this:
./orxonox --port 125 or ./orxonox -p 125
Note the difference with "—" and "-". The value after the name or shortcut can be anything that converts to the given type. If the type is boolean and no value is given, it is automatically set to 'true' (so called command line switches).

Usage information

The user can choose to display information on how to use the arguments or display a list. This information is configured via setInformation(string) when declaring a CommandLineArgument.
The standard pattern is [--name information]