/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file Option.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Mon, 17 Dec 200118///19// Classes representing a single program option (with different types)20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <vector>26#include <exception>27#include <utils/common/UtilExceptions.h>2829// ===========================================================================30// class definitions31// ===========================================================================3233/**@typedef IntVector34* @brief Definition of a vector of ints35*/36typedef std::vector<int> IntVector;3738/**@typedef StringVector39* @brief Definition of a vector of strings40*/41typedef std::vector<std::string> StringVector;4243#define CLONEABLE(Type) virtual Type* clone() const { return new Type(*this); }4445/* -------------------------------------------------------------------------46* Option47* ----------------------------------------------------------------------- */48/**49* @class Option50* @brief A class representing a single program option51*52* The base class for a single program option. All options which hold values53* are derived from this class as the type of stored values may differ.54*55* Most of the getter-methods throw exceptions because this base class is not meant56* to hold any values by itself. Instead, the derived classes implement the57* appropriate method (Option_Integer implements getInt, f.e.). So, when one58* tries to retrieve a value which is not of the type of the option, an59* exception will be thrown. This behaviour is meant to be valid, because60* errors like this one only occur when building and testing the application.61*62* Due to described behaviour, this class has no public constructors. Only63* construction of derived, value and type holding, classes is allowed.64*65* At the begin (after being constructed) an Option either has a default value or not.66* In dependence to this, myHaveTheDefaultValue is set. Also, myAmSet is set to67* true if a default value was supported. myAmWritable is set to true,68* indicating that a new value may be set.69*70* Each option may have a description about its purpose stored. Furthermore, it71* stores a man-readable type name for this option.72*/73class Option {7475public:76/// @brief destructor77virtual ~Option();7879/** @brief returns the information whether this options holds a valid value80* @return Whether a value has been set81*/82bool isSet() const;8384/** @brief Returns the stored double value85*86* Option_Float returns the stored real number in this method's reimplementation.87* All other option classes do not override this method which throws an InvalidArgument-exception.88*89* @return Returns the stored real number if being an instance of Option_Float90* @exception InvalidArgument If the class is not an instance of Option_Float91*/92virtual double getFloat() const;9394/** @brief Returns the stored integer value95*96* Option_Integer returns the stored integer number in this method's reimplementation.97* All other option classesdo not override this method which throws an InvalidArgument-exception.98*99* @return Returns the stored integer number if being an instance of Option_Integer100* @exception InvalidArgument If the class is not an instance of Option_Integer101*/102virtual int getInt() const;103104/** @brief Returns the stored string value105*106* Option_String returns the stored string in this method's reimplementation.107* Option_FileName's reimplementation is only to be used for single filename string-vector options.108* All other option classes do not override this method which throws an InvalidArgument-exception.109*110* @return Returns the stored string if being an instance of Option_String or Option_FileName111* @exception InvalidArgument If the class is not an instance of Option_String or Option_FileName112*/113virtual std::string getString() const;114115/** @brief Returns the stored boolean value116*117* Option_Bool returns the stored boolean in this method's reimplementation.118* All other option classes do not override this method which throws an InvalidArgument-exception.119*120* @return Returns the stored boolean if being an instance of Option_Bool121* @exception InvalidArgument If the class is not an instance of Option_Bool122*/123virtual bool getBool() const;124125/** @brief Returns the stored integer vector126*127* Option_IntVector returns the stored integer vector in this method's reimplementation.128* All other option classes do not override this method which throws an InvalidArgument-exception.129*130* @return Returns the stored integer vector if being an instance of Option_IntVector131* @exception InvalidArgument If the class is not an instance of Option_IntVector132*/133virtual const IntVector& getIntVector() const;134135/** @brief Returns the stored string vector136*137* Option_StringVector returns the stored string vector in this method's reimplementation.138* All other option classes do not override this method which throws an InvalidArgument-exception.139*140* @return Returns the stored string vector if being an instance of Option_StringVector141* @exception InvalidArgument If the class is not an instance of Option_StringVector142*/143virtual const StringVector& getStringVector() const;144145/** @brief Stores the given value146*147* This method is overriden by all option classes.148* The value is converted into the proper type and stored in "myValue".149* Then, "markSet" is called in order to know that a value has been set.150*151* The method returns whether the value could be set (the return value from152* "markSet").153*154* If the string could not be converted into the type, an InvalidArgument155* is thrown.156*157* @return Whether the new value could be set158* @exception InvalidArgument If the value could not be converted159*/160virtual bool set(const std::string& v, const std::string& orig, const bool append) = 0;161162/** @brief Returns the string-representation of the value163*164* The stored value is encoded into a string and returned.165*166* @return The stored value encoded into a string-167*/168const std::string& getValueString() const;169170/** @brief Returns the information whether the option holds the default value171*172* @return true if the option was not set from command line / configuration, false otherwise173*/174virtual bool isDefault() const;175176/** @brief Returns the information whether the option is a int option177*178* Returns false. Only Option_Integer overrides this method returning true.179*180* @return true if the Option is an Option_Integer, false otherwise181*/182virtual bool isInteger() const;183184/** @brief Returns the information whether the option is a float option185*186* Returns false. Only Option_Float overrides this method returning true.187*188* @return true if the Option is an Option_Float, false otherwise189*/190virtual bool isFloat() const;191192/** @brief Returns the information whether the option is a bool option193*194* Returns false. Only Option_Bool overrides this method returning true.195*196* @return true if the Option is an Option_Bool, false otherwise197*/198virtual bool isBool() const;199200/** @brief Returns the information whether this option is a file name201*202* Returns false. Only Option_FileName overrides this method returning true.203*204* @return true if the Option is an Option_FileName, false otherwise205*/206virtual bool isFileName() const;207208/** @brief Returns the information whether this option is a network file209*210* Returns false. Only Option_Network overrides this method returning true.211*212* @return true if the Option is an Option_Network, false otherwise213*/214virtual bool isNetwork() const;215216/** @brief Returns the information whether this option is an additional file217*218* Returns false. Only Option_Additional overrides this method returning true.219*220* @return true if the Option is an Option_Additional, false otherwise221*/222virtual bool isAdditional() const;223224/** @brief Returns the information whether this option is a route file225*226* Returns false. Only Option_Route overrides this method returning true.227*228* @return true if the Option is an Option_Route, false otherwise229*/230virtual bool isRoute() const;231232/** @brief Returns the information whether this option is a data file233*234* Returns false. Only Option_Data overrides this method returning true.235*236* @return true if the Option is an Option_Data, false otherwise237*/238virtual bool isData() const;239240/** @brief Returns the information whether this option is a sumo config file241*242* Returns false. Only Option_SumoConfig overrides this method returning true.243*244* @return true if the Option is an Option_SumoConfig, false otherwise245*/246virtual bool isSumoConfig() const;247248/** @brief Returns the information whether this option is an edge249*250* Returns false. Only Option_Edge overrides this method returning true.251*252* @return true if the Option is an Option_Edge, false otherwise253*/254virtual bool isEdge() const;255256/** @brief Returns the information whether this option is a vector of edges257*258* Returns false. Only Option_EdgeVector overrides this method returning true.259*260* @return true if the Option is an Option_EdgeVector, false otherwise261*/262virtual bool isEdgeVector() const;263264/** @brief Returns the information whether the option may be set a further time265*266* This method returns whether the option was not already set using command line267* options / configuration. This is done by returning the value of myAmWritable.268*269* @return Whether the option may be set from the command line / configuration270*/271bool isWriteable() const;272273/** @brief Resets the option to be writeable274*275* An option is writable after initialisation, but as soon as it gets set,276* it is no longer writeable. This method resets the writable-flag.277*/278void resetWritable();279280/** @brief Resets the option to be on its default value281*282* An option is on its default after initialisation with a value, but as soon as it gets set,283* it is no longer. This method resets the default-flag.284*/285void resetDefault();286287/** @brief Returns the description of what this option does288*289* The description stored in myDescription is returned.290*291* @return The description of this option's purpose292*/293const std::string& getDescription() const;294295/** @brief Sets the description of what this option does296*297* The description stored in myDescription is returned.298*299* @return The description of this option's purpose300*/301void setDescription(const std::string& desc);302303/// @brief check if option is required304bool isRequired() const;305306/// @brief mark option as required307void setRequired();308309/// @brief check if option is positional310bool isPositional() const;311312/// @brief mark option as positional313void setPositional();314315/// @brief retrieve list separator316const std::string& getListSeparator() const;317318/// @brief set list separator319void setListSeparator(const std::string& listSep);320321/// @brief Returns the subtopic to which this option belongs322const std::string& getSubTopic() const;323324/// @brief Sets the subtopic to which this option belongs325void setSubtopic(const std::string& subtopic);326327/** @brief Returns the mml-type name of this option328*329* The type name stored in myTypeName is returned.330*331* @return The man-readable type name332*/333virtual const std::string& getTypeName() const;334335/** @brief Returns a copy of this option336*337* @return The option copy338*/339virtual Option* clone() const = 0;340341protected:342/** @brief Marks the information as set343*344* Sets the "myAmSet" - information. Returns whether the option was writeable before.345*346* @return Whether the option was not set before.347*/348bool markSet(const std::string& orig);349350/** @brief Constructor351*352* This constructor should be used by derived classes.353* The boolean value indicates whether a default value was supplied or not.354*355* @param[in] set A default value was supplied356*/357Option(bool set = false);358359/// @brief A type name for this option (has presets, but may be overwritten)360std::string myTypeName;361362/// @brief The original set string363std::string myValueString;364365private:366/// @brief information whether the value is set367bool myAmSet;368369/// @brief information whether the value is the default value (is then set)370bool myHaveTheDefaultValue = true;371372/// @brief information whether the value may be changed373bool myAmWritable = true;374375/// @brief The description what this option does376std::string myDescription;377378/// @brief this option is required (needed for python tools)379bool myRequired = false;380381/// @brief this option is positional (needed for python tools)382bool myPositional = false;383384/// @brief the list separator for this option (needed for python tools)385std::string myListSeparator = "";386387/// @brief The subtopic to which this option belongs388std::string mySubTopic;389};390391// -------------------------------------------------------------------------392// Option_Integer393// -------------------------------------------------------------------------394395class Option_Integer : public Option {396397public:398/** @brief Constructor for an option with a default value399*400* Calls Option(true)401*402* @param[in] value This option's default value403*/404Option_Integer(int value);405406/** @brief Returns the stored integer value407* @see Option::getInt()408* @return Returns the stored integer number409*/410int getInt() const;411412/** @brief Stores the given value after parsing it into an integer413*414* The value is converted into an integer and stored in "myValue".415* Then, "markSet" is called in order to know that a value has been set.416*417* The method returns whether the value could be set (the return value from418* "markSet").419*420* If the string could not be converted into an integer, an InvalidArgument421* is thrown.422*423* @see bool Option::set(std::string v)424* @return Whether the new value could be set425* @exception InvalidArgument If the value could not be converted into an integer426*/427bool set(const std::string& v, const std::string& orig, const bool append);428429/** @brief Returns the information whether the option is a int option430*431* Returns false. Only Option_Integer overrides this method returning true.432*433* @return true if the Option is an Option_Integer, false otherwise434*/435bool isInteger() const;436437CLONEABLE(Option_Integer)438439private:440/// @brief the value, valid only when the base-classes "myAmSet"-member is true441int myValue;442};443444// -------------------------------------------------------------------------445// Option_String446// -------------------------------------------------------------------------447448class Option_String : public Option {449450public:451/** @brief Constructor for an option with no default value452*453* Calls Option(false)454*/455Option_String();456457/** @brief Constructor for an option with a default value458*459* Calls Option(true)460*461* @param[in] value This option's default value462*/463Option_String(const std::string& value, std::string typeName = "STR");464465/** @brief Returns the stored string value466* @see std::string Option::getString()467* @return Returns the stored string468*/469std::string getString() const;470471/** @brief Stores the given value472*473* The value is stored in "myValue".474* Then, "markSet" is called in order to know that a value has been set.475*476* The method returns whether the value could be set (the return value from477* "markSet").478*479* @see bool Option::set(std::string v)480* @return Whether the new value could be set481*/482bool set(const std::string& v, const std::string& orig, const bool append);483484CLONEABLE(Option_String)485486protected:487/// @brief the value, valid only when the base-classes "myAmSet"-member is true488std::string myValue;489};490491// -------------------------------------------------------------------------492// Option_Float493// -------------------------------------------------------------------------494495class Option_Float : public Option {496497public:498/** @brief Constructor for an option with a default value499*500* Calls Option(true)501*502* @param[in] value This option's default value503*/504Option_Float(double value);505506/** @brief Returns the stored double value507* @see double Option::getFloat()508* @return Returns the stored real number509*/510double getFloat() const;511512/** @brief Stores the given value after parsing it into a double513*514* The value is converted into a double and stored in "myValue".515* Then, "markSet" is called in order to know that a value has been set.516*517* The method returns whether the value could be set (the return value from518* "markSet").519*520* If the string could not be converted into a double, an InvalidArgument521* is thrown.522*523* @see bool Option::set(std::string v)524* @return Whether the new value could be set525* @exception InvalidArgument If the value could not be converted into a double526*/527bool set(const std::string& v, const std::string& orig, const bool append);528529/** @brief Returns the information whether the option is a float option530*531* Returns false. Only Option_Float overrides this method returning true.532*533* @return true if the Option is an Option_Float, false otherwise534*/535bool isFloat() const;536537CLONEABLE(Option_Float)538539private:540/// @brief the value, valid only when the base-classes "myAmSet"-member is true541double myValue;542};543544// -------------------------------------------------------------------------545// Option_Bool546// -------------------------------------------------------------------------547548class Option_Bool : public Option {549550public:551/** @brief Constructor for an option with a default value552*553* Calls Option(true)554*555* @param[in] value This option's default value556*/557Option_Bool(bool value);558559/** @brief Returns the stored boolean value560* @see bool Option::getBool()561* @return Returns the stored boolean562*/563bool getBool() const;564565/// @brief sets the given value (converts it to bool)566bool set(const std::string& v, const std::string& orig, const bool append);567568/** @brief Returns true, the information whether the option is a bool option569*570* Returns true.571*572* @see bool Option::isBool()573* @return true574*/575bool isBool() const;576577CLONEABLE(Option_Bool)578579protected:580/// @brief the value, valid only when the base-classes "myAmSet"-member is true581bool myValue;582};583584// -------------------------------------------------------------------------585// Option_BoolExtended586// -------------------------------------------------------------------------587588class Option_BoolExtended : public Option_Bool {589590public:591/** @brief Constructor for an option that can be used without an argument592* like Option_BoolExtended but which also handles value strings593*594* Calls Option(true)595*596* @param[in] value This option's default value597*/598Option_BoolExtended(bool value);599600/// @brief sets the given value (converts it to bool)601bool set(const std::string& v, const std::string& orig, const bool append);602603CLONEABLE(Option_BoolExtended)604};605606// -------------------------------------------------------------------------607// Option_IntVector608// -------------------------------------------------------------------------609610class Option_IntVector : public Option {611612public:613/// @brief Constructor for an option with no default value614Option_IntVector();615616/** @brief Constructor for an option with a default value617*618* @param[in] value This option's default value619*/620Option_IntVector(const IntVector& value);621622/** @brief Returns the stored integer vector623* @see const IntVector &Option::getIntVector()624* @return Returns the stored integer vector625*/626const IntVector& getIntVector() const;627628/** @brief Stores the given value after parsing it into a vector of integers629*630* The value is converted into a vector of integers and stored in "myValue".631* Then, "markSet" is called in order to know that a value has been set.632*633* The method returns whether the value could be set (the return value from634* "markSet").635*636* If the string could not be converted into a vector of integers, an InvalidArgument637* is thrown.638*639* @see bool Option::set(std::string v)640* @return Whether the new value could be set641* @exception InvalidArgument If the value could not be converted into a vector of integers642*/643bool set(const std::string& v, const std::string& orig, const bool append);644645CLONEABLE(Option_IntVector)646647private:648/// @brief the value, valid only when the base-classes "myAmSet"-member is true649IntVector myValue;650};651652// -------------------------------------------------------------------------653// Option_StringVector654// -------------------------------------------------------------------------655656class Option_StringVector : public Option {657658public:659/// @brief Constructor for an option with no default value660Option_StringVector();661662/** @brief Constructor for an option with a default value663*664* @param[in] value This option's default value665*/666Option_StringVector(const StringVector& value);667668/** @brief Returns the stored string vector669* @see const StringVector &Option::getStringVector()670* @return Returns the stored string vector671*/672const StringVector& getStringVector() const;673674/** @brief Stores the given value after parsing it into a vector of strings675*676* The value is converted into a vector of strings and stored in "myValue".677* Then, "markSet" is called in order to know that a value has been set.678*679* The method returns whether the value could be set (the return value from680* "markSet").681*682* If the string could not be converted into a vector of strings, an683* InvalidArgument is thrown.684*685* @see bool Option::set(std::string v)686* @return Whether the new value could be set687* @exception InvalidArgument If the value could not be converted into a688* vector of strings689*/690bool set(const std::string& v, const std::string& orig, const bool append);691692CLONEABLE(Option_StringVector)693694private:695/// @brief the value, valid only when the base-classes "myAmSet"-member is true696StringVector myValue;697};698699// -------------------------------------------------------------------------700// Option_FileName701// -------------------------------------------------------------------------702703class Option_FileName : public Option_StringVector {704705public:706/// @brief Constructor for an option with no default value707Option_FileName();708709/** @brief Constructor for an option with a default value710*711* @param[in] value This option's default value712*/713Option_FileName(const StringVector& value);714715/** @brief Returns true, the information whether this option is a file name716*717* Returns true.718*719* @return true720*/721bool isFileName() const;722723/** @brief Legacy method that returns the stored filenames as a comma-separated string.724*725* @see std::string Option::getString()726* @see std::string StringVector::getValueString()727* @return Returns comma-separated string of the stored filenames728* @deprecated Legacy method used when Option_FileName was still derived from Option_String;729* not in line with code style of the Options sub-system.730*/731std::string getString() const;732733CLONEABLE(Option_FileName)734};735736// -------------------------------------------------------------------------737// Option_Network738// -------------------------------------------------------------------------739740class Option_Network : public Option_String {741742public:743/** @brief Constructor for an option with a default value744*745* @param[in] value This option's default value746*/747Option_Network(const std::string& value);748749/** @brief Returns true, the information whether this option is a file name750*751* Returns true.752*753* @return true754*/755bool isNetwork() const;756757CLONEABLE(Option_Network)758};759760// -------------------------------------------------------------------------761// Option_Additional762// -------------------------------------------------------------------------763764class Option_Additional : public Option_String {765766public:767/** @brief Constructor for an option with a default value768*769* @param[in] value This option's default value770*/771Option_Additional(const std::string& value);772773/** @brief Returns true, the information whether this option is a file name774*775* Returns true.776*777* @return true778*/779bool isAdditional() const;780781CLONEABLE(Option_Additional)782};783784// -------------------------------------------------------------------------785// Option_Route786// -------------------------------------------------------------------------787788class Option_Route : public Option_String {789790public:791/** @brief Constructor for an option with a default value792*793* @param[in] value This option's default value794*/795Option_Route(const std::string& value);796797/** @brief Returns true, the information whether this option is a file name798*799* Returns true.800*801* @return true802*/803bool isRoute() const;804805CLONEABLE(Option_Route)806};807808// -------------------------------------------------------------------------809// Option_Data810// -------------------------------------------------------------------------811812class Option_Data : public Option_String {813814public:815/** @brief Constructor for an option with a default value816*817* @param[in] value This option's default value818*/819Option_Data(const std::string& value);820821/** @brief Returns true, the information whether this option is a data file822*823* Returns true.824*825* @return true826*/827bool isData() const;828829CLONEABLE(Option_Data)830};831832// -------------------------------------------------------------------------833// Option_SumoConfig834// -------------------------------------------------------------------------835836class Option_SumoConfig : public Option_String {837838public:839/** @brief Constructor for an option with a default value840*841* @param[in] value This option's default value842*/843Option_SumoConfig(const std::string& value);844845/** @brief Returns true, the information whether this option is a sumo config name846*847* Returns true.848*849* @return true850*/851bool isSumoConfig() const;852853CLONEABLE(Option_SumoConfig)854};855856// -------------------------------------------------------------------------857// Option_Edge858// -------------------------------------------------------------------------859860class Option_Edge : public Option_String {861862public:863/** @brief Constructor for an option with a default value864*865* @param[in] value This option's default value866*/867Option_Edge(const std::string& value);868869/** @brief Returns true, the information whether this option is a list of edges870*871* Returns true.872*873* @return true874*/875bool isEdge() const;876877CLONEABLE(Option_Edge)878};879880// -------------------------------------------------------------------------881// Option_EdgeVector882// -------------------------------------------------------------------------883884class Option_EdgeVector : public Option_String {885886public:887/** @brief Constructor for an option with a default value888*889* @param[in] value This option's default value890*/891Option_EdgeVector(const std::string& value);892893/** @brief Returns true, the information whether this option is a list of edges894*895* Returns true.896*897* @return true898*/899bool isEdgeVector() const;900901CLONEABLE(Option_EdgeVector)902};903904905