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-2018 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  bool set(const std::string& v);
571 
572 
580  std::string getValueString() const;
581 
582 
590  bool isBool() const;
591 
592 
593 private:
595  bool myValue;
596 
597 };
598 
599 
600 /* -------------------------------------------------------------------------
601  * Option_FileName
602  * ----------------------------------------------------------------------- */
604 public:
607  Option_FileName();
608 
609 
614  Option_FileName(const std::string& value);
615 
616 
618  Option_FileName(const Option_String& s);
619 
620 
622  virtual ~Option_FileName();
623 
626 
627 
634  bool isFileName() const;
635 
636 
644  std::string getValueString() const;
645 
646 
647 };
648 
649 
650 /* -------------------------------------------------------------------------
651  * Option_IntVector
652  * ----------------------------------------------------------------------- */
653 class Option_IntVector : public Option {
654 public:
658 
659 
664  Option_IntVector(const IntVector& value);
665 
666 
669 
670 
672  virtual ~Option_IntVector();
673 
674 
677 
678 
683  const IntVector& getIntVector() const;
684 
685 
701  bool set(const std::string& v);
702 
703 
711  std::string getValueString() const;
712 
713 
714 private:
717 };
718 
719 
720 /* -------------------------------------------------------------------------
721  * Option_FloatVector
722  * ----------------------------------------------------------------------- */
723 class Option_FloatVector : public Option {
724 public:
728 
729 
734  Option_FloatVector(const FloatVector& value);
735 
736 
739 
740 
742  virtual ~Option_FloatVector();
743 
744 
747 
748 
753  const FloatVector& getFloatVector() const;
754 
755 
771  bool set(const std::string& v);
772 
773 
781  std::string getValueString() const;
782 
783 
784 private:
787 };
788 #endif
789 
790 /****************************************************************************/
791 
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:75
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:99
bool markSet()
Marks the information as set.
Definition: Option.cpp:109
virtual const FloatVector & getFloatVector() const
Returns the stored float vector.
Definition: Option.cpp:104
std::vector< double > FloatVector
Definition of a vector of doubles.
Definition: Option.h:46
bool myAmWritable
information whether the value may be changed
Definition: Option.h:318
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:87
virtual ~Option()
Definition: Option.cpp:53
std::string myValue
Definition: Option.h:464
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:168
bool myAmSet
information whether the value is set
Definition: Option.h:312
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:144
bool myValue
Definition: Option.h:595
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:81
void unSet()
marks this option as unset
Definition: Option.cpp:119
Option(bool set=false)
Constructor.
Definition: Option.cpp:44
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:156
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:57
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:41
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:307
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:138
double myValue
Definition: Option.h:532
IntVector myValue
Definition: Option.h:716
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:126
A class representing a single program option.
Definition: Option.h:77
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:93
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:132
An integer-option.
Definition: Option.h:333
virtual std::string getValueString() const =0
Returns the string-representation of the value.
const std::string & getDescription() const
Returns the description of what this option does.
Definition: Option.cpp:162
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:150
std::string myDescription
The description what this option does.
Definition: Option.h:321
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:69
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:174
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:315
FloatVector myValue
Definition: Option.h:786
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