Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Option.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Classes representing a single program option (with different types)
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <string>
26#include <vector>
27#include <exception>
29
30// ===========================================================================
31// class definitions
32// ===========================================================================
33
37typedef std::vector<int> IntVector;
38
42typedef std::vector<std::string> StringVector;
43
44#define CLONEABLE(Type) virtual Type* clone() const { return new Type(*this); }
45
46/* -------------------------------------------------------------------------
47 * Option
48 * ----------------------------------------------------------------------- */
74class Option {
75
76public:
78 virtual ~Option();
79
83 bool isSet() const;
84
93 virtual double getFloat() const;
94
103 virtual int getInt() const;
104
114 virtual std::string getString() const;
115
124 virtual bool getBool() const;
125
134 virtual const IntVector& getIntVector() const;
135
144 virtual const StringVector& getStringVector() const;
145
161 virtual bool set(const std::string& v, const std::string& orig, const bool append) = 0;
162
169 const std::string& getValueString() const;
170
175 virtual bool isDefault() const;
176
183 virtual bool isInteger() const;
184
191 virtual bool isFloat() const;
192
199 virtual bool isBool() const;
200
207 virtual bool isFileName() const;
208
215 virtual bool isNetwork() const;
216
223 virtual bool isAdditional() const;
224
231 virtual bool isRoute() const;
232
239 virtual bool isData() const;
240
247 virtual bool isSumoConfig() const;
248
255 virtual bool isEdge() const;
256
263 virtual bool isEdgeVector() const;
264
272 bool isWriteable() const;
273
279 void resetWritable();
280
286 void resetDefault();
287
294 const std::string& getDescription() const;
295
302 void setDescription(const std::string& desc);
303
305 bool isRequired() const;
306
308 void setRequired();
309
311 bool isPositional() const;
312
314 void setPositional();
315
317 bool isEditable() const;
318
320 void setEditable(const bool value);
321
323 const std::string& getListSeparator() const;
324
326 void setListSeparator(const std::string& listSep);
327
329 const std::string& getSubTopic() const;
330
332 void setSubtopic(const std::string& subtopic);
333
340 virtual const std::string& getTypeName() const;
341
346 virtual Option* clone() const = 0;
347
348protected:
355 bool markSet(const std::string& orig);
356
364 Option(bool set = false);
365
367 std::string myTypeName;
368
370 std::string myValueString;
371
372private:
375
378
380 bool myAmWritable = true;
381
383 std::string myDescription;
384
386 bool myRequired = false;
387
389 bool myPositional = false;
390
392 bool myEditable = true;
393
395 std::string myListSeparator = "";
396
398 std::string mySubTopic;
399};
400
401// -------------------------------------------------------------------------
402// Option_Integer
403// -------------------------------------------------------------------------
404
405class Option_Integer : public Option {
406
407public:
414 Option_Integer(int value);
415
420 int getInt() const;
421
437 bool set(const std::string& v, const std::string& orig, const bool append);
438
445 bool isInteger() const;
446
448
449private:
452};
453
454// -------------------------------------------------------------------------
455// Option_String
456// -------------------------------------------------------------------------
457
458class Option_String : public Option {
459
460public:
466
473 Option_String(const std::string& value, std::string typeName = "STR");
474
479 std::string getString() const;
480
492 bool set(const std::string& v, const std::string& orig, const bool append);
493
495
496protected:
498 std::string myValue;
499};
500
501// -------------------------------------------------------------------------
502// Option_Float
503// -------------------------------------------------------------------------
504
505class Option_Float : public Option {
506
507public:
514 Option_Float(double value);
515
520 double getFloat() const;
521
537 bool set(const std::string& v, const std::string& orig, const bool append);
538
545 bool isFloat() const;
546
548
549private:
551 double myValue;
552};
553
554// -------------------------------------------------------------------------
555// Option_Bool
556// -------------------------------------------------------------------------
557
558class Option_Bool : public Option {
559
560public:
567 Option_Bool(bool value);
568
573 bool getBool() const;
574
576 bool set(const std::string& v, const std::string& orig, const bool append);
577
585 bool isBool() const;
586
588
589protected:
592};
593
594// -------------------------------------------------------------------------
595// Option_BoolExtended
596// -------------------------------------------------------------------------
597
599
600public:
608 Option_BoolExtended(bool value);
609
611 bool set(const std::string& v, const std::string& orig, const bool append);
612
614};
615
616// -------------------------------------------------------------------------
617// Option_IntVector
618// -------------------------------------------------------------------------
619
620class Option_IntVector : public Option {
621
622public:
625
630 Option_IntVector(const IntVector& value);
631
636 const IntVector& getIntVector() const;
637
653 bool set(const std::string& v, const std::string& orig, const bool append);
654
656
657private:
660};
661
662// -------------------------------------------------------------------------
663// Option_StringVector
664// -------------------------------------------------------------------------
665
667
668public:
671
676 Option_StringVector(const StringVector& value);
677
682 const StringVector& getStringVector() const;
683
700 bool set(const std::string& v, const std::string& orig, const bool append);
701
703
704private:
707};
708
709// -------------------------------------------------------------------------
710// Option_FileName
711// -------------------------------------------------------------------------
712
714
715public:
718
723 Option_FileName(const StringVector& value);
724
731 bool isFileName() const;
732
741 std::string getString() const;
742
744};
745
746// -------------------------------------------------------------------------
747// Option_Network
748// -------------------------------------------------------------------------
749
751
752public:
757 Option_Network(const std::string& value);
758
765 bool isNetwork() const;
766
768};
769
770// -------------------------------------------------------------------------
771// Option_Additional
772// -------------------------------------------------------------------------
773
775
776public:
781 Option_Additional(const std::string& value);
782
789 bool isAdditional() const;
790
792};
793
794// -------------------------------------------------------------------------
795// Option_Route
796// -------------------------------------------------------------------------
797
799
800public:
805 Option_Route(const std::string& value);
806
813 bool isRoute() const;
814
816};
817
818// -------------------------------------------------------------------------
819// Option_Data
820// -------------------------------------------------------------------------
821
823
824public:
829 Option_Data(const std::string& value);
830
837 bool isData() const;
838
840};
841
842// -------------------------------------------------------------------------
843// Option_SumoConfig
844// -------------------------------------------------------------------------
845
847
848public:
853 Option_SumoConfig(const std::string& value);
854
861 bool isSumoConfig() const;
862
864};
865
866// -------------------------------------------------------------------------
867// Option_Edge
868// -------------------------------------------------------------------------
869
871
872public:
877 Option_Edge(const std::string& value);
878
885 bool isEdge() const;
886
888};
889
890// -------------------------------------------------------------------------
891// Option_EdgeVector
892// -------------------------------------------------------------------------
893
895
896public:
901 Option_EdgeVector(const std::string& value);
902
909 bool isEdgeVector() const;
910
912};
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition Option.h:42
#define CLONEABLE(Type)
Definition Option.h:44
std::vector< int > IntVector
Definition of a vector of ints.
Definition Option.h:37
bool isAdditional() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:557
bool set(const std::string &v, const std::string &orig, const bool append)
sets the given value (converts it to bool)
Definition Option.cpp:418
bool getBool() const
Returns the stored boolean value.
Definition Option.cpp:387
bool set(const std::string &v, const std::string &orig, const bool append)
sets the given value (converts it to bool)
Definition Option.cpp:393
bool isBool() const
Returns true, the information whether the option is a bool option.
Definition Option.cpp:404
bool myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:591
bool isData() const
Returns true, the information whether this option is a data file.
Definition Option.cpp:585
bool isEdge() const
Returns true, the information whether this option is a list of edges.
Definition Option.cpp:613
bool isEdgeVector() const
Returns true, the information whether this option is a list of edges.
Definition Option.cpp:627
std::string getString() const
Legacy method that returns the stored filenames as a comma-separated string.
Definition Option.cpp:530
Option_FileName()
Constructor for an option with no default value.
Definition Option.cpp:511
bool isFileName() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:524
bool isFloat() const
Returns the information whether the option is a float option.
Definition Option.cpp:370
double getFloat() const
Returns the stored double value.
Definition Option.cpp:353
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value after parsing it into a double.
Definition Option.cpp:359
double myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:551
const IntVector & getIntVector() const
Returns the stored integer vector.
Definition Option.cpp:446
IntVector myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:659
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value after parsing it into a vector of integers.
Definition Option.cpp:452
Option_IntVector()
Constructor for an option with no default value.
Definition Option.cpp:432
bool isInteger() const
Returns the information whether the option is a int option.
Definition Option.cpp:304
int myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:451
int getInt() const
Returns the stored integer value.
Definition Option.cpp:286
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value after parsing it into an integer.
Definition Option.cpp:292
bool isNetwork() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:543
bool isRoute() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:571
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value.
Definition Option.cpp:333
std::string myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:498
std::string getString() const
Returns the stored string value.
Definition Option.cpp:327
Option_String()
Constructor for an option with no default value.
Definition Option.cpp:312
const StringVector & getStringVector() const
Returns the stored string vector.
Definition Option.cpp:490
StringVector myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:706
Option_StringVector()
Constructor for an option with no default value.
Definition Option.cpp:476
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value after parsing it into a vector of strings.
Definition Option.cpp:496
bool isSumoConfig() const
Returns true, the information whether this option is a sumo config name.
Definition Option.cpp:599
A class representing a single program option.
Definition Option.h:74
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition Option.h:377
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition Option.cpp:184
virtual bool isSumoConfig() const
Returns the information whether this option is a sumo config file.
Definition Option.cpp:166
virtual bool isNetwork() const
Returns the information whether this option is a network file.
Definition Option.cpp:142
bool isSet() const
returns the information whether this options holds a valid value
Definition Option.cpp:53
virtual ~Option()
destructor
Definition Option.cpp:49
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition Option.cpp:112
void setRequired()
mark option as required
Definition Option.cpp:220
virtual std::string getString() const
Returns the stored string value.
Definition Option.cpp:71
bool myAmSet
information whether the value is set
Definition Option.h:374
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition Option.cpp:83
void resetWritable()
Resets the option to be writeable.
Definition Option.cpp:190
const std::string & getDescription() const
Returns the description of what this option does.
Definition Option.cpp:202
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition Option.h:367
virtual bool isInteger() const
Returns the information whether the option is a int option.
Definition Option.cpp:118
std::string myListSeparator
the list separator for this option (needed for python tools)
Definition Option.h:395
std::string mySubTopic
The subtopic to which this option belongs.
Definition Option.h:398
void setListSeparator(const std::string &listSep)
set list separator
Definition Option.cpp:252
virtual bool isAdditional() const
Returns the information whether this option is an additional file.
Definition Option.cpp:148
virtual bool isData() const
Returns the information whether this option is a data file.
Definition Option.cpp:160
bool myEditable
this option can be edited using option dialog
Definition Option.h:392
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition Option.cpp:136
const std::string & getListSeparator() const
retrieve list separator
Definition Option.cpp:247
std::string myDescription
The description what this option does.
Definition Option.h:383
virtual const StringVector & getStringVector() const
Returns the stored string vector.
Definition Option.cpp:89
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition Option.cpp:208
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition Option.cpp:269
virtual int getInt() const
Returns the stored integer value.
Definition Option.cpp:65
virtual double getFloat() const
Returns the stored double value.
Definition Option.cpp:59
virtual bool isEdgeVector() const
Returns the information whether this option is a vector of edges.
Definition Option.cpp:178
virtual bool getBool() const
Returns the stored boolean value.
Definition Option.cpp:77
virtual bool isRoute() const
Returns the information whether this option is a route file.
Definition Option.cpp:154
bool isPositional() const
check if option is positional
Definition Option.cpp:225
void setPositional()
mark option as positional
Definition Option.cpp:230
bool myPositional
this option is positional (needed for python tools)
Definition Option.h:389
void resetDefault()
Resets the option to be on its default value.
Definition Option.cpp:196
const std::string & getSubTopic() const
Returns the subtopic to which this option belongs.
Definition Option.cpp:257
virtual bool set(const std::string &v, const std::string &orig, const bool append)=0
Stores the given value.
virtual bool isFloat() const
Returns the information whether the option is a float option.
Definition Option.cpp:124
bool markSet(const std::string &orig)
Marks the information as set.
Definition Option.cpp:95
bool myRequired
this option is required (needed for python tools)
Definition Option.h:386
bool myAmWritable
information whether the value may be changed
Definition Option.h:380
std::string myValueString
The original set string.
Definition Option.h:370
bool isEditable() const
check if this option is editable
Definition Option.cpp:236
virtual bool isEdge() const
Returns the information whether this option is an edge.
Definition Option.cpp:172
virtual Option * clone() const =0
Returns a copy of this option.
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition Option.cpp:130
void setEditable(const bool value)
set editable
Definition Option.cpp:241
bool isRequired() const
check if option is required
Definition Option.cpp:214
const std::string & getValueString() const
Returns the string-representation of the value.
Definition Option.cpp:106
void setSubtopic(const std::string &subtopic)
Sets the subtopic to which this option belongs.
Definition Option.cpp:263