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/* -------------------------------------------------------------------------
45 * Option
46 * ----------------------------------------------------------------------- */
72class Option {
73
74public:
76 virtual ~Option();
77
81 bool isSet() const;
82
91 virtual double getFloat() const;
92
101 virtual int getInt() const;
102
112 virtual std::string getString() const;
113
122 virtual bool getBool() const;
123
132 virtual const IntVector& getIntVector() const;
133
142 virtual const StringVector& getStringVector() const;
143
159 virtual bool set(const std::string& v, const std::string& orig, const bool append) = 0;
160
167 const std::string& getValueString() const;
168
173 virtual bool isDefault() const;
174
181 virtual bool isInteger() const;
182
189 virtual bool isFloat() const;
190
197 virtual bool isBool() const;
198
205 virtual bool isFileName() const;
206
213 virtual bool isNetwork() const;
214
221 virtual bool isAdditional() const;
222
229 virtual bool isRoute() const;
230
237 virtual bool isData() const;
238
245 virtual bool isSumoConfig() const;
246
253 virtual bool isEdge() const;
254
261 virtual bool isEdgeVector() const;
262
270 bool isWriteable() const;
271
277 void resetWritable();
278
284 void resetDefault();
285
292 const std::string& getDescription() const;
293
300 void setDescription(const std::string& desc);
301
303 bool isRequired() const;
304
306 void setRequired();
307
309 bool isPositional() const;
310
312 void setPositional();
313
315 const std::string& getListSeparator() const;
316
318 void setListSeparator(const std::string& listSep);
319
321 const std::string& getSubTopic() const;
322
324 void setSubtopic(const std::string& subtopic);
325
332 virtual const std::string& getTypeName() const;
333
334protected:
341 bool markSet(const std::string& orig);
342
350 Option(bool set = false);
351
353 std::string myTypeName;
354
356 std::string myValueString;
357
358private:
361
364
366 bool myAmWritable = true;
367
369 std::string myDescription;
370
372 bool myRequired = false;
373
375 bool myPositional = false;
376
378 std::string myListSeparator = "";
379
381 std::string mySubTopic;
382};
383
384// -------------------------------------------------------------------------
385// Option_Integer
386// -------------------------------------------------------------------------
387
388class Option_Integer : public Option {
389
390public:
397 Option_Integer(int value);
398
403 int getInt() const;
404
420 bool set(const std::string& v, const std::string& orig, const bool append);
421
428 bool isInteger() const;
429
430private:
433};
434
435// -------------------------------------------------------------------------
436// Option_String
437// -------------------------------------------------------------------------
438
439class Option_String : public Option {
440
441public:
447
454 Option_String(const std::string& value, std::string typeName = "STR");
455
460 std::string getString() const;
461
473 bool set(const std::string& v, const std::string& orig, const bool append);
474
475protected:
477 std::string myValue;
478};
479
480// -------------------------------------------------------------------------
481// Option_Float
482// -------------------------------------------------------------------------
483
484class Option_Float : public Option {
485
486public:
493 Option_Float(double value);
494
499 double getFloat() const;
500
516 bool set(const std::string& v, const std::string& orig, const bool append);
517
524 bool isFloat() const;
525
526private:
528 double myValue;
529};
530
531// -------------------------------------------------------------------------
532// Option_Bool
533// -------------------------------------------------------------------------
534
535class Option_Bool : public Option {
536
537public:
544 Option_Bool(bool value);
545
550 bool getBool() const;
551
553 bool set(const std::string& v, const std::string& orig, const bool append);
554
562 bool isBool() const;
563
564protected:
567};
568
569// -------------------------------------------------------------------------
570// Option_BoolExtended
571// -------------------------------------------------------------------------
572
574
575public:
583 Option_BoolExtended(bool value);
584
586 bool set(const std::string& v, const std::string& orig, const bool append);
587};
588
589// -------------------------------------------------------------------------
590// Option_IntVector
591// -------------------------------------------------------------------------
592
593class Option_IntVector : public Option {
594
595public:
598
603 Option_IntVector(const IntVector& value);
604
609 const IntVector& getIntVector() const;
610
626 bool set(const std::string& v, const std::string& orig, const bool append);
627
628private:
631};
632
633// -------------------------------------------------------------------------
634// Option_StringVector
635// -------------------------------------------------------------------------
636
638
639public:
642
647 Option_StringVector(const StringVector& value);
648
653 const StringVector& getStringVector() const;
654
671 bool set(const std::string& v, const std::string& orig, const bool append);
672
673private:
676};
677
678// -------------------------------------------------------------------------
679// Option_FileName
680// -------------------------------------------------------------------------
681
683
684public:
687
692 Option_FileName(const StringVector& value);
693
700 bool isFileName() const;
701
710 std::string getString() const;
711};
712
713// -------------------------------------------------------------------------
714// Option_Network
715// -------------------------------------------------------------------------
716
718
719public:
724 Option_Network(const std::string& value);
725
732 bool isNetwork() const;
733};
734
735// -------------------------------------------------------------------------
736// Option_Additional
737// -------------------------------------------------------------------------
738
740
741public:
746 Option_Additional(const std::string& value);
747
754 bool isAdditional() const;
755};
756
757// -------------------------------------------------------------------------
758// Option_Route
759// -------------------------------------------------------------------------
760
762
763public:
768 Option_Route(const std::string& value);
769
776 bool isRoute() const;
777};
778
779// -------------------------------------------------------------------------
780// Option_Data
781// -------------------------------------------------------------------------
782
784
785public:
790 Option_Data(const std::string& value);
791
798 bool isData() const;
799};
800
801// -------------------------------------------------------------------------
802// Option_SumoConfig
803// -------------------------------------------------------------------------
804
806
807public:
812 Option_SumoConfig(const std::string& value);
813
820 bool isSumoConfig() const;
821};
822
823// -------------------------------------------------------------------------
824// Option_Edge
825// -------------------------------------------------------------------------
826
828
829public:
834 Option_Edge(const std::string& value);
835
842 bool isEdge() const;
843};
844
845// -------------------------------------------------------------------------
846// Option_EdgeVector
847// -------------------------------------------------------------------------
848
850
851public:
856 Option_EdgeVector(const std::string& value);
857
864 bool isEdgeVector() const;
865};
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition Option.h:42
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:566
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:528
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:630
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:432
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:477
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:675
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:72
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition Option.h:363
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:360
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:353
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:378
std::string mySubTopic
The subtopic to which this option belongs.
Definition Option.h:381
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:369
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:375
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:372
bool myAmWritable
information whether the value may be changed
Definition Option.h:366
std::string myValueString
The original set string.
Definition Option.h:356
virtual bool isEdge() const
Returns the information whether this option is an edge.
Definition Option.cpp:172
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