/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 check if this option is editable316bool isEditable() const;317318/// @brief set editable319void setEditable(const bool value);320321/// @brief retrieve list separator322const std::string& getListSeparator() const;323324/// @brief set list separator325void setListSeparator(const std::string& listSep);326327/// @brief Returns the subtopic to which this option belongs328const std::string& getSubTopic() const;329330/// @brief Sets the subtopic to which this option belongs331void setSubtopic(const std::string& subtopic);332333/** @brief Returns the mml-type name of this option334*335* The type name stored in myTypeName is returned.336*337* @return The man-readable type name338*/339virtual const std::string& getTypeName() const;340341/** @brief Returns a copy of this option342*343* @return The option copy344*/345virtual Option* clone() const = 0;346347protected:348/** @brief Marks the information as set349*350* Sets the "myAmSet" - information. Returns whether the option was writeable before.351*352* @return Whether the option was not set before.353*/354bool markSet(const std::string& orig);355356/** @brief Constructor357*358* This constructor should be used by derived classes.359* The boolean value indicates whether a default value was supplied or not.360*361* @param[in] set A default value was supplied362*/363Option(bool set = false);364365/// @brief A type name for this option (has presets, but may be overwritten)366std::string myTypeName;367368/// @brief The original set string369std::string myValueString;370371private:372/// @brief information whether the value is set373bool myAmSet;374375/// @brief information whether the value is the default value (is then set)376bool myHaveTheDefaultValue = true;377378/// @brief information whether the value may be changed379bool myAmWritable = true;380381/// @brief The description what this option does382std::string myDescription;383384/// @brief this option is required (needed for python tools)385bool myRequired = false;386387/// @brief this option is positional (needed for python tools)388bool myPositional = false;389390/// @brief this option can be edited using option dialog391bool myEditable = true;392393/// @brief the list separator for this option (needed for python tools)394std::string myListSeparator = "";395396/// @brief The subtopic to which this option belongs397std::string mySubTopic;398};399400// -------------------------------------------------------------------------401// Option_Integer402// -------------------------------------------------------------------------403404class Option_Integer : public Option {405406public:407/** @brief Constructor for an option with a default value408*409* Calls Option(true)410*411* @param[in] value This option's default value412*/413Option_Integer(int value);414415/** @brief Returns the stored integer value416* @see Option::getInt()417* @return Returns the stored integer number418*/419int getInt() const;420421/** @brief Stores the given value after parsing it into an integer422*423* The value is converted into an integer and stored in "myValue".424* Then, "markSet" is called in order to know that a value has been set.425*426* The method returns whether the value could be set (the return value from427* "markSet").428*429* If the string could not be converted into an integer, an InvalidArgument430* is thrown.431*432* @see bool Option::set(std::string v)433* @return Whether the new value could be set434* @exception InvalidArgument If the value could not be converted into an integer435*/436bool set(const std::string& v, const std::string& orig, const bool append);437438/** @brief Returns the information whether the option is a int option439*440* Returns false. Only Option_Integer overrides this method returning true.441*442* @return true if the Option is an Option_Integer, false otherwise443*/444bool isInteger() const;445446CLONEABLE(Option_Integer)447448private:449/// @brief the value, valid only when the base-classes "myAmSet"-member is true450int myValue;451};452453// -------------------------------------------------------------------------454// Option_String455// -------------------------------------------------------------------------456457class Option_String : public Option {458459public:460/** @brief Constructor for an option with no default value461*462* Calls Option(false)463*/464Option_String();465466/** @brief Constructor for an option with a default value467*468* Calls Option(true)469*470* @param[in] value This option's default value471*/472Option_String(const std::string& value, std::string typeName = "STR");473474/** @brief Returns the stored string value475* @see std::string Option::getString()476* @return Returns the stored string477*/478std::string getString() const;479480/** @brief Stores the given value481*482* The value is stored in "myValue".483* Then, "markSet" is called in order to know that a value has been set.484*485* The method returns whether the value could be set (the return value from486* "markSet").487*488* @see bool Option::set(std::string v)489* @return Whether the new value could be set490*/491bool set(const std::string& v, const std::string& orig, const bool append);492493CLONEABLE(Option_String)494495protected:496/// @brief the value, valid only when the base-classes "myAmSet"-member is true497std::string myValue;498};499500// -------------------------------------------------------------------------501// Option_Float502// -------------------------------------------------------------------------503504class Option_Float : public Option {505506public:507/** @brief Constructor for an option with a default value508*509* Calls Option(true)510*511* @param[in] value This option's default value512*/513Option_Float(double value);514515/** @brief Returns the stored double value516* @see double Option::getFloat()517* @return Returns the stored real number518*/519double getFloat() const;520521/** @brief Stores the given value after parsing it into a double522*523* The value is converted into a double and stored in "myValue".524* Then, "markSet" is called in order to know that a value has been set.525*526* The method returns whether the value could be set (the return value from527* "markSet").528*529* If the string could not be converted into a double, an InvalidArgument530* is thrown.531*532* @see bool Option::set(std::string v)533* @return Whether the new value could be set534* @exception InvalidArgument If the value could not be converted into a double535*/536bool set(const std::string& v, const std::string& orig, const bool append);537538/** @brief Returns the information whether the option is a float option539*540* Returns false. Only Option_Float overrides this method returning true.541*542* @return true if the Option is an Option_Float, false otherwise543*/544bool isFloat() const;545546CLONEABLE(Option_Float)547548private:549/// @brief the value, valid only when the base-classes "myAmSet"-member is true550double myValue;551};552553// -------------------------------------------------------------------------554// Option_Bool555// -------------------------------------------------------------------------556557class Option_Bool : public Option {558559public:560/** @brief Constructor for an option with a default value561*562* Calls Option(true)563*564* @param[in] value This option's default value565*/566Option_Bool(bool value);567568/** @brief Returns the stored boolean value569* @see bool Option::getBool()570* @return Returns the stored boolean571*/572bool getBool() const;573574/// @brief sets the given value (converts it to bool)575bool set(const std::string& v, const std::string& orig, const bool append);576577/** @brief Returns true, the information whether the option is a bool option578*579* Returns true.580*581* @see bool Option::isBool()582* @return true583*/584bool isBool() const;585586CLONEABLE(Option_Bool)587588protected:589/// @brief the value, valid only when the base-classes "myAmSet"-member is true590bool myValue;591};592593// -------------------------------------------------------------------------594// Option_BoolExtended595// -------------------------------------------------------------------------596597class Option_BoolExtended : public Option_Bool {598599public:600/** @brief Constructor for an option that can be used without an argument601* like Option_BoolExtended but which also handles value strings602*603* Calls Option(true)604*605* @param[in] value This option's default value606*/607Option_BoolExtended(bool value);608609/// @brief sets the given value (converts it to bool)610bool set(const std::string& v, const std::string& orig, const bool append);611612CLONEABLE(Option_BoolExtended)613};614615// -------------------------------------------------------------------------616// Option_IntVector617// -------------------------------------------------------------------------618619class Option_IntVector : public Option {620621public:622/// @brief Constructor for an option with no default value623Option_IntVector();624625/** @brief Constructor for an option with a default value626*627* @param[in] value This option's default value628*/629Option_IntVector(const IntVector& value);630631/** @brief Returns the stored integer vector632* @see const IntVector &Option::getIntVector()633* @return Returns the stored integer vector634*/635const IntVector& getIntVector() const;636637/** @brief Stores the given value after parsing it into a vector of integers638*639* The value is converted into a vector of integers and stored in "myValue".640* Then, "markSet" is called in order to know that a value has been set.641*642* The method returns whether the value could be set (the return value from643* "markSet").644*645* If the string could not be converted into a vector of integers, an InvalidArgument646* is thrown.647*648* @see bool Option::set(std::string v)649* @return Whether the new value could be set650* @exception InvalidArgument If the value could not be converted into a vector of integers651*/652bool set(const std::string& v, const std::string& orig, const bool append);653654CLONEABLE(Option_IntVector)655656private:657/// @brief the value, valid only when the base-classes "myAmSet"-member is true658IntVector myValue;659};660661// -------------------------------------------------------------------------662// Option_StringVector663// -------------------------------------------------------------------------664665class Option_StringVector : public Option {666667public:668/// @brief Constructor for an option with no default value669Option_StringVector();670671/** @brief Constructor for an option with a default value672*673* @param[in] value This option's default value674*/675Option_StringVector(const StringVector& value);676677/** @brief Returns the stored string vector678* @see const StringVector &Option::getStringVector()679* @return Returns the stored string vector680*/681const StringVector& getStringVector() const;682683/** @brief Stores the given value after parsing it into a vector of strings684*685* The value is converted into a vector of strings and stored in "myValue".686* Then, "markSet" is called in order to know that a value has been set.687*688* The method returns whether the value could be set (the return value from689* "markSet").690*691* If the string could not be converted into a vector of strings, an692* InvalidArgument is thrown.693*694* @see bool Option::set(std::string v)695* @return Whether the new value could be set696* @exception InvalidArgument If the value could not be converted into a697* vector of strings698*/699bool set(const std::string& v, const std::string& orig, const bool append);700701CLONEABLE(Option_StringVector)702703private:704/// @brief the value, valid only when the base-classes "myAmSet"-member is true705StringVector myValue;706};707708// -------------------------------------------------------------------------709// Option_FileName710// -------------------------------------------------------------------------711712class Option_FileName : public Option_StringVector {713714public:715/// @brief Constructor for an option with no default value716Option_FileName();717718/** @brief Constructor for an option with a default value719*720* @param[in] value This option's default value721*/722Option_FileName(const StringVector& value);723724/** @brief Returns true, the information whether this option is a file name725*726* Returns true.727*728* @return true729*/730bool isFileName() const;731732/** @brief Legacy method that returns the stored filenames as a comma-separated string.733*734* @see std::string Option::getString()735* @see std::string StringVector::getValueString()736* @return Returns comma-separated string of the stored filenames737* @deprecated Legacy method used when Option_FileName was still derived from Option_String;738* not in line with code style of the Options sub-system.739*/740std::string getString() const;741742CLONEABLE(Option_FileName)743};744745// -------------------------------------------------------------------------746// Option_Network747// -------------------------------------------------------------------------748749class Option_Network : public Option_String {750751public:752/** @brief Constructor for an option with a default value753*754* @param[in] value This option's default value755*/756Option_Network(const std::string& value);757758/** @brief Returns true, the information whether this option is a file name759*760* Returns true.761*762* @return true763*/764bool isNetwork() const;765766CLONEABLE(Option_Network)767};768769// -------------------------------------------------------------------------770// Option_Additional771// -------------------------------------------------------------------------772773class Option_Additional : public Option_String {774775public:776/** @brief Constructor for an option with a default value777*778* @param[in] value This option's default value779*/780Option_Additional(const std::string& value);781782/** @brief Returns true, the information whether this option is a file name783*784* Returns true.785*786* @return true787*/788bool isAdditional() const;789790CLONEABLE(Option_Additional)791};792793// -------------------------------------------------------------------------794// Option_Route795// -------------------------------------------------------------------------796797class Option_Route : public Option_String {798799public:800/** @brief Constructor for an option with a default value801*802* @param[in] value This option's default value803*/804Option_Route(const std::string& value);805806/** @brief Returns true, the information whether this option is a file name807*808* Returns true.809*810* @return true811*/812bool isRoute() const;813814CLONEABLE(Option_Route)815};816817// -------------------------------------------------------------------------818// Option_Data819// -------------------------------------------------------------------------820821class Option_Data : public Option_String {822823public:824/** @brief Constructor for an option with a default value825*826* @param[in] value This option's default value827*/828Option_Data(const std::string& value);829830/** @brief Returns true, the information whether this option is a data file831*832* Returns true.833*834* @return true835*/836bool isData() const;837838CLONEABLE(Option_Data)839};840841// -------------------------------------------------------------------------842// Option_SumoConfig843// -------------------------------------------------------------------------844845class Option_SumoConfig : public Option_String {846847public:848/** @brief Constructor for an option with a default value849*850* @param[in] value This option's default value851*/852Option_SumoConfig(const std::string& value);853854/** @brief Returns true, the information whether this option is a sumo config name855*856* Returns true.857*858* @return true859*/860bool isSumoConfig() const;861862CLONEABLE(Option_SumoConfig)863};864865// -------------------------------------------------------------------------866// Option_Edge867// -------------------------------------------------------------------------868869class Option_Edge : public Option_String {870871public:872/** @brief Constructor for an option with a default value873*874* @param[in] value This option's default value875*/876Option_Edge(const std::string& value);877878/** @brief Returns true, the information whether this option is a list of edges879*880* Returns true.881*882* @return true883*/884bool isEdge() const;885886CLONEABLE(Option_Edge)887};888889// -------------------------------------------------------------------------890// Option_EdgeVector891// -------------------------------------------------------------------------892893class Option_EdgeVector : public Option_String {894895public:896/** @brief Constructor for an option with a default value897*898* @param[in] value This option's default value899*/900Option_EdgeVector(const std::string& value);901902/** @brief Returns true, the information whether this option is a list of edges903*904* Returns true.905*906* @return true907*/908bool isEdgeVector() const;909910CLONEABLE(Option_EdgeVector)911};912913914