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

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

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

Public Member Functions

 CommandLineArgument (const std::string &name, const MultiType &defaultValue)
 Constructor initialises both value_ and defaultValue_ with defaultValue. More...
 
 ~CommandLineArgument ()
 
const MultiTypegetDefaultValue () const
 Returns the given default value as type T. More...
 
const std::string & getInformation () const
 Returns the usage information. More...
 
const std::string & getName () const
 Returns the name of the argument. More...
 
const std::string & getShortcut () const
 Returns the shortcut (example: "-p 22" for "--port 22") of the argument. More...
 
const MultiTypegetValue () const
 Returns the actual value of the argument. Can be equal to default value. More...
 
bool hasDefaultValue () const
 Tells whether the value has been changed by the command line. More...
 
CommandLineArgumentinformation (const std::string &usage)
 Sets the option information when displaying orxonox usage. More...
 
CommandLineArgumentshortcut (const std::string &shortcut)
 Sets the shortcut for the argument. More...
 

Private Member Functions

 CommandLineArgument (const CommandLineArgument &)=delete
 
CommandLineArgumentoperator= (const CommandLineArgument &)=delete
 
void parse (const std::string &value)
 Parses the value string of a command line argument. More...
 

Private Attributes

bool bHasDefaultValue_
 Tells whether the value has been changed by the command line. More...
 
MultiType defaultValue_
 Default value. Should not be changed. More...
 
std::string name_
 Name of the argument. More...
 
std::string shortcut_
 Shortcut of the argument. More...
 
std::string usageInformation_
 Tells about the usage of this parameter. More...
 
MultiType value_
 The actual value. More...
 

Friends

class CommandLineParser
 

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 CommandLineParser class. It is a Singleton, but the public interface is static.

Constructor & Destructor Documentation

orxonox::CommandLineArgument::CommandLineArgument ( const std::string &  name,
const MultiType defaultValue 
)
inline

Constructor initialises both value_ and defaultValue_ with defaultValue.

orxonox::CommandLineArgument::~CommandLineArgument ( )
inline
orxonox::CommandLineArgument::CommandLineArgument ( const CommandLineArgument )
privatedelete

Member Function Documentation

const 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 ( void  ) const
inline

Returns the name of the argument.

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.

const 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.

CommandLineArgument& orxonox::CommandLineArgument::operator= ( const CommandLineArgument )
privatedelete
void orxonox::CommandLineArgument::parse ( const std::string &  value)
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.

CommandLineArgument& orxonox::CommandLineArgument::shortcut ( const std::string &  shortcut)
inline

Sets the shortcut for the argument.

Friends And Related Function Documentation

friend class CommandLineParser
friend

Member Data Documentation

bool orxonox::CommandLineArgument::bHasDefaultValue_
private

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

MultiType orxonox::CommandLineArgument::defaultValue_
private

Default value. Should not be changed.

std::string orxonox::CommandLineArgument::name_
private

Name of the argument.

std::string orxonox::CommandLineArgument::shortcut_
private

Shortcut of the argument.

See also
getShortcut().
std::string orxonox::CommandLineArgument::usageInformation_
private

Tells about the usage of this parameter.

MultiType orxonox::CommandLineArgument::value_
private

The actual value.


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