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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Classes representing a single program option (with different types)
20 /****************************************************************************/
21 #ifndef Option_h
22 #define Option_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include <exception>
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
47 typedef std::vector<int> IntVector;
48 
49 
50 /* -------------------------------------------------------------------------
51  * Option
52  * ----------------------------------------------------------------------- */
78 class Option {
79 public:
81  virtual ~Option();
82 
83 
87  bool isSet() const;
88 
89 
92  void unSet();
93 
94 
103  virtual double getFloat() const;
104 
105 
114  virtual int getInt() const;
115 
116 
125  virtual std::string getString() const;
126 
127 
136  virtual bool getBool() const;
137 
138 
147  virtual const IntVector& getIntVector() const;
148 
149 
165  virtual bool set(const std::string& v) = 0;
166 
167 
174  virtual std::string getValueString() const = 0;
175 
176 
183  virtual bool isBool() const;
184 
185 
190  virtual bool isDefault() const;
191 
192 
199  virtual bool isFileName() const;
200 
201 
209  bool isWriteable() const;
210 
211 
217  void resetWritable();
218 
219 
225  void resetDefault();
226 
227 
234  const std::string& getDescription() const;
235 
236 
243  void setDescription(const std::string& desc);
244 
245 
252  virtual const std::string& getTypeName() const;
253 
254 
255 protected:
262  bool markSet();
263 
264 
265 protected:
273  Option(bool set = false);
274 
275 
277  Option(const Option& s);
278 
279 
281  virtual Option& operator=(const Option& s);
282 
283 
284 protected:
286  std::string myTypeName;
287 
288 
289 private:
291  bool myAmSet;
292 
295 
298 
300  std::string myDescription;
301 
302 };
303 
304 
305 /* -------------------------------------------------------------------------
306  * Option_Integer
307  * ----------------------------------------------------------------------- */
312 class Option_Integer : public Option {
313 public:
320  Option_Integer(int value);
321 
322 
324  Option_Integer(const Option_Integer& s);
325 
326 
328  ~Option_Integer();
329 
330 
333 
334 
339  int getInt() const;
340 
341 
357  bool set(const std::string& v);
358 
359 
367  std::string getValueString() const;
368 
369 
370 private:
372  int myValue;
373 
374 };
375 
376 
377 /* -------------------------------------------------------------------------
378  * Option_String
379  * ----------------------------------------------------------------------- */
380 class Option_String : public Option {
381 public:
386  Option_String();
387 
388 
395  Option_String(const std::string& value, std::string typeName = "STR");
396 
397 
399  Option_String(const Option_String& s);
400 
401 
403  virtual ~Option_String();
404 
405 
408 
409 
414  std::string getString() const;
415 
416 
428  bool set(const std::string& v);
429 
430 
438  std::string getValueString() const;
439 
440 
441 protected:
443  std::string myValue;
444 
445 };
446 
447 
448 /* -------------------------------------------------------------------------
449  * Option_Float
450  * ----------------------------------------------------------------------- */
451 class Option_Float : public Option {
452 public:
459  Option_Float(double value);
460 
461 
463  Option_Float(const Option_Float& s);
464 
465 
467  ~Option_Float();
468 
469 
472 
473 
478  double getFloat() const;
479 
480 
496  bool set(const std::string& v);
497 
498 
506  std::string getValueString() const;
507 
508 
509 private:
511  double myValue;
512 
513 };
514 
515 
516 /* -------------------------------------------------------------------------
517  * Option_Bool
518  * ----------------------------------------------------------------------- */
519 class Option_Bool : public Option {
520 public:
527  Option_Bool(bool value);
528 
529 
531  Option_Bool(const Option_Bool& s);
532 
533 
535  ~Option_Bool();
536 
537 
539  Option_Bool& operator=(const Option_Bool& s);
540 
541 
546  bool getBool() const;
547 
549  bool set(const std::string& v);
550 
551 
559  std::string getValueString() const;
560 
561 
569  bool isBool() const;
570 
571 
572 private:
574  bool myValue;
575 
576 };
577 
578 
579 /* -------------------------------------------------------------------------
580  * Option_FileName
581  * ----------------------------------------------------------------------- */
583 public:
586  Option_FileName();
587 
588 
593  Option_FileName(const std::string& value);
594 
595 
597  Option_FileName(const Option_String& s);
598 
599 
601  virtual ~Option_FileName();
602 
605 
606 
613  bool isFileName() const;
614 
615 
623  std::string getValueString() const;
624 
625 
626 };
627 
628 
629 /* -------------------------------------------------------------------------
630  * Option_IntVector
631  * ----------------------------------------------------------------------- */
632 class Option_IntVector : public Option {
633 public:
637 
638 
643  Option_IntVector(const IntVector& value);
644 
645 
648 
649 
651  virtual ~Option_IntVector();
652 
653 
656 
657 
662  const IntVector& getIntVector() const;
663 
664 
680  bool set(const std::string& v);
681 
682 
690  std::string getValueString() const;
691 
692 
693 private:
696 };
697 
698 
699 #endif
700 
701 /****************************************************************************/
702 
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:81
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:105
bool markSet()
Marks the information as set.
Definition: Option.cpp:111
bool myAmWritable
information whether the value may be changed
Definition: Option.h:297
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:93
virtual ~Option()
Definition: Option.cpp:59
std::string myValue
Definition: Option.h:443
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:170
bool myAmSet
information whether the value is set
Definition: Option.h:291
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:146
bool myValue
Definition: Option.h:574
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:87
void unSet()
marks this option as unset
Definition: Option.cpp:121
Option(bool set=false)
Constructor.
Definition: Option.cpp:50
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:158
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:63
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:47
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:286
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:140
double myValue
Definition: Option.h:511
IntVector myValue
Definition: Option.h:695
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:128
A class representing a single program option.
Definition: Option.h:78
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:99
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:134
An integer-option.
Definition: Option.h:312
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:164
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:152
std::string myDescription
The description what this option does.
Definition: Option.h:300
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:75
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:176
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:294