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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Classes representing a single program option (with different types)
18 /****************************************************************************/
19 #ifndef Option_h
20 #define Option_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <exception>
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
41 typedef std::vector<int> IntVector;
46 typedef std::vector<double> FloatVector;
47 
48 
49 /* -------------------------------------------------------------------------
50  * Option
51  * ----------------------------------------------------------------------- */
77 class Option {
78 public:
80  virtual ~Option();
81 
82 
86  bool isSet() const;
87 
88 
91  void unSet();
92 
93 
102  virtual double getFloat() const;
103 
104 
113  virtual int getInt() const;
114 
115 
124  virtual std::string getString() const;
125 
126 
135  virtual bool getBool() const;
136 
137 
146  virtual const IntVector& getIntVector() const;
147 
156  virtual const FloatVector& getFloatVector() const;
157 
158 
174  virtual bool set(const std::string& v) = 0;
175 
176 
183  virtual std::string getValueString() const = 0;
184 
185 
192  virtual bool isBool() const;
193 
194 
199  virtual bool isDefault() const;
200 
201 
208  virtual bool isFileName() const;
209 
210 
218  bool isWriteable() const;
219 
220 
226  void resetWritable();
227 
228 
234  void resetDefault();
235 
236 
243  const std::string& getDescription() const;
244 
245 
252  void setDescription(const std::string& desc);
253 
254 
261  virtual const std::string& getTypeName() const;
262 
263 
268  template<class OptionType, class ValueType>
269  static OptionType* makeUnsetWithDefault(ValueType def) {
270  OptionType* o = new OptionType(def);
271  o->unSet();
272  return o;
273  }
274 
275 
276 protected:
283  bool markSet();
284 
285 
286 protected:
294  Option(bool set = false);
295 
296 
298  Option(const Option& s);
299 
300 
302  virtual Option& operator=(const Option& s);
303 
304 
305 protected:
307  std::string myTypeName;
308 
309 
310 private:
312  bool myAmSet;
313 
316 
319 
321  std::string myDescription;
322 
323 };
324 
325 
326 /* -------------------------------------------------------------------------
327  * Option_Integer
328  * ----------------------------------------------------------------------- */
333 class Option_Integer : public Option {
334 public:
341  Option_Integer(int value);
342 
343 
345  Option_Integer(const Option_Integer& s);
346 
347 
349  ~Option_Integer();
350 
351 
354 
355 
360  int getInt() const;
361 
362 
378  bool set(const std::string& v);
379 
380 
388  std::string getValueString() const;
389 
390 
391 private:
393  int myValue;
394 
395 };
396 
397 
398 /* -------------------------------------------------------------------------
399  * Option_String
400  * ----------------------------------------------------------------------- */
401 class Option_String : public Option {
402 public:
407  Option_String();
408 
409 
416  Option_String(const std::string& value, std::string typeName = "STR");
417 
418 
420  Option_String(const Option_String& s);
421 
422 
424  virtual ~Option_String();
425 
426 
429 
430 
435  std::string getString() const;
436 
437 
449  bool set(const std::string& v);
450 
451 
459  std::string getValueString() const;
460 
461 
462 protected:
464  std::string myValue;
465 
466 };
467 
468 
469 /* -------------------------------------------------------------------------
470  * Option_Float
471  * ----------------------------------------------------------------------- */
472 class Option_Float : public Option {
473 public:
480  Option_Float(double value);
481 
482 
484  Option_Float(const Option_Float& s);
485 
486 
488  ~Option_Float();
489 
490 
493 
494 
499  double getFloat() const;
500 
501 
517  bool set(const std::string& v);
518 
519 
527  std::string getValueString() const;
528 
529 
530 private:
532  double myValue;
533 
534 };
535 
536 
537 /* -------------------------------------------------------------------------
538  * Option_Bool
539  * ----------------------------------------------------------------------- */
540 class Option_Bool : public Option {
541 public:
548  Option_Bool(bool value);
549 
550 
552  Option_Bool(const Option_Bool& s);
553 
554 
556  ~Option_Bool();
557 
558 
560  Option_Bool& operator=(const Option_Bool& s);
561 
562 
567  bool getBool() const;
568 
570  virtual bool set(const std::string& v);
571 
572 
580  virtual std::string getValueString() const;
581 
582 
590  bool isBool() const;
591 
592 
593 protected:
595  bool myValue;
596 
597 };
598 
599 
600 
601 /* -------------------------------------------------------------------------
602  * Option_BoolExtended
603  * ----------------------------------------------------------------------- */
605 public:
613  Option_BoolExtended(bool value);
614 
615 
618 
619 
622 
623 
626 
627 
629  bool set(const std::string& v);
630 
631 
639  std::string getValueString() const;
640 
641 
642 private:
644  std::string myValueString;
645 
646 };
647 
648 /* -------------------------------------------------------------------------
649  * Option_FileName
650  * ----------------------------------------------------------------------- */
652 public:
655  Option_FileName();
656 
657 
662  Option_FileName(const std::string& value);
663 
664 
666  Option_FileName(const Option_String& s);
667 
668 
670  virtual ~Option_FileName();
671 
674 
675 
682  bool isFileName() const;
683 
684 
692  std::string getValueString() const;
693 
694 
695 };
696 
697 
698 /* -------------------------------------------------------------------------
699  * Option_IntVector
700  * ----------------------------------------------------------------------- */
701 class Option_IntVector : public Option {
702 public:
706 
707 
712  Option_IntVector(const IntVector& value);
713 
714 
717 
718 
720  virtual ~Option_IntVector();
721 
722 
725 
726 
731  const IntVector& getIntVector() const;
732 
733 
749  bool set(const std::string& v);
750 
751 
759  std::string getValueString() const;
760 
761 
762 private:
765 };
766 
767 
768 /* -------------------------------------------------------------------------
769  * Option_FloatVector
770  * ----------------------------------------------------------------------- */
771 class Option_FloatVector : public Option {
772 public:
776 
777 
782  Option_FloatVector(const FloatVector& value);
783 
784 
787 
788 
790  virtual ~Option_FloatVector();
791 
792 
795 
796 
801  const FloatVector& getFloatVector() const;
802 
803 
819  bool set(const std::string& v);
820 
821 
829  std::string getValueString() const;
830 
831 
832 private:
835 };
836 #endif
837 
838 /****************************************************************************/
839 
Option_FloatVector::set
bool set(const std::string &v)
Stores the given value after parsing it into a vector of integers.
Definition: Option.cpp:599
Option::myAmSet
bool myAmSet
information whether the value is set
Definition: Option.h:312
Option::~Option
virtual ~Option()
Definition: Option.cpp:53
Option_BoolExtended::~Option_BoolExtended
~Option_BoolExtended()
Destructor.
Definition: Option.cpp:417
Option_String::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:286
Option_BoolExtended
Definition: Option.h:604
Option
A class representing a single program option.
Definition: Option.h:77
Option_Bool
Definition: Option.h:540
Option_Integer::set
bool set(const std::string &v)
Stores the given value after parsing it into an integer.
Definition: Option.cpp:217
Option_Bool::isBool
bool isBool() const
Returns true, the information whether the option is a bool option.
Definition: Option.cpp:403
Option::isWriteable
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:144
Option_Integer::operator=
Option_Integer & operator=(const Option_Integer &s)
Assignment operator.
Definition: Option.cpp:200
Option_BoolExtended::operator=
Option_BoolExtended & operator=(const Option_BoolExtended &s)
Assignment operator.
Definition: Option.cpp:427
Option_Float::operator=
Option_Float & operator=(const Option_Float &s)
Assignment operator.
Definition: Option.cpp:311
Option::resetDefault
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:156
Option_IntVector::Option_IntVector
Option_IntVector()
Constructor for an option with no default value.
Definition: Option.cpp:503
Option_Bool::operator=
Option_Bool & operator=(const Option_Bool &s)
Assignment operator.
Definition: Option.cpp:366
Option::isFileName
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:138
Option_Bool::set
virtual bool set(const std::string &v)
Definition: Option.cpp:383
Option_Float::myValue
double myValue
Definition: Option.h:532
Option_IntVector::myValue
IntVector myValue
Definition: Option.h:764
Option_FileName::isFileName
bool isFileName() const
Returns true, the information whether this option is a file name.
Definition: Option.cpp:488
Option::isBool
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:126
Option::setDescription
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:168
Option::isDefault
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:132
Option::getFloatVector
virtual const FloatVector & getFloatVector() const
Returns the stored float vector.
Definition: Option.cpp:104
Option_IntVector::set
bool set(const std::string &v)
Stores the given value after parsing it into a vector of integers.
Definition: Option.cpp:537
Option::myDescription
std::string myDescription
The description what this option does.
Definition: Option.h:321
IntVector
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:41
Option_Integer::getInt
int getInt() const
Returns the stored integer value.
Definition: Option.cpp:211
Option::getTypeName
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:174
Option::Option
Option(bool set=false)
Constructor.
Definition: Option.cpp:44
Option_Integer::Option_Integer
Option_Integer(int value)
Constructor for an option with a default value.
Definition: Option.cpp:184
Option_BoolExtended::Option_BoolExtended
Option_BoolExtended(bool value)
Constructor for an option that can be used without an argument like Option_BoolExtended but which als...
Definition: Option.cpp:412
Option_Float::getFloat
double getFloat() const
Returns the stored double value.
Definition: Option.cpp:322
Option_Bool::getValueString
virtual std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:394
Option_FileName::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:494
Option_String::getString
std::string getString() const
Returns the stored string value.
Definition: Option.cpp:273
Option_String::operator=
Option_String & operator=(const Option_String &s)
Assignment operator.
Definition: Option.cpp:262
Option_BoolExtended::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:452
Option_Integer::~Option_Integer
~Option_Integer()
Destructor.
Definition: Option.cpp:190
Option_FloatVector::getFloatVector
const FloatVector & getFloatVector() const
Returns the stored float vector.
Definition: Option.cpp:593
Option_FloatVector::~Option_FloatVector
virtual ~Option_FloatVector()
Destructor.
Definition: Option.cpp:581
Option::getDescription
const std::string & getDescription() const
Returns the description of what this option does.
Definition: Option.cpp:162
Option_Float::Option_Float
Option_Float(double value)
Constructor for an option with a default value.
Definition: Option.cpp:295
Option::isSet
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:69
Option_IntVector::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:557
Option_String::Option_String
Option_String()
Constructor for an option with no default value.
Definition: Option.cpp:240
Option_String
Definition: Option.h:401
UtilExceptions.h
Option_Float::set
bool set(const std::string &v)
Stores the given value after parsing it into a double.
Definition: Option.cpp:328
Option_FileName::Option_FileName
Option_FileName()
Constructor for an option with no default value.
Definition: Option.cpp:461
Option::set
virtual bool set(const std::string &v)=0
Stores the given value.
Option::getFloat
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:75
Option_Bool::~Option_Bool
~Option_Bool()
Destructor.
Definition: Option.cpp:356
Option_FloatVector::operator=
Option_FloatVector & operator=(const Option_FloatVector &s)
Assignment operator.
Definition: Option.cpp:585
Option_Float::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:339
Option_FloatVector::myValue
FloatVector myValue
Definition: Option.h:834
Option_String::set
bool set(const std::string &v)
Stores the given value.
Definition: Option.cpp:279
Option::resetWritable
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:150
Option_FloatVector::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:619
Option_Integer::getValueString
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:229
Option_IntVector::~Option_IntVector
virtual ~Option_IntVector()
Destructor.
Definition: Option.cpp:519
Option::unSet
void unSet()
marks this option as unset
Definition: Option.cpp:119
Option_Float
Definition: Option.h:472
Option_IntVector::getIntVector
const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:531
Option_FileName::~Option_FileName
virtual ~Option_FileName()
Destructor.
Definition: Option.cpp:477
Option_Bool::getBool
bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:377
Option::getString
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:87
Option_Float::~Option_Float
~Option_Float()
Destructor.
Definition: Option.cpp:301
Option::makeUnsetWithDefault
static OptionType * makeUnsetWithDefault(ValueType def)
Create a new Option of the given type with given default value but make it unset.
Definition: Option.h:269
Option_Bool::Option_Bool
Option_Bool(bool value)
Constructor for an option with a default value.
Definition: Option.cpp:350
Option_Bool::myValue
bool myValue
Definition: Option.h:595
Option::getIntVector
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:99
Option_BoolExtended::myValueString
std::string myValueString
Definition: Option.h:644
config.h
Option_FileName
Definition: Option.h:651
Option_BoolExtended::set
bool set(const std::string &v)
Definition: Option.cpp:439
Option::markSet
bool markSet()
Marks the information as set.
Definition: Option.cpp:109
Option_IntVector
Definition: Option.h:701
Option::getBool
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:93
Option::operator=
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:57
Option::myTypeName
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:307
Option::getInt
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:81
Option_Integer::myValue
int myValue
Definition: Option.h:393
Option_String::~Option_String
virtual ~Option_String()
Destructor.
Definition: Option.cpp:252
Option_Integer
An integer-option.
Definition: Option.h:333
Option::getValueString
virtual std::string getValueString() const =0
Returns the string-representation of the value.
Option_String::myValue
std::string myValue
Definition: Option.h:464
Option_FloatVector
Definition: Option.h:771
Option::myAmWritable
bool myAmWritable
information whether the value may be changed
Definition: Option.h:318
Option_IntVector::operator=
Option_IntVector & operator=(const Option_IntVector &s)
Assignment operator.
Definition: Option.cpp:523
Option_FileName::operator=
Option_FileName & operator=(const Option_FileName &s)
Assignment operator.
Definition: Option.cpp:481
FloatVector
std::vector< double > FloatVector
Definition of a vector of doubles.
Definition: Option.h:46
Option_FloatVector::Option_FloatVector
Option_FloatVector()
Constructor for an option with no default value.
Definition: Option.cpp:565
Option::myHaveTheDefaultValue
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:315