Eclipse SUMO - Simulation of Urban MObility
Option.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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// ===========================================================================
32// class definitions
33// ===========================================================================
38typedef std::vector<int> IntVector;
43typedef std::vector<std::string> StringVector;
44
45/* -------------------------------------------------------------------------
46 * Option
47 * ----------------------------------------------------------------------- */
73class Option {
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 return myValueString;
169 }
170
177 virtual bool isBool() const;
178
183 virtual bool isDefault() const;
184
191 virtual bool isFileName() const;
192
200 bool isWriteable() const;
201
207 void resetWritable();
208
214 void resetDefault();
215
222 const std::string& getDescription() const;
223
230 void setDescription(const std::string& desc);
231
238 virtual const std::string& getTypeName() const;
239
240protected:
247 bool markSet(const std::string& orig);
248
249protected:
257 Option(bool set = false);
258
259protected:
261 std::string myTypeName;
262
264 std::string myValueString;
265
266private:
269
272
275
277 std::string myDescription;
278
279};
280
281
282/* -------------------------------------------------------------------------
283 * Option_Integer
284 * ----------------------------------------------------------------------- */
289class Option_Integer : public Option {
290public:
297 Option_Integer(int value);
298
303 int getInt() const;
304
320 bool set(const std::string& v, const std::string& orig, const bool append);
321
322private:
325};
326
327
328/* -------------------------------------------------------------------------
329 * Option_String
330 * ----------------------------------------------------------------------- */
331class Option_String : public Option {
332public:
338
345 Option_String(const std::string& value, std::string typeName = "STR");
346
351 std::string getString() const;
352
364 bool set(const std::string& v, const std::string& orig, const bool append);
365
366protected:
368 std::string myValue;
369
370};
371
372
373/* -------------------------------------------------------------------------
374 * Option_Float
375 * ----------------------------------------------------------------------- */
376class Option_Float : public Option {
377public:
384 Option_Float(double value);
385
390 double getFloat() const;
391
407 bool set(const std::string& v, const std::string& orig, const bool append);
408
409private:
411 double myValue;
412};
413
414
415/* -------------------------------------------------------------------------
416 * Option_Bool
417 * ----------------------------------------------------------------------- */
418class Option_Bool : public Option {
419public:
426 Option_Bool(bool value);
427
432 bool getBool() const;
433
435 bool set(const std::string& v, const std::string& orig, const bool append);
436
444 bool isBool() const;
445
446protected:
449};
450
451
452
453/* -------------------------------------------------------------------------
454 * Option_BoolExtended
455 * ----------------------------------------------------------------------- */
457public:
465 Option_BoolExtended(bool value);
466
468 bool set(const std::string& v, const std::string& orig, const bool append);
469};
470
471
472/* -------------------------------------------------------------------------
473 * Option_IntVector
474 * ----------------------------------------------------------------------- */
475class Option_IntVector : public Option {
476public:
480
485 Option_IntVector(const IntVector& value);
486
491 const IntVector& getIntVector() const;
492
508 bool set(const std::string& v, const std::string& orig, const bool append);
509
510private:
513};
514
515
516/* -------------------------------------------------------------------------
517 * Option_StringVector
518 * ----------------------------------------------------------------------- */
520public:
524
529 Option_StringVector(const StringVector& value);
530
535 const StringVector& getStringVector() const;
536
553 bool set(const std::string& v, const std::string& orig, const bool append);
554
555private:
558};
559
560
561/* -------------------------------------------------------------------------
562 * Option_FileName
563 * ----------------------------------------------------------------------- */
565public:
569
574 Option_FileName(const StringVector& value);
575
582 bool isFileName() const;
583
592 std::string getString() const;
593};
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:43
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:38
Option_BoolExtended(bool value)
Constructor for an option that can be used without an argument like Option_BoolExtended but which als...
Definition: Option.cpp:278
bool set(const std::string &v, const std::string &orig, const bool append)
Definition: Option.cpp:284
bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:253
bool set(const std::string &v, const std::string &orig, const bool append)
Definition: Option.cpp:259
bool isBool() const
Returns true, the information whether the option is a bool option.
Definition: Option.cpp:270
Option_Bool(bool value)
Constructor for an option with a default value.
Definition: Option.cpp:245
bool myValue
Definition: Option.h:448
std::string getString() const
Legacy method that returns the stored filenames as a comma-separated string.
Definition: Option.cpp:393
Option_FileName()
Constructor for an option with no default value.
Definition: Option.cpp:376
bool isFileName() const
Returns true, the information whether this option is a file name.
Definition: Option.cpp:387
double getFloat() const
Returns the stored double value.
Definition: Option.cpp:226
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:232
double myValue
Definition: Option.h:411
Option_Float(double value)
Constructor for an option with a default value.
Definition: Option.cpp:216
const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:312
IntVector myValue
Definition: Option.h:512
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:318
Option_IntVector()
Constructor for an option with no default value.
Definition: Option.cpp:298
An integer-option.
Definition: Option.h:289
Option_Integer(int value)
Constructor for an option with a default value.
Definition: Option.cpp:159
int getInt() const
Returns the stored integer value.
Definition: Option.cpp:167
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:173
bool set(const std::string &v, const std::string &orig, const bool append)
Stores the given value.
Definition: Option.cpp:207
std::string myValue
Definition: Option.h:368
std::string getString() const
Returns the stored string value.
Definition: Option.cpp:201
Option_String()
Constructor for an option with no default value.
Definition: Option.cpp:187
const StringVector & getStringVector() const
Returns the stored string vector.
Definition: Option.cpp:355
StringVector myValue
Definition: Option.h:557
Option_StringVector()
Constructor for an option with no default value.
Definition: Option.cpp:342
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:361
A class representing a single program option.
Definition: Option.h:73
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:271
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:121
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:50
virtual ~Option()
Definition: Option.cpp:46
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:109
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:68
bool myAmSet
information whether the value is set
Definition: Option.h:268
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:80
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:127
const std::string & getDescription() const
Returns the description of what this option does.
Definition: Option.cpp:139
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:261
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:115
std::string myDescription
The description what this option does.
Definition: Option.h:277
virtual const StringVector & getStringVector() const
Returns the stored string vector.
Definition: Option.cpp:86
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:145
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:151
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:62
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:56
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:74
Option(bool set=false)
Constructor.
Definition: Option.cpp:42
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:133
virtual bool set(const std::string &v, const std::string &orig, const bool append)=0
Stores the given value.
bool markSet(const std::string &orig)
Marks the information as set.
Definition: Option.cpp:92
bool myAmWritable
information whether the value may be changed
Definition: Option.h:274
std::string myValueString
The original set string.
Definition: Option.h:264
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:103
const std::string & getValueString() const
Returns the string-representation of the value.
Definition: Option.h:167