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-2020 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 // ===========================================================================
38 typedef std::vector<int> IntVector;
43 typedef std::vector<std::string> StringVector;
44 
45 /* -------------------------------------------------------------------------
46  * Option
47  * ----------------------------------------------------------------------- */
73 class Option {
74 public:
76  virtual ~Option();
77 
78 
82  bool isSet() const;
83 
84 
87  void unSet();
88 
89 
98  virtual double getFloat() const;
99 
100 
109  virtual int getInt() const;
110 
111 
121  virtual std::string getString() const;
122 
123 
132  virtual bool getBool() const;
133 
134 
143  virtual const IntVector& getIntVector() const;
144 
153  virtual const StringVector& getStringVector() const;
154 
170  virtual bool set(const std::string& v) = 0;
171 
172 
179  virtual std::string getValueString() const = 0;
180 
181 
188  virtual bool isBool() const;
189 
190 
195  virtual bool isDefault() const;
196 
197 
204  virtual bool isFileName() const;
205 
206 
214  bool isWriteable() const;
215 
216 
222  void resetWritable();
223 
224 
230  void resetDefault();
231 
232 
239  const std::string& getDescription() const;
240 
241 
248  void setDescription(const std::string& desc);
249 
250 
257  virtual const std::string& getTypeName() const;
258 
259 
264  template<class OptionType, class ValueType>
265  static OptionType* makeUnsetWithDefault(ValueType def) {
266  OptionType* o = new OptionType(def);
267  o->unSet();
268  return o;
269  }
270 
271 
272 protected:
279  bool markSet();
280 
281 
282 protected:
290  Option(bool set = false);
291 
292 
294  Option(const Option& s);
295 
296 
298  virtual Option& operator=(const Option& s);
299 
300 
301 protected:
303  std::string myTypeName;
304 
305 
306 private:
308  bool myAmSet;
309 
312 
315 
317  std::string myDescription;
318 
319 };
320 
321 
322 /* -------------------------------------------------------------------------
323  * Option_Integer
324  * ----------------------------------------------------------------------- */
329 class Option_Integer : public Option {
330 public:
337  Option_Integer(int value);
338 
339 
341  Option_Integer(const Option_Integer& s);
342 
343 
345  ~Option_Integer();
346 
347 
350 
351 
356  int getInt() const;
357 
358 
374  bool set(const std::string& v);
375 
376 
384  std::string getValueString() const;
385 
386 
387 private:
389  int myValue;
390 
391 };
392 
393 
394 /* -------------------------------------------------------------------------
395  * Option_String
396  * ----------------------------------------------------------------------- */
397 class Option_String : public Option {
398 public:
403  Option_String();
404 
405 
412  Option_String(const std::string& value, std::string typeName = "STR");
413 
414 
416  Option_String(const Option_String& s);
417 
418 
420  virtual ~Option_String();
421 
422 
425 
426 
431  std::string getString() const;
432 
433 
445  bool set(const std::string& v);
446 
447 
455  std::string getValueString() const;
456 
457 
458 protected:
460  std::string myValue;
461 
462 };
463 
464 
465 /* -------------------------------------------------------------------------
466  * Option_Float
467  * ----------------------------------------------------------------------- */
468 class Option_Float : public Option {
469 public:
476  Option_Float(double value);
477 
478 
480  Option_Float(const Option_Float& s);
481 
482 
484  ~Option_Float();
485 
486 
489 
490 
495  double getFloat() const;
496 
497 
513  bool set(const std::string& v);
514 
515 
523  std::string getValueString() const;
524 
525 
526 private:
528  double myValue;
529 
530 };
531 
532 
533 /* -------------------------------------------------------------------------
534  * Option_Bool
535  * ----------------------------------------------------------------------- */
536 class Option_Bool : public Option {
537 public:
544  Option_Bool(bool value);
545 
546 
548  Option_Bool(const Option_Bool& s);
549 
550 
552  ~Option_Bool();
553 
554 
556  Option_Bool& operator=(const Option_Bool& s);
557 
558 
563  bool getBool() const;
564 
566  virtual bool set(const std::string& v);
567 
568 
576  virtual std::string getValueString() const;
577 
578 
586  bool isBool() const;
587 
588 
589 protected:
591  bool myValue;
592 
593 };
594 
595 
596 
597 /* -------------------------------------------------------------------------
598  * Option_BoolExtended
599  * ----------------------------------------------------------------------- */
601 public:
609  Option_BoolExtended(bool value);
610 
611 
614 
615 
618 
619 
622 
623 
625  bool set(const std::string& v);
626 
627 
635  std::string getValueString() const;
636 
637 
638 private:
640  std::string myValueString;
641 
642 };
643 
644 
645 /* -------------------------------------------------------------------------
646  * Option_IntVector
647  * ----------------------------------------------------------------------- */
648 class Option_IntVector : public Option {
649 public:
653 
654 
659  Option_IntVector(const IntVector& value);
660 
661 
664 
665 
667  virtual ~Option_IntVector();
668 
669 
672 
673 
678  const IntVector& getIntVector() const;
679 
680 
696  bool set(const std::string& v);
697 
698 
706  std::string getValueString() const;
707 
708 
709 private:
712 };
713 
714 
715 /* -------------------------------------------------------------------------
716  * Option_StringVector
717  * ----------------------------------------------------------------------- */
718 class Option_StringVector : public Option {
719 public:
723 
728  Option_StringVector(const StringVector& value);
729 
732 
734  virtual ~Option_StringVector();
735 
738 
743  const StringVector& getStringVector() const;
744 
761  bool set(const std::string& v);
762 
770  std::string getValueString() const;
771 
772 private:
775 };
776 
777 
778 /* -------------------------------------------------------------------------
779  * Option_FileName
780  * ----------------------------------------------------------------------- */
782 public:
785  Option_FileName();
786 
791  Option_FileName(const StringVector& value);
792 
795 
797  virtual ~Option_FileName();
798 
801 
808  bool isFileName() const;
809 
818  std::string getString() const;
819 
827  std::string getValueString() const;
828 };
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
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:450
Option_BoolExtended(bool value)
Constructor for an option that can be used without an argument like Option_BoolExtended but which als...
Definition: Option.cpp:410
std::string myValueString
Definition: Option.h:640
~Option_BoolExtended()
Destructor.
Definition: Option.cpp:415
bool set(const std::string &v)
Definition: Option.cpp:437
Option_BoolExtended & operator=(const Option_BoolExtended &s)
Assignment operator.
Definition: Option.cpp:425
Option_Bool & operator=(const Option_Bool &s)
Assignment operator.
Definition: Option.cpp:364
bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:375
~Option_Bool()
Destructor.
Definition: Option.cpp:354
virtual std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:392
bool isBool() const
Returns true, the information whether the option is a bool option.
Definition: Option.cpp:401
Option_Bool(bool value)
Constructor for an option with a default value.
Definition: Option.cpp:348
virtual bool set(const std::string &v)
Definition: Option.cpp:381
bool myValue
Definition: Option.h:591
Option_FileName & operator=(const Option_FileName &s)
Assignment operator.
Definition: Option.cpp:588
std::string getString() const
Legacy method that returns the stored filenames as a comma-separated string.
Definition: Option.cpp:598
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:602
virtual ~Option_FileName()
Destructor.
Definition: Option.cpp:586
Option_FileName()
Constructor for an option with no default value.
Definition: Option.cpp:574
bool isFileName() const
Returns true, the information whether this option is a file name.
Definition: Option.cpp:593
double getFloat() const
Returns the stored double value.
Definition: Option.cpp:320
~Option_Float()
Destructor.
Definition: Option.cpp:299
bool set(const std::string &v)
Stores the given value after parsing it into a double.
Definition: Option.cpp:326
double myValue
Definition: Option.h:528
Option_Float & operator=(const Option_Float &s)
Assignment operator.
Definition: Option.cpp:309
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:337
Option_Float(double value)
Constructor for an option with a default value.
Definition: Option.cpp:293
const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:486
Option_IntVector & operator=(const Option_IntVector &s)
Assignment operator.
Definition: Option.cpp:478
IntVector myValue
Definition: Option.h:711
Option_IntVector()
Constructor for an option with no default value.
Definition: Option.cpp:458
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:512
bool set(const std::string &v)
Stores the given value after parsing it into a vector of integers.
Definition: Option.cpp:492
virtual ~Option_IntVector()
Destructor.
Definition: Option.cpp:474
An integer-option.
Definition: Option.h:329
Option_Integer(int value)
Constructor for an option with a default value.
Definition: Option.cpp:182
Option_Integer & operator=(const Option_Integer &s)
Assignment operator.
Definition: Option.cpp:198
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:227
~Option_Integer()
Destructor.
Definition: Option.cpp:188
int getInt() const
Returns the stored integer value.
Definition: Option.cpp:209
bool set(const std::string &v)
Stores the given value after parsing it into an integer.
Definition: Option.cpp:215
bool set(const std::string &v)
Stores the given value.
Definition: Option.cpp:277
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:284
virtual ~Option_String()
Destructor.
Definition: Option.cpp:250
std::string myValue
Definition: Option.h:460
Option_String & operator=(const Option_String &s)
Assignment operator.
Definition: Option.cpp:260
std::string getString() const
Returns the stored string value.
Definition: Option.cpp:271
Option_String()
Constructor for an option with no default value.
Definition: Option.cpp:238
const StringVector & getStringVector() const
Returns the stored string vector.
Definition: Option.cpp:542
Option_StringVector & operator=(const Option_StringVector &s)
Assignment operator.
Definition: Option.cpp:535
StringVector myValue
Definition: Option.h:774
Option_StringVector()
Constructor for an option with no default value.
Definition: Option.cpp:520
bool set(const std::string &v)
Stores the given value after parsing it into a vector of strings.
Definition: Option.cpp:547
virtual ~Option_StringVector()
Destructor.
Definition: Option.cpp:532
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:566
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:311
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:142
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:67
virtual ~Option()
Definition: Option.cpp:51
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:130
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:85
bool myAmSet
information whether the value is set
Definition: Option.h:308
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:97
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:148
const std::string & getDescription() const
Returns the description of what this option does.
Definition: Option.cpp:160
static OptionType * makeUnsetWithDefault(ValueType def)
Create a new Option of the given type with given default value but make it unset.
Definition: Option.h:265
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:303
virtual bool set(const std::string &v)=0
Stores the given value.
void unSet()
marks this option as unset
Definition: Option.cpp:117
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:136
std::string myDescription
The description what this option does.
Definition: Option.h:317
virtual const StringVector & getStringVector() const
Returns the stored string vector.
Definition: Option.cpp:102
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:166
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:172
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:79
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:73
bool markSet()
Marks the information as set.
Definition: Option.cpp:107
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:91
Option(bool set=false)
Constructor.
Definition: Option.cpp:42
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:154
bool myAmWritable
information whether the value may be changed
Definition: Option.h:314
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:55
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:124
virtual std::string getValueString() const =0
Returns the string-representation of the value.