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-2024 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 const std::string& getListSeparator() const;
318
320 void setListSeparator(const std::string& listSep);
321
323 const std::string& getSubTopic() const;
324
326 void setSubtopic(const std::string& subtopic);
327
334 virtual const std::string& getTypeName() const;
335
340 virtual Option* clone() const = 0;
341
342protected:
349 bool markSet(const std::string& orig);
350
358 Option(bool set = false);
359
361 std::string myTypeName;
362
364 std::string myValueString;
365
366private:
369
372
374 bool myAmWritable = true;
375
377 std::string myDescription;
378
380 bool myRequired = false;
381
383 bool myPositional = false;
384
386 std::string myListSeparator = "";
387
389 std::string mySubTopic;
390};
391
392// -------------------------------------------------------------------------
393// Option_Integer
394// -------------------------------------------------------------------------
395
396class Option_Integer : public Option {
397
398public:
405 Option_Integer(int value);
406
411 int getInt() const;
412
428 bool set(const std::string& v, const std::string& orig, const bool append);
429
436 bool isInteger() const;
437
439
440private:
443};
444
445// -------------------------------------------------------------------------
446// Option_String
447// -------------------------------------------------------------------------
448
449class Option_String : public Option {
450
451public:
457
464 Option_String(const std::string& value, std::string typeName = "STR");
465
470 std::string getString() const;
471
483 bool set(const std::string& v, const std::string& orig, const bool append);
484
486
487protected:
489 std::string myValue;
490};
491
492// -------------------------------------------------------------------------
493// Option_Float
494// -------------------------------------------------------------------------
495
496class Option_Float : public Option {
497
498public:
505 Option_Float(double value);
506
511 double getFloat() const;
512
528 bool set(const std::string& v, const std::string& orig, const bool append);
529
536 bool isFloat() const;
537
539
540private:
542 double myValue;
543};
544
545// -------------------------------------------------------------------------
546// Option_Bool
547// -------------------------------------------------------------------------
548
549class Option_Bool : public Option {
550
551public:
558 Option_Bool(bool value);
559
564 bool getBool() const;
565
567 bool set(const std::string& v, const std::string& orig, const bool append);
568
576 bool isBool() const;
577
579
580protected:
583};
584
585// -------------------------------------------------------------------------
586// Option_BoolExtended
587// -------------------------------------------------------------------------
588
590
591public:
599 Option_BoolExtended(bool value);
600
602 bool set(const std::string& v, const std::string& orig, const bool append);
603
605};
606
607// -------------------------------------------------------------------------
608// Option_IntVector
609// -------------------------------------------------------------------------
610
611class Option_IntVector : public Option {
612
613public:
616
621 Option_IntVector(const IntVector& value);
622
627 const IntVector& getIntVector() const;
628
644 bool set(const std::string& v, const std::string& orig, const bool append);
645
647
648private:
651};
652
653// -------------------------------------------------------------------------
654// Option_StringVector
655// -------------------------------------------------------------------------
656
658
659public:
662
667 Option_StringVector(const StringVector& value);
668
673 const StringVector& getStringVector() const;
674
691 bool set(const std::string& v, const std::string& orig, const bool append);
692
694
695private:
698};
699
700// -------------------------------------------------------------------------
701// Option_FileName
702// -------------------------------------------------------------------------
703
705
706public:
709
714 Option_FileName(const StringVector& value);
715
722 bool isFileName() const;
723
732 std::string getString() const;
733
735};
736
737// -------------------------------------------------------------------------
738// Option_Network
739// -------------------------------------------------------------------------
740
742
743public:
748 Option_Network(const std::string& value);
749
756 bool isNetwork() const;
757
759};
760
761// -------------------------------------------------------------------------
762// Option_Additional
763// -------------------------------------------------------------------------
764
766
767public:
772 Option_Additional(const std::string& value);
773
780 bool isAdditional() const;
781
783};
784
785// -------------------------------------------------------------------------
786// Option_Route
787// -------------------------------------------------------------------------
788
790
791public:
796 Option_Route(const std::string& value);
797
804 bool isRoute() const;
805
807};
808
809// -------------------------------------------------------------------------
810// Option_Data
811// -------------------------------------------------------------------------
812
814
815public:
820 Option_Data(const std::string& value);
821
828 bool isData() const;
829
831};
832
833// -------------------------------------------------------------------------
834// Option_SumoConfig
835// -------------------------------------------------------------------------
836
838
839public:
844 Option_SumoConfig(const std::string& value);
845
852 bool isSumoConfig() const;
853
855};
856
857// -------------------------------------------------------------------------
858// Option_Edge
859// -------------------------------------------------------------------------
860
862
863public:
868 Option_Edge(const std::string& value);
869
876 bool isEdge() const;
877
879};
880
881// -------------------------------------------------------------------------
882// Option_EdgeVector
883// -------------------------------------------------------------------------
884
886
887public:
892 Option_EdgeVector(const std::string& value);
893
900 bool isEdgeVector() const;
901
903};
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:545
bool set(const std::string &v, const std::string &orig, const bool append)
sets the given value (converts it to bool)
Definition Option.cpp:406
bool getBool() const
Returns the stored boolean value.
Definition Option.cpp:375
bool set(const std::string &v, const std::string &orig, const bool append)
sets the given value (converts it to bool)
Definition Option.cpp:381
bool isBool() const
Returns true, the information whether the option is a bool option.
Definition Option.cpp:392
bool myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:582
bool isData() const
Returns true, the information whether this option is a data file.
Definition Option.cpp:573
bool isEdge() const
Returns true, the information whether this option is a list of edges.
Definition Option.cpp:601
bool isEdgeVector() const
Returns true, the information whether this option is a list of edges.
Definition Option.cpp:615
std::string getString() const
Legacy method that returns the stored filenames as a comma-separated string.
Definition Option.cpp:518
Option_FileName()
Constructor for an option with no default value.
Definition Option.cpp:499
bool isFileName() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:512
bool isFloat() const
Returns the information whether the option is a float option.
Definition Option.cpp:358
double getFloat() const
Returns the stored double value.
Definition Option.cpp:341
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:347
double myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:542
const IntVector & getIntVector() const
Returns the stored integer vector.
Definition Option.cpp:434
IntVector myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:650
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:440
Option_IntVector()
Constructor for an option with no default value.
Definition Option.cpp:420
bool isInteger() const
Returns the information whether the option is a int option.
Definition Option.cpp:292
int myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:442
int getInt() const
Returns the stored integer value.
Definition Option.cpp:274
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:280
bool isNetwork() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:531
bool isRoute() const
Returns true, the information whether this option is a file name.
Definition Option.cpp:559
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value.
Definition Option.cpp:321
std::string myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:489
std::string getString() const
Returns the stored string value.
Definition Option.cpp:315
Option_String()
Constructor for an option with no default value.
Definition Option.cpp:300
const StringVector & getStringVector() const
Returns the stored string vector.
Definition Option.cpp:478
StringVector myValue
the value, valid only when the base-classes "myAmSet"-member is true
Definition Option.h:697
Option_StringVector()
Constructor for an option with no default value.
Definition Option.cpp:464
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:484
bool isSumoConfig() const
Returns true, the information whether this option is a sumo config name.
Definition Option.cpp:587
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:371
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:368
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:361
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:386
std::string mySubTopic
The subtopic to which this option belongs.
Definition Option.h:389
void setListSeparator(const std::string &listSep)
set list separator
Definition Option.cpp:240
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
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:235
std::string myDescription
The description what this option does.
Definition Option.h:377
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:257
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:383
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:245
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:380
bool myAmWritable
information whether the value may be changed
Definition Option.h:374
std::string myValueString
The original set string.
Definition Option.h:364
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
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:251