orxonox::CommandLineArgument Class Reference

Container class for a command line argument of any type supported by MultiType. More...

#include <src/core/CommandLine.h>

List of all members.

Public Member Functions

MultiType getDefaultValue () const
 Returns the given default value as type T.
const std::stringgetInformation () const
 Returns the usage information.
const std::stringgetName () const
 Returns the name of the argument.
const std::stringgetShortcut () 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.
CommandLineArgumentinformation (const std::string &usage)
 Sets the option information when displaying orxonox usage.
CommandLineArgumentshortcut (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


Detailed Description

Container class for a command line argument of any type supported by MultiType.

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.


Constructor & Destructor Documentation

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]


Member Function Documentation

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]

Returns the name of the argument.

Referenced by parse().

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.


Friends And Related Function Documentation

friend class CommandLine [friend]


Member Data Documentation

Whether you cannot specify the value in a text file.

Referenced by parse().

Tells whether the value has been changed by the command line.

Referenced by parse().

Default value. Should not be changed.

Referenced by parse().

Name of the argument.

Shortcut of the argument.

See also:
getShortcut().

Tells about the usage of this parameter.

The actual value.

Referenced by parse().


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

Generated on Tue Jul 28 16:22:24 2009 for Orxonox by  doxygen 1.5.6