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-2016 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 SUMOReal 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:
319  Option_Integer();
320 
321 
328  Option_Integer(int value);
329 
330 
332  Option_Integer(const Option_Integer& s);
333 
334 
336  ~Option_Integer();
337 
338 
341 
342 
347  int getInt() const;
348 
349 
365  bool set(const std::string& v);
366 
367 
375  std::string getValueString() const;
376 
377 
378 private:
380  int myValue;
381 
382 };
383 
384 
385 /* -------------------------------------------------------------------------
386  * Option_String
387  * ----------------------------------------------------------------------- */
388 class Option_String : public Option {
389 public:
394  Option_String();
395 
396 
403  Option_String(const std::string& value, std::string typeName = "STR");
404 
405 
407  Option_String(const Option_String& s);
408 
409 
411  virtual ~Option_String();
412 
413 
416 
417 
422  std::string getString() const;
423 
424 
436  bool set(const std::string& v);
437 
438 
446  std::string getValueString() const;
447 
448 
449 protected:
451  std::string myValue;
452 
453 };
454 
455 
456 /* -------------------------------------------------------------------------
457  * Option_Float
458  * ----------------------------------------------------------------------- */
459 class Option_Float : public Option {
460 public:
465  Option_Float();
466 
467 
474  Option_Float(SUMOReal value);
475 
476 
478  Option_Float(const Option_Float& s);
479 
480 
482  ~Option_Float();
483 
484 
487 
488 
493  SUMOReal getFloat() const;
494 
495 
511  bool set(const std::string& v);
512 
513 
521  std::string getValueString() const;
522 
523 
524 private:
527 
528 };
529 
530 
531 /* -------------------------------------------------------------------------
532  * Option_Bool
533  * ----------------------------------------------------------------------- */
534 class Option_Bool : public Option {
535 public:
540  Option_Bool();
541 
542 
549  Option_Bool(bool value);
550 
551 
553  Option_Bool(const Option_Bool& s);
554 
555 
557  ~Option_Bool();
558 
559 
561  Option_Bool& operator=(const Option_Bool& s);
562 
563 
568  bool getBool() const;
569 
571  bool set(const std::string& v);
572 
573 
581  std::string getValueString() const;
582 
583 
591  bool isBool() const;
592 
593 
594 private:
596  bool myValue;
597 
598 };
599 
600 
601 /* -------------------------------------------------------------------------
602  * Option_FileName
603  * ----------------------------------------------------------------------- */
605 public:
608  Option_FileName();
609 
610 
615  Option_FileName(const std::string& value);
616 
617 
619  Option_FileName(const Option_String& s);
620 
621 
623  virtual ~Option_FileName();
624 
627 
628 
635  bool isFileName() const;
636 
637 
645  std::string getValueString() const;
646 
647 
648 };
649 
650 
651 /* -------------------------------------------------------------------------
652  * Option_IntVector
653  * ----------------------------------------------------------------------- */
654 class Option_IntVector : public Option {
655 public:
659 
660 
665  Option_IntVector(const IntVector& value);
666 
667 
670 
671 
673  virtual ~Option_IntVector();
674 
675 
678 
679 
684  const IntVector& getIntVector() const;
685 
686 
702  bool set(const std::string& v);
703 
704 
712  std::string getValueString() const;
713 
714 
715 private:
718 };
719 
720 
721 #endif
722 
723 /****************************************************************************/
724 
bool markSet()
Marks the information as set.
Definition: Option.cpp:116
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:80
bool myAmWritable
information whether the value may be changed
Definition: Option.h:298
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:133
virtual ~Option()
Definition: Option.cpp:64
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:104
std::string myValue
Definition: Option.h:451
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:110
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:175
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:181
bool myAmSet
information whether the value is set
Definition: Option.h:292
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:98
bool myValue
Definition: Option.h:596
void unSet()
marks this option as unset
Definition: Option.cpp:126
Option(bool set=false)
Constructor.
Definition: Option.cpp:55
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:163
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:68
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:48
const std::string & getDescription() const
Returns the description of what this option does.
Definition: Option.cpp:169
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:287
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:151
IntVector myValue
Definition: Option.h:717
A class representing a single program option.
Definition: Option.h:79
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:139
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:92
virtual SUMOReal getFloat() const
Returns the stored SUMOReal value.
Definition: Option.cpp:86
An integer-option.
Definition: Option.h:313
virtual std::string getValueString() const =0
Returns the string-representation of the value.
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:145
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:157
std::string myDescription
The description what this option does.
Definition: Option.h:301
SUMOReal myValue
Definition: Option.h:526
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:295
#define SUMOReal
Definition: config.h:213