#include <src/core/CommandLine.h>
Public Member Functions | |
MultiType | getDefaultValue () const |
Returns the given default value as type T. | |
const std::string & | getInformation () const |
Returns the usage information. | |
const std::string & | getName () const |
Returns the name of the argument. | |
const std::string & | getShortcut () const |
MultiType | getValue () const |
Returns the actual value of the argument. Can be equal to default value. | |
bool | hasDefaultValue () const |
Tells whether the value has been changed by the command line. | |
CommandLineArgument & | information (const std::string &usage) |
Sets the option information when displaying orxonox usage. | |
CommandLineArgument & | shortcut (const std::string &shortcut) |
Sets the shortcut for the argument. | |
Private Member Functions | |
CommandLineArgument (const CommandLineArgument &instance) | |
Undefined copy constructor. | |
CommandLineArgument (const std::string &name, const MultiType &defaultValue, bool bCommandLineOnly) | |
Constructor initialises both value_ and defaultValue_ with defaultValue. | |
void | parse (const std::string &value, bool bParsingFile) |
Parses the value string of a command line argument. | |
~CommandLineArgument () | |
Private Attributes | |
bool | bCommandLineOnly_ |
Whether you cannot specify the value in a text file. | |
bool | bHasDefaultValue_ |
Tells whether the value has been changed by the command line. | |
MultiType | defaultValue_ |
Default value. Should not be changed. | |
std::string | name_ |
Name of the argument. | |
std::string | shortcut_ |
Shortcut of the argument. | |
std::string | usageInformation_ |
Tells about the usage of this parameter. | |
MultiType | value_ |
The actual value. | |
Friends | |
class | CommandLine |
Whenever you want to have an option specified by a command line switch, you need to first define it with SetCommandLineArgument(name, defaultValue). It is then added to a map and possibly changed when the command line is being parsed. If the option was not given, you can detect this by asking hasDefaultValue().
There is a possibility to define a short cut so you can write "-p 20" instead of "--port 20". Note the difference between "-" and "--"! Also, there is no restriction to the number of strings you add after --name. So "--startVector (2, 4, 5)" is perfectly legal.
Retrieving an argument is possible with the getCommandLineArgument function of the CommandLine class. It is a Singleton, but the public interface is static.
orxonox::CommandLineArgument::CommandLineArgument | ( | const std::string & | name, | |
const MultiType & | defaultValue, | |||
bool | bCommandLineOnly | |||
) | [inline, private] |
Constructor initialises both value_ and defaultValue_ with defaultValue.
orxonox::CommandLineArgument::CommandLineArgument | ( | const CommandLineArgument & | instance | ) | [private] |
Undefined copy constructor.
orxonox::CommandLineArgument::~CommandLineArgument | ( | ) | [inline, private] |
MultiType orxonox::CommandLineArgument::getDefaultValue | ( | ) | const [inline] |
Returns the given default value as type T.
const std::string& orxonox::CommandLineArgument::getInformation | ( | ) | const [inline] |
Returns the usage information.
const std::string& orxonox::CommandLineArgument::getName | ( | ) | const [inline] |
const std::string& orxonox::CommandLineArgument::getShortcut | ( | ) | const [inline] |
Returns the shortcut (example: "-p 22" for "--port 22") of the argument. Evaluates to "" if there is none.
MultiType orxonox::CommandLineArgument::getValue | ( | ) | const [inline] |
Returns the actual value of the argument. Can be equal to default value.
bool orxonox::CommandLineArgument::hasDefaultValue | ( | ) | const [inline] |
Tells whether the value has been changed by the command line.
CommandLineArgument& orxonox::CommandLineArgument::information | ( | const std::string & | usage | ) | [inline] |
Sets the option information when displaying orxonox usage.
void orxonox::CommandLineArgument::parse | ( | const std::string & | value, | |
bool | bParsingFile | |||
) | [private] |
Parses the value string of a command line argument.
Parses a value string for a command line argument. It simply uses convertValue(Output, Input) to do that. Bools are treated specially. That is necessary so that you can have simple command line switches.
References bCommandLineOnly_, bHasDefaultValue_, orxonox::MT_Type::Bool, orxonox::convertValue(), defaultValue_, getName(), orxonox::MultiType::getType(), orxonox::MultiType::setValue(), ThrowException, and value_.
CommandLineArgument& orxonox::CommandLineArgument::shortcut | ( | const std::string & | shortcut | ) | [inline] |
Sets the shortcut for the argument.
friend class CommandLine [friend] |
bool orxonox::CommandLineArgument::bCommandLineOnly_ [private] |
bool orxonox::CommandLineArgument::bHasDefaultValue_ [private] |
Name of the argument.
Tells about the usage of this parameter.