SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Option Class Reference

A class representing a single program option. More...

#include <Option.h>

Inheritance diagram for Option:
Option_Bool Option_Float Option_Integer Option_IntVector Option_String Option_FileName

Public Member Functions

virtual bool getBool () const
 Returns the stored boolean value.
const std::string & getDescription () const
 Returns the description of what this option does.
virtual SUMOReal getFloat () const
 Returns the stored SUMOReal value.
virtual int getInt () const
 Returns the stored integer value.
virtual const IntVectorgetIntVector () const
 Returns the stored integer vector.
virtual std::string getString () const
 Returns the stored string value.
virtual const std::string & getTypeName () const
 Returns the mml-type name of this option.
virtual std::string getValueString () const =0
 Returns the string-representation of the value.
virtual bool isBool () const
 Returns the information whether the option is a bool option.
virtual bool isDefault () const
 Returns the information whether the option holds the default value.
virtual bool isFileName () const
 Returns the information whether this option is a file name.
bool isSet () const
 returns the information whether this options holds a valid value
bool isWriteable () const
 Returns the information whether the option may be set a further time.
void resetWritable ()
 Resets the option to be writeable.
virtual bool set (const std::string &v)=0
 Stores the given value (used for non-bool options)
void setDescription (const std::string &desc)
 Sets the description of what this option does.
void unSet ()
 marks this option as unset
virtual ~Option ()

Protected Member Functions

bool markSet ()
 Marks the information as set.
virtual Optionoperator= (const Option &s)
 Assignment operator.
 Option (bool set=false)
 Constructor.
 Option (const Option &s)
 Copy constructor.

Protected Attributes

std::string myTypeName
 A type name for this option (has presets, but may be overwritten)

Private Attributes

bool myAmSet
 information whether the value is set
bool myAmWritable
 information whether the value may be changed
std::string myDescription
 The description what this option does.
bool myHaveTheDefaultValue
 information whether the value is the default value (is then set)

Detailed Description

A class representing a single program option.

The base class for a single program option. All options which hold values are derived from this class as the type of stored values may differ.

Most of the getter-methods throw exceptions because this base class is not meant to hold any values by itself. Instead, the derived classes implement the appropriate method (Option_Integer implements getInt, f.e.). So, when one tries to retrieve a value which is not of the type of the option, an exception will be thrown. This behaviour is meant to be valid, because errors like this one only occur when building and testing the application.

Due to described behaviour, this class has no public constructors. Only construction of derived, value and type holding, classes is allowed.

At the begin (after being constructed) an Option either has a default value or not. In dependance to this, myHaveTheDefaultValue is set. Also, myAmSet is set to true if a default value was supported. myAmWritable is set to true, indicating that a new value may be set.

Each option may have a description about its purpose stored. Furthermore, it stores a man-readable type name for this option.

Definition at line 79 of file Option.h.

Constructor & Destructor Documentation

Option::~Option ( )
virtual

destructor

Definition at line 63 of file Option.cpp.

Option::Option ( bool  set = false)
protected

Constructor.

This constructor should be used by derived classes. The boolean value indicates whether a default value was supplied or not.

Parameters
[in]setA default value was supplied

Definition at line 54 of file Option.cpp.

Option::Option ( const Option s)
protected

Copy constructor.

Definition at line 58 of file Option.cpp.

Member Function Documentation

bool Option::getBool ( ) const
virtual

Returns the stored boolean value.

Option_Bool returns the stored boolean in this method's reimplementation. All other option classes do not override this method which throws an InvalidArgument-exception.

Returns
Returns the stored boolean if being an instance of Option_Bool
Exceptions
InvalidArgumentIf the class is not an instance of Option_Bool

Reimplemented in Option_Bool.

Definition at line 103 of file Option.cpp.

Referenced by OptionsCont::getBool().

const std::string & Option::getDescription ( ) const

Returns the description of what this option does.

The description stored in myDescription is returned.

Returns
The description of this option's purpose

Definition at line 162 of file Option.cpp.

References myDescription.

Referenced by OptionsCont::printHelp(), and OptionsCont::writeConfiguration().

SUMOReal Option::getFloat ( ) const
virtual

Returns the stored SUMOReal value.

Option_Float returns the stored real number in this method's reimplementation. All other option classes do not override this method which throws an InvalidArgument-exception.

Returns
Returns the stored real number if being an instance of Option_Float
Exceptions
InvalidArgumentIf the class is not an instance of Option_Float

Reimplemented in Option_Float.

Definition at line 85 of file Option.cpp.

Referenced by OptionsCont::getFloat().

int Option::getInt ( ) const
virtual

Returns the stored integer value.

Option_Integer returns the stored integer number in this method's reimplementation. All other option classesdo not override this method which throws an InvalidArgument-exception.

Returns
Returns the stored integer number if being an instance of Option_Integer
Exceptions
InvalidArgumentIf the class is not an instance of Option_Integer

Reimplemented in Option_Integer.

Definition at line 91 of file Option.cpp.

Referenced by OptionsCont::getInt().

const IntVector & Option::getIntVector ( ) const
virtual

Returns the stored integer vector.

Option_IntVector returns the stored integer vector in this method's reimplementation. All other option classes do not override this method which throws an InvalidArgument-exception.

Returns
Returns the stored integer vector if being an instance of Option_IntVector
Exceptions
InvalidArgumentIf the class is not an instance of Option_IntVector

Reimplemented in Option_IntVector.

Definition at line 109 of file Option.cpp.

Referenced by OptionsCont::getIntVector().

std::string Option::getString ( ) const
virtual

Returns the stored string value.

Option_String and Option_FileName return the stored string in this method's reimplementation. All other option classes do not override this method which throws an InvalidArgument-exception.

Returns
Returns the stored string if being an instance of Option_String
Exceptions
InvalidArgumentIf the class is not an instance of Option_String

Reimplemented in Option_String.

Definition at line 97 of file Option.cpp.

Referenced by OptionsCont::getString(), and OptionsCont::getStringVector().

const std::string & Option::getTypeName ( ) const
virtual

Returns the mml-type name of this option.

The type name stored in myTypeName is returned.

Returns
The man-readable type name

Definition at line 174 of file Option.cpp.

References myTypeName.

Referenced by OptionsCont::getTypeName(), OptionsCont::printHelp(), OptionsCont::writeConfiguration(), and OptionsCont::writeSchema().

virtual std::string Option::getValueString ( ) const
pure virtual

Returns the string-representation of the value.

The stored value is encoded into a string and returned.

Returns
The stored value encoded into a string-

Implemented in Option_IntVector, Option_Bool, Option_Float, Option_String, and Option_Integer.

Referenced by OptionsCont::writeConfiguration().

bool Option::isBool ( ) const
virtual

Returns the information whether the option is a bool option.

Returns false. Only Option_Bool overrides this method returning true.

Returns
true if the Option is an Option_Bool, false otherwise

Reimplemented in Option_Bool.

Definition at line 132 of file Option.cpp.

Referenced by OptionsCont::isBool(), and OptionsCont::printHelp().

bool Option::isDefault ( ) const
virtual

Returns the information whether the option holds the default value.

Returns
true if the option was not set from command line / configuration, false otherwise

Definition at line 138 of file Option.cpp.

References myHaveTheDefaultValue.

Referenced by OptionsCont::writeConfiguration().

bool Option::isFileName ( ) const
virtual

Returns the information whether this option is a file name.

Returns false. Only Option_FileName overrides this method returning true.

Returns
true if the Option is an Option_FileName, false otherwise

Reimplemented in Option_FileName.

Definition at line 144 of file Option.cpp.

bool Option::isSet ( ) const

returns the information whether this options holds a valid value

Returns
Whether a value has been set

Definition at line 79 of file Option.cpp.

References myAmSet.

Referenced by OptionsCont::checkDependingSuboptions(), OptionsCont::isUsableFileList(), and OptionsCont::writeConfiguration().

bool Option::isWriteable ( ) const

Returns the information whether the option may be set a further time.

This method returns whether the option was not already set using command line options / configuration. This is done by returning the value of myAmWritable.

Returns
Whether the option may be set from the command line / configuration

Definition at line 150 of file Option.cpp.

References myAmWritable.

Referenced by OptionsCont::isWriteable(), and OptionsCont::set().

bool Option::markSet ( )
protected

Marks the information as set.

Sets the "myAmSet" - information. Returns whether the option was writeable before.

Returns
Whether the option was not set before.

Definition at line 115 of file Option.cpp.

References myAmSet, myAmWritable, and myHaveTheDefaultValue.

Referenced by Option_Integer::set(), Option_String::set(), Option_Float::set(), Option_Bool::set(), and Option_IntVector::set().

Option & Option::operator= ( const Option s)
protectedvirtual

Assignment operator.

Definition at line 67 of file Option.cpp.

References myAmSet, myAmWritable, and myHaveTheDefaultValue.

void Option::resetWritable ( )

Resets the option to be writeable.

An option is writable after initialisation, but as soon as it gets set, it is no longer writeable. This method resets the writable-flag.

Definition at line 156 of file Option.cpp.

References myAmWritable.

virtual bool Option::set ( const std::string &  v)
pure virtual

Stores the given value (used for non-bool options)

This method is overriden by all option classes but Option_Bool. The value is converted into the proper type and stored in "myValue". Then, "markSet" is called in order to know that a value has been set.

The method defined in Option throws an exception, because all derived classes should override it - for Option_Bool, it is tested on a different position whether to use this method or bool set(bool).

The method returns whether the value could be set (the return value from "markSet").

If the string could not be converted into the type, an InvalidArgument is thrown.

Returns
Whether the new value could be set
Exceptions
InvalidArgumentIf being an instance of Option or Option_Bool or if the value could not be converted

Implemented in Option_IntVector, Option_Bool, Option_Float, Option_String, and Option_Integer.

Referenced by OptionsCont::set().

void Option::setDescription ( const std::string &  desc)

Sets the description of what this option does.

The description stored in myDescription is returned.

Returns
The description of this option's purpose

Definition at line 168 of file Option.cpp.

References myDescription.

Referenced by OptionsCont::addDescription().

void Option::unSet ( )

marks this option as unset

Definition at line 125 of file Option.cpp.

References myAmSet, and myAmWritable.

Field Documentation

bool Option::myAmSet
private

information whether the value is set

Definition at line 288 of file Option.h.

Referenced by isSet(), markSet(), operator=(), and unSet().

bool Option::myAmWritable
private

information whether the value may be changed

Definition at line 294 of file Option.h.

Referenced by isWriteable(), markSet(), operator=(), resetWritable(), and unSet().

std::string Option::myDescription
private

The description what this option does.

Definition at line 297 of file Option.h.

Referenced by getDescription(), and setDescription().

bool Option::myHaveTheDefaultValue
private

information whether the value is the default value (is then set)

Definition at line 291 of file Option.h.

Referenced by isDefault(), markSet(), and operator=().

std::string Option::myTypeName
protected

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