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 };
634 
635 
636 /* -------------------------------------------------------------------------
637  * Option_IntVector
638  * ----------------------------------------------------------------------- */
639 class Option_IntVector : public Option {
640 public:
644 
645 
650  Option_IntVector(const IntVector& value);
651 
652 
655 
656 
658  virtual ~Option_IntVector();
659 
660 
663 
664 
669  const IntVector& getIntVector() const;
670 
671 
687  bool set(const std::string& v);
688 
689 
697  std::string getValueString() const;
698 
699 
700 private:
703 };
704 
705 
706 #endif
707 
708 /****************************************************************************/
709 
Option_Float()
Constructor for an option with no default value.
Definition: Option.cpp:301
~Option_Bool()
Destructor.
Definition: Option.cpp:374
bool set(const std::string &v)
Stores the given value after parsing it into an integer.
Definition: Option.cpp:223
bool markSet()
Marks the information as set.
Definition: Option.cpp:115
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:79
Option_IntVector & operator=(const Option_IntVector &s)
Assignment operator.
Definition: Option.cpp:486
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:132
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:351
~Option_Float()
Destructor.
Definition: Option.cpp:313
virtual ~Option()
Definition: Option.cpp:63
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:103
std::string myValue
Definition: Option.h:447
Option_String & operator=(const Option_String &s)
Assignment operator.
Definition: Option.cpp:268
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:109
bool isFileName() const
Returns true, the information whether this option is a file name.
Definition: Option.cpp:457
bool set(const std::string &v)
Stores the given value after parsing it into a SUMOReal.
Definition: Option.cpp:340
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:168
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:174
SUMOReal getFloat() const
Returns the stored SUMOReal value.
Definition: Option.cpp:334
bool myAmSet
information whether the value is set
Definition: Option.h:288
std::string getString() const
Returns the stored string value.
Definition: Option.cpp:279
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:97
bool myValue
Definition: Option.h:592
void unSet()
marks this option as unset
Definition: Option.cpp:125
Option(bool set=false)
Constructor.
Definition: Option.cpp:54
virtual ~Option_IntVector()
Destructor.
Definition: Option.cpp:482
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:520
Option_FileName()
Constructor for an option with no default value.
Definition: Option.cpp:430
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:292
virtual ~Option_String()
Destructor.
Definition: Option.cpp:258
bool isBool() const
Returns true, the information whether the option is a bool option.
Definition: Option.cpp:421
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:67
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:162
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:283
Option_Integer()
Constructor for an option with no default value.
Definition: Option.cpp:184
Option_String()
Constructor for an option with no default value.
Definition: Option.cpp:246
int getInt() const
Returns the stored integer value.
Definition: Option.cpp:217
bool set(const std::string &v)
Stores the given value after parsing it into a vector of integers.
Definition: Option.cpp:500
Option_Bool()
Constructor for an option with no default value.
Definition: Option.cpp:362
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:150
Option_Bool & operator=(const Option_Bool &s)
Assignment operator.
Definition: Option.cpp:384
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:235
virtual bool set(const std::string &v)=0
Stores the given value (used for non-bool options)
~Option_Integer()
Destructor.
Definition: Option.cpp:196
IntVector myValue
Definition: Option.h:702
bool set(const std::string &v)
Stores the given value.
Definition: Option.cpp:285
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:138
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:91
virtual SUMOReal getFloat() const
Returns the stored SUMOReal value.
Definition: Option.cpp:85
bool set(const std::string &v)
Definition: Option.cpp:401
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:144
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:156
Option_IntVector()
Constructor for an option with no default value.
Definition: Option.cpp:466
std::string myDescription
The description what this option does.
Definition: Option.h:297
bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:395
virtual ~Option_FileName()
Destructor.
Definition: Option.cpp:446
Option_FileName & operator=(const Option_FileName &s)
Assignment operator.
Definition: Option.cpp:450
std::string getValueString() const
Returns the string-representation of the value.
Definition: Option.cpp:412
Option_Float & operator=(const Option_Float &s)
Assignment operator.
Definition: Option.cpp:323
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:218
const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:494
Option_Integer & operator=(const Option_Integer &s)
Assignment operator.
Definition: Option.cpp:206