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-2015 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 
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 
231  const std::string& getDescription() const;
232 
233 
240  void setDescription(const std::string& desc);
241 
242 
249  virtual const std::string& getTypeName() const;
250 
251 
252 protected:
259  bool markSet();
260 
261 
262 protected:
270  Option(bool set = false);
271 
272 
274  Option(const Option& s);
275 
276 
278  virtual Option& operator=(const Option& s);
279 
280 
281 protected:
283  std::string myTypeName;
284 
285 
286 private:
288  bool myAmSet;
289 
292 
295 
297  std::string myDescription;
298 
299 };
300 
301 
302 /* -------------------------------------------------------------------------
303  * Option_Integer
304  * ----------------------------------------------------------------------- */
309 class Option_Integer : public Option {
310 public:
315  Option_Integer();
316 
317 
324  Option_Integer(int value);
325 
326 
328  Option_Integer(const Option_Integer& s);
329 
330 
332  ~Option_Integer();
333 
334 
337 
338 
343  int getInt() const;
344 
345 
361  bool set(const std::string& v);
362 
363 
371  std::string getValueString() const;
372 
373 
374 private:
376  int myValue;
377 
378 };
379 
380 
381 /* -------------------------------------------------------------------------
382  * Option_String
383  * ----------------------------------------------------------------------- */
384 class Option_String : public Option {
385 public:
390  Option_String();
391 
392 
399  Option_String(const std::string& value, std::string typeName = "STR");
400 
401 
403  Option_String(const Option_String& s);
404 
405 
407  virtual ~Option_String();
408 
409 
412 
413 
418  std::string getString() const;
419 
420 
432  bool set(const std::string& v);
433 
434 
442  std::string getValueString() const;
443 
444 
445 protected:
447  std::string myValue;
448 
449 };
450 
451 
452 /* -------------------------------------------------------------------------
453  * Option_Float
454  * ----------------------------------------------------------------------- */
455 class Option_Float : public Option {
456 public:
461  Option_Float();
462 
463 
470  Option_Float(SUMOReal value);
471 
472 
474  Option_Float(const Option_Float& s);
475 
476 
478  ~Option_Float();
479 
480 
483 
484 
489  SUMOReal getFloat() const;
490 
491 
507  bool set(const std::string& v);
508 
509 
517  std::string getValueString() const;
518 
519 
520 private:
523 
524 };
525 
526 
527 /* -------------------------------------------------------------------------
528  * Option_Bool
529  * ----------------------------------------------------------------------- */
530 class Option_Bool : public Option {
531 public:
536  Option_Bool();
537 
538 
545  Option_Bool(bool value);
546 
547 
549  Option_Bool(const Option_Bool& s);
550 
551 
553  ~Option_Bool();
554 
555 
557  Option_Bool& operator=(const Option_Bool& s);
558 
559 
564  bool getBool() const;
565 
567  bool set(const std::string& v);
568 
569 
577  std::string getValueString() const;
578 
579 
587  bool isBool() const;
588 
589 
590 private:
592  bool myValue;
593 
594 };
595 
596 
597 /* -------------------------------------------------------------------------
598  * Option_FileName
599  * ----------------------------------------------------------------------- */
601 public:
604  Option_FileName();
605 
606 
611  Option_FileName(const std::string& value);
612 
613 
615  Option_FileName(const Option_String& s);
616 
617 
619  virtual ~Option_FileName();
620 
623 
624 
631  bool isFileName() const;
632 
633 
641  std::string getValueString() const;
642 
643 
644 };
645 
646 
647 /* -------------------------------------------------------------------------
648  * Option_IntVector
649  * ----------------------------------------------------------------------- */
650 class Option_IntVector : public Option {
651 public:
655 
656 
661  Option_IntVector(const IntVector& value);
662 
663 
666 
667 
669  virtual ~Option_IntVector();
670 
671 
674 
675 
680  const IntVector& getIntVector() const;
681 
682 
698  bool set(const std::string& v);
699 
700 
708  std::string getValueString() const;
709 
710 
711 private:
714 };
715 
716 
717 #endif
718 
719 /****************************************************************************/
720 
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:294
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:447
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:169
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:175
bool myAmSet
information whether the value is set
Definition: Option.h:288
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:98
bool myValue
Definition: Option.h:592
void unSet()
marks this option as unset
Definition: Option.cpp:126
Option(bool set=false)
Constructor.
Definition: Option.cpp:55
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:68
std::vector< int > IntVector
Definition of a vector of unsigned ints.
Definition: Option.h:48
const std::string & getDescription() const
Returns the description of what this option does.
Definition: Option.cpp:163
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:283
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:151
IntVector myValue
Definition: Option.h:713
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:309
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:297
SUMOReal myValue
Definition: Option.h:522
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:291
#define SUMOReal
Definition: config.h:214