SUMO - Simulation of Urban MObility
Option.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Classes representing a single program option (with different types)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef Option_h
23 #define Option_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <exception>
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
48 typedef std::vector<int> IntVector;
49 
50 
51 /* -------------------------------------------------------------------------
52  * Option
53  * ----------------------------------------------------------------------- */
79 class Option {
80 public:
82  virtual ~Option();
83 
84 
88  bool isSet() const;
89 
90 
93  void unSet();
94 
95 
104  virtual double getFloat() const;
105 
106 
115  virtual int getInt() const;
116 
117 
126  virtual std::string getString() const;
127 
128 
137  virtual bool getBool() const;
138 
139 
148  virtual const IntVector& getIntVector() const;
149 
150 
166  virtual bool set(const std::string& v) = 0;
167 
168 
175  virtual std::string getValueString() const = 0;
176 
177 
184  virtual bool isBool() const;
185 
186 
191  virtual bool isDefault() const;
192 
193 
200  virtual bool isFileName() const;
201 
202 
210  bool isWriteable() const;
211 
212 
218  void resetWritable();
219 
220 
226  void resetDefault();
227 
228 
235  const std::string& getDescription() const;
236 
237 
244  void setDescription(const std::string& desc);
245 
246 
253  virtual const std::string& getTypeName() const;
254 
255 
256 protected:
263  bool markSet();
264 
265 
266 protected:
274  Option(bool set = false);
275 
276 
278  Option(const Option& s);
279 
280 
282  virtual Option& operator=(const Option& s);
283 
284 
285 protected:
287  std::string myTypeName;
288 
289 
290 private:
292  bool myAmSet;
293 
296 
299 
301  std::string myDescription;
302 
303 };
304 
305 
306 /* -------------------------------------------------------------------------
307  * Option_Integer
308  * ----------------------------------------------------------------------- */
313 class Option_Integer : public Option {
314 public:
321  Option_Integer(int value);
322 
323 
325  Option_Integer(const Option_Integer& s);
326 
327 
329  ~Option_Integer();
330 
331 
334 
335 
340  int getInt() const;
341 
342 
358  bool set(const std::string& v);
359 
360 
368  std::string getValueString() const;
369 
370 
371 private:
373  int myValue;
374 
375 };
376 
377 
378 /* -------------------------------------------------------------------------
379  * Option_String
380  * ----------------------------------------------------------------------- */
381 class Option_String : public Option {
382 public:
387  Option_String();
388 
389 
396  Option_String(const std::string& value, std::string typeName = "STR");
397 
398 
400  Option_String(const Option_String& s);
401 
402 
404  virtual ~Option_String();
405 
406 
409 
410 
415  std::string getString() const;
416 
417 
429  bool set(const std::string& v);
430 
431 
439  std::string getValueString() const;
440 
441 
442 protected:
444  std::string myValue;
445 
446 };
447 
448 
449 /* -------------------------------------------------------------------------
450  * Option_Float
451  * ----------------------------------------------------------------------- */
452 class Option_Float : public Option {
453 public:
460  Option_Float(double value);
461 
462 
464  Option_Float(const Option_Float& s);
465 
466 
468  ~Option_Float();
469 
470 
473 
474 
479  double getFloat() const;
480 
481 
497  bool set(const std::string& v);
498 
499 
507  std::string getValueString() const;
508 
509 
510 private:
512  double myValue;
513 
514 };
515 
516 
517 /* -------------------------------------------------------------------------
518  * Option_Bool
519  * ----------------------------------------------------------------------- */
520 class Option_Bool : public Option {
521 public:
528  Option_Bool(bool value);
529 
530 
532  Option_Bool(const Option_Bool& s);
533 
534 
536  ~Option_Bool();
537 
538 
540  Option_Bool& operator=(const Option_Bool& s);
541 
542 
547  bool getBool() const;
548 
550  bool set(const std::string& v);
551 
552 
560  std::string getValueString() const;
561 
562 
570  bool isBool() const;
571 
572 
573 private:
575  bool myValue;
576 
577 };
578 
579 
580 /* -------------------------------------------------------------------------
581  * Option_FileName
582  * ----------------------------------------------------------------------- */
584 public:
587  Option_FileName();
588 
589 
594  Option_FileName(const std::string& value);
595 
596 
598  Option_FileName(const Option_String& s);
599 
600 
602  virtual ~Option_FileName();
603 
606 
607 
614  bool isFileName() const;
615 
616 
624  std::string getValueString() const;
625 
626 
627 };
628 
629 
630 /* -------------------------------------------------------------------------
631  * Option_IntVector
632  * ----------------------------------------------------------------------- */
633 class Option_IntVector : public Option {
634 public:
638 
639 
644  Option_IntVector(const IntVector& value);
645 
646 
649 
650 
652  virtual ~Option_IntVector();
653 
654 
657 
658 
663  const IntVector& getIntVector() const;
664 
665 
681  bool set(const std::string& v);
682 
683 
691  std::string getValueString() const;
692 
693 
694 private:
697 };
698 
699 
700 #endif
701 
702 /****************************************************************************/
703 
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:82
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:106
bool markSet()
Marks the information as set.
Definition: Option.cpp:112
bool myAmWritable
information whether the value may be changed
Definition: Option.h:298
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:94
virtual ~Option()
Definition: Option.cpp:60
std::string myValue
Definition: Option.h:444
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:171
bool myAmSet
information whether the value is set
Definition: Option.h:292
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:147
bool myValue
Definition: Option.h:575
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:88
void unSet()
marks this option as unset
Definition: Option.cpp:122
Option(bool set=false)
Constructor.
Definition: Option.cpp:51
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:159
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:64
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:48
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:287
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:141
double myValue
Definition: Option.h:512
IntVector myValue
Definition: Option.h:696
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:129
A class representing a single program option.
Definition: Option.h:79
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:100
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:135
An integer-option.
Definition: Option.h:313
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:165
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:153
std::string myDescription
The description what this option does.
Definition: Option.h:301
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:76
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:177
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:295