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 
249 protected:
256  bool markSet();
257 
258 
259 protected:
267  Option(bool set = false);
268 
269 
271  Option(const Option& s);
272 
273 
275  virtual Option& operator=(const Option& s);
276 
277 
278 protected:
280  std::string myTypeName;
281 
282 
283 private:
285  bool myAmSet;
286 
289 
292 
294  std::string myDescription;
295 
296 };
297 
298 
299 /* -------------------------------------------------------------------------
300  * Option_Integer
301  * ----------------------------------------------------------------------- */
306 class Option_Integer : public Option {
307 public:
314  Option_Integer(int value);
315 
316 
318  Option_Integer(const Option_Integer& s);
319 
320 
322  ~Option_Integer();
323 
324 
327 
328 
333  int getInt() const;
334 
335 
351  bool set(const std::string& v);
352 
353 
361  std::string getValueString() const;
362 
363 
364 private:
366  int myValue;
367 
368 };
369 
370 
371 /* -------------------------------------------------------------------------
372  * Option_String
373  * ----------------------------------------------------------------------- */
374 class Option_String : public Option {
375 public:
380  Option_String();
381 
382 
389  Option_String(const std::string& value, std::string typeName = "STR");
390 
391 
393  Option_String(const Option_String& s);
394 
395 
397  virtual ~Option_String();
398 
399 
402 
403 
408  std::string getString() const;
409 
410 
422  bool set(const std::string& v);
423 
424 
432  std::string getValueString() const;
433 
434 
435 protected:
437  std::string myValue;
438 
439 };
440 
441 
442 /* -------------------------------------------------------------------------
443  * Option_Float
444  * ----------------------------------------------------------------------- */
445 class Option_Float : public Option {
446 public:
453  Option_Float(double value);
454 
455 
457  Option_Float(const Option_Float& s);
458 
459 
461  ~Option_Float();
462 
463 
466 
467 
472  double getFloat() const;
473 
474 
490  bool set(const std::string& v);
491 
492 
500  std::string getValueString() const;
501 
502 
503 private:
505  double myValue;
506 
507 };
508 
509 
510 /* -------------------------------------------------------------------------
511  * Option_Bool
512  * ----------------------------------------------------------------------- */
513 class Option_Bool : public Option {
514 public:
521  Option_Bool(bool value);
522 
523 
525  Option_Bool(const Option_Bool& s);
526 
527 
529  ~Option_Bool();
530 
531 
533  Option_Bool& operator=(const Option_Bool& s);
534 
535 
540  bool getBool() const;
541 
543  bool set(const std::string& v);
544 
545 
553  std::string getValueString() const;
554 
555 
563  bool isBool() const;
564 
565 
566 private:
568  bool myValue;
569 
570 };
571 
572 
573 /* -------------------------------------------------------------------------
574  * Option_FileName
575  * ----------------------------------------------------------------------- */
577 public:
580  Option_FileName();
581 
582 
587  Option_FileName(const std::string& value);
588 
589 
591  Option_FileName(const Option_String& s);
592 
593 
595  virtual ~Option_FileName();
596 
599 
600 
607  bool isFileName() const;
608 
609 
617  std::string getValueString() const;
618 
619 
620 };
621 
622 
623 /* -------------------------------------------------------------------------
624  * Option_IntVector
625  * ----------------------------------------------------------------------- */
626 class Option_IntVector : public Option {
627 public:
631 
632 
637  Option_IntVector(const IntVector& value);
638 
639 
642 
643 
645  virtual ~Option_IntVector();
646 
647 
650 
651 
656  const IntVector& getIntVector() const;
657 
658 
674  bool set(const std::string& v);
675 
676 
684  std::string getValueString() const;
685 
686 
687 private:
690 };
691 
692 
693 #endif
694 
695 /****************************************************************************/
696 
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:291
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:437
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:285
bool isWriteable() const
Returns the information whether the option may be set a further time.
Definition: Option.cpp:140
bool myValue
Definition: Option.h:568
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:280
virtual bool isFileName() const
Returns the information whether this option is a file name.
Definition: Option.cpp:134
double myValue
Definition: Option.h:505
IntVector myValue
Definition: Option.h:689
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:306
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:294
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:288