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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Classes representing a single program option (with different types)
18 /****************************************************************************/
19 #ifndef Option_h
20 #define Option_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <exception>
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
41 typedef std::vector<int> IntVector;
42 
43 
44 /* -------------------------------------------------------------------------
45  * Option
46  * ----------------------------------------------------------------------- */
72 class Option {
73 public:
75  virtual ~Option();
76 
77 
81  bool isSet() const;
82 
83 
86  void unSet();
87 
88 
97  virtual double getFloat() const;
98 
99 
108  virtual int getInt() const;
109 
110 
119  virtual std::string getString() const;
120 
121 
130  virtual bool getBool() const;
131 
132 
141  virtual const IntVector& getIntVector() const;
142 
143 
159  virtual bool set(const std::string& v) = 0;
160 
161 
168  virtual std::string getValueString() const = 0;
169 
170 
177  virtual bool isBool() const;
178 
179 
184  virtual bool isDefault() const;
185 
186 
193  virtual bool isFileName() const;
194 
195 
203  bool isWriteable() const;
204 
205 
211  void resetWritable();
212 
213 
219  void resetDefault();
220 
221 
228  const std::string& getDescription() const;
229 
230 
237  void setDescription(const std::string& desc);
238 
239 
246  virtual const std::string& getTypeName() const;
247 
248 
253  template<class OptionType, class ValueType>
254  static OptionType* makeUnsetWithDefault(ValueType def) {
255  OptionType* o = new OptionType(def);
256  o->unSet();
257  return o;
258  }
259 
260 
261 protected:
268  bool markSet();
269 
270 
271 protected:
279  Option(bool set = false);
280 
281 
283  Option(const Option& s);
284 
285 
287  virtual Option& operator=(const Option& s);
288 
289 
290 protected:
292  std::string myTypeName;
293 
294 
295 private:
297  bool myAmSet;
298 
301 
304 
306  std::string myDescription;
307 
308 };
309 
310 
311 /* -------------------------------------------------------------------------
312  * Option_Integer
313  * ----------------------------------------------------------------------- */
318 class Option_Integer : public Option {
319 public:
326  Option_Integer(int value);
327 
328 
330  Option_Integer(const Option_Integer& s);
331 
332 
334  ~Option_Integer();
335 
336 
339 
340 
345  int getInt() const;
346 
347 
363  bool set(const std::string& v);
364 
365 
373  std::string getValueString() const;
374 
375 
376 private:
378  int myValue;
379 
380 };
381 
382 
383 /* -------------------------------------------------------------------------
384  * Option_String
385  * ----------------------------------------------------------------------- */
386 class Option_String : public Option {
387 public:
392  Option_String();
393 
394 
401  Option_String(const std::string& value, std::string typeName = "STR");
402 
403 
405  Option_String(const Option_String& s);
406 
407 
409  virtual ~Option_String();
410 
411 
414 
415 
420  std::string getString() const;
421 
422 
434  bool set(const std::string& v);
435 
436 
444  std::string getValueString() const;
445 
446 
447 protected:
449  std::string myValue;
450 
451 };
452 
453 
454 /* -------------------------------------------------------------------------
455  * Option_Float
456  * ----------------------------------------------------------------------- */
457 class Option_Float : public Option {
458 public:
465  Option_Float(double value);
466 
467 
469  Option_Float(const Option_Float& s);
470 
471 
473  ~Option_Float();
474 
475 
478 
479 
484  double getFloat() const;
485 
486 
502  bool set(const std::string& v);
503 
504 
512  std::string getValueString() const;
513 
514 
515 private:
517  double myValue;
518 
519 };
520 
521 
522 /* -------------------------------------------------------------------------
523  * Option_Bool
524  * ----------------------------------------------------------------------- */
525 class Option_Bool : public Option {
526 public:
533  Option_Bool(bool value);
534 
535 
537  Option_Bool(const Option_Bool& s);
538 
539 
541  ~Option_Bool();
542 
543 
545  Option_Bool& operator=(const Option_Bool& s);
546 
547 
552  bool getBool() const;
553 
555  bool set(const std::string& v);
556 
557 
565  std::string getValueString() const;
566 
567 
575  bool isBool() const;
576 
577 
578 private:
580  bool myValue;
581 
582 };
583 
584 
585 /* -------------------------------------------------------------------------
586  * Option_FileName
587  * ----------------------------------------------------------------------- */
589 public:
592  Option_FileName();
593 
594 
599  Option_FileName(const std::string& value);
600 
601 
603  Option_FileName(const Option_String& s);
604 
605 
607  virtual ~Option_FileName();
608 
611 
612 
619  bool isFileName() const;
620 
621 
629  std::string getValueString() const;
630 
631 
632 };
633 
634 
635 /* -------------------------------------------------------------------------
636  * Option_IntVector
637  * ----------------------------------------------------------------------- */
638 class Option_IntVector : public Option {
639 public:
643 
644 
649  Option_IntVector(const IntVector& value);
650 
651 
654 
655 
657  virtual ~Option_IntVector();
658 
659 
662 
663 
668  const IntVector& getIntVector() const;
669 
670 
686  bool set(const std::string& v);
687 
688 
696  std::string getValueString() const;
697 
698 
699 private:
702 };
703 
704 
705 #endif
706 
707 /****************************************************************************/
708 
virtual double getFloat() const
Returns the stored double value.
Definition: Option.cpp:75
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
Definition: Option.cpp:99
bool markSet()
Marks the information as set.
Definition: Option.cpp:105
bool myAmWritable
information whether the value may be changed
Definition: Option.h:303
virtual std::string getString() const
Returns the stored string value.
Definition: Option.cpp:87
virtual ~Option()
Definition: Option.cpp:53
std::string myValue
Definition: Option.h:449
void setDescription(const std::string &desc)
Sets the description of what this option does.
Definition: Option.cpp:164
bool myAmSet
information whether the value is set
Definition: Option.h:297
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:140
bool myValue
Definition: Option.h:580
virtual int getInt() const
Returns the stored integer value.
Definition: Option.cpp:81
void unSet()
marks this option as unset
Definition: Option.cpp:115
Option(bool set=false)
Constructor.
Definition: Option.cpp:44
void resetDefault()
Resets the option to be on its default value.
Definition: Option.cpp:152
virtual Option & operator=(const Option &s)
Assignment operator.
Definition: Option.cpp:57
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:41
std::string myTypeName
A type name for this option (has presets, but may be overwritten)
Definition: Option.h:292
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:134
double myValue
Definition: Option.h:517
IntVector myValue
Definition: Option.h:701
virtual bool isBool() const
Returns the information whether the option is a bool option.
Definition: Option.cpp:122
A class representing a single program option.
Definition: Option.h:72
virtual bool getBool() const
Returns the stored boolean value.
Definition: Option.cpp:93
virtual bool isDefault() const
Returns the information whether the option holds the default value.
Definition: Option.cpp:128
An integer-option.
Definition: Option.h:318
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:158
void resetWritable()
Resets the option to be writeable.
Definition: Option.cpp:146
std::string myDescription
The description what this option does.
Definition: Option.h:306
bool isSet() const
returns the information whether this options holds a valid value
Definition: Option.cpp:69
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:170
bool myHaveTheDefaultValue
information whether the value is the default value (is then set)
Definition: Option.h:300
static OptionType * makeUnsetWithDefault(ValueType def)
Create a new Option of the given type with given default value but make it unset. ...
Definition: Option.h:254