SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OptionsCont.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // A storage for options (typed value containers)
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef OptionsCont_h
24 #define OptionsCont_h
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 <map>
35 #include <string>
36 #include <vector>
37 #include <iostream>
38 #include "Option.h"
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
99 class OptionsCont {
100 public:
102  static OptionsCont& getOptions();
103 
104 
106  OptionsCont();
107 
108 
110  ~OptionsCont();
111 
112 
113 
116 
122  void setApplicationName(const std::string& appName, const std::string& fullName);
123 
124 
129  void setApplicationDescription(const std::string& appDesc);
130 
131 
137  void addCallExample(const std::string& example, const std::string& desc);
138 
139 
144  void setAdditionalHelpMessage(const std::string& add);
145 
146 
151  void addCopyrightNotice(const std::string& copyrightLine);
152 
153 
156  void clearCopyrightNotices();
157 
158 
167  void addOptionSubTopic(const std::string& topic);
168 
169 
174  void printHelp(std::ostream& os);
175 
176 
187  void writeConfiguration(std::ostream& os, bool filled,
188  bool complete, bool addComments) const;
189 
190 
199  void writeSchema(std::ostream& os, bool addComments);
200 
201 
210  void writeXMLHeader(std::ostream& os);
212 
213 
214 
215 
218 
224  void doRegister(const std::string& name, Option* v);
225 
226 
236  void doRegister(const std::string& name, char abbr, Option* v);
237 
238 
255  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
256 
257 
263  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
264 
265 
279  void addDescription(const std::string& name, const std::string& subtopic,
280  const std::string& description);
282 
283 
284 
285 
288 
292  bool exists(const std::string& name) const;
293 
294 
310  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
311 
312 
317  void unSet(const std::string& name, bool failOnNonExistant = true) const;
318 
319 
333  bool isDefault(const std::string& name) const;
334 
335 
345  bool isBool(const std::string& name) const;
346 
347 
365  bool isUsableFileList(const std::string& name) const;
366 
367 
378  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
379 
380 
388  void relocateFiles(const std::string& configuration) const;
389 
390 
400  std::vector<std::string> getSynonymes(const std::string& name) const;
401 
402 
414  bool isWriteable(const std::string& name);
416 
417 
418 
419 
422 
433  std::string getString(const std::string& name) const;
434 
435 
446  SUMOReal getFloat(const std::string& name) const;
447 
448 
459  int getInt(const std::string& name) const;
460 
461 
472  bool getBool(const std::string& name) const;
473 
474 
485  const IntVector& getIntVector(const std::string& name) const;
486 
487 
504  std::vector<std::string> getStringVector(const std::string& name) const;
505 
506 
524  bool isInStringVector(const std::string& optionName,
525  const std::string& itemName);
527 
528 
529 
530 
533 
553  bool set(const std::string& name, const std::string& value);
554 
574  bool setDefault(const std::string& name, const std::string& value);
575 
588  bool setByRootElement(const std::string& name, const std::string& value);
590 
591 
598  void resetWritable();
599 
608  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
609 
610 
612  void clear();
613 
614 
631  bool processMetaOptions(bool missingOptions);
632 
633 
635  const std::vector<std::string>& getSubTopics() const {
636  return mySubTopics;
637  }
638 
639 
641  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
642  if (mySubTopicEntries.count(subtopic) > 0) {
643  return mySubTopicEntries.find(subtopic)->second;
644  } else {
645  return std::vector<std::string>();
646  }
647  }
648 
649 
651  std::string getTypeName(const std::string name) {
652  return getSecure(name)->getTypeName();
653  }
654 
655 
656  inline const std::string& getFullName() const {
657  return myFullName;
658  }
659 
660 private:
668  Option* getSecure(const std::string& name) const;
669 
670 
678  void reportDoubleSetting(const std::string& arg) const;
679 
680 
688  std::string convertChar(char abbr) const;
689 
690 
702  void splitLines(std::ostream& os, std::string what,
703  int offset, int nextOffset);
704 
705 
706 private:
709 
711  typedef std::vector<Option*> ItemAddressContType;
712 
714  typedef std::map<std::string, Option*> KnownContType;
715 
717  ItemAddressContType myAddresses;
718 
720  KnownContType myValues;
721 
724 
726  std::vector< std::pair<std::string, std::string> > myCallExamples;
727 
729  std::vector<std::string> mySubTopics, myCopyrightNotices;
730 
732  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
733 
735  std::map<std::string, std::string> myXMLDefaults;
736 
738  mutable std::map<std::string, bool> myDeprecatedSynonymes;
739 
742 
743 
744 private:
750  public:
752  explicit abbreviation_finder() { }
753 
759  bool operator()(const std::string& s) {
760  return s.length() == 1;
761  }
762  };
763 
764 
765 private:
767  OptionsCont(const OptionsCont& s);
768 
770  OptionsCont& operator=(const OptionsCont& s);
771 
772 };
773 
774 
775 #endif
776 
777 /****************************************************************************/
778 
std::string myAppName
some information on the application
Definition: OptionsCont.h:723
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:86
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:729
std::string myFullName
Definition: OptionsCont.h:723
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:635
void resetWritable()
Resets all options to be writeable.
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
bool isInStringVector(const std::string &optionName, const std::string &itemName)
Returns the named option is a list of string values containing the specified item.
bool checkDependingSuboptions(const std::string &name, const std::string &prefix) const
Checks whether an option is set, which has options with a prefix depending on it. ...
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:711
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void clearCopyrightNotices()
Removes all copyright information.
void printHelp(std::ostream &os)
Prints the help.
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector) ...
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool myHaveInformedAboutDeprecatedDivider
Information whether a warning a deprecated divider.
Definition: OptionsCont.h:741
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:181
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:708
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
const std::string & getFullName() const
Definition: OptionsCont.h:656
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:735
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:651
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::string myAppDescription
Definition: OptionsCont.h:723
ItemAddressContType myAddresses
Definition: OptionsCont.h:717
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool setByRootElement(const std::string &name, const std::string &value)
Sets the given value for the option which can handle the given XML root.
std::map< std::string, bool > myDeprecatedSynonymes
A map from deprecated options to a bool indicating whether we warned about deprecation.
Definition: OptionsCont.h:738
void clear()
Removes all information from the container.
void writeXMLHeader(std::ostream &os)
Writes a standard XML header, including the configuration.
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
std::string myAdditionalMessage
Definition: OptionsCont.h:723
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:48
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
void setAdditionalHelpMessage(const std::string &add)
Sets an additional message to be printed at the begin of the help screen.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file) ...
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
~OptionsCont()
Destructor.
Definition: OptionsCont.cpp:80
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void writeSchema(std::ostream &os, bool addComments)
Writes the xml schema for the configuration.
A class to find abbreviated option names (length=1)
Definition: OptionsCont.h:749
A class representing a single program option.
Definition: Option.h:79
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
void addXMLDefault(const std::string &name, const std::string &xmlRoot="")
Adds an XML root element to handle by default. The special root "" denotes the default handler...
KnownContType myValues
Definition: OptionsCont.h:720
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:732
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
A storage for options typed value containers)
Definition: OptionsCont.h:99
Option * getSecure(const std::string &name) const
Returns the named option.
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:729
#define SUMOReal
Definition: config.h:214
void writeConfiguration(std::ostream &os, bool filled, bool complete, bool addComments) const
Writes the configuration.
OptionsCont & operator=(const OptionsCont &s)
bool operator()(const std::string &s)
The comparing function.
Definition: OptionsCont.h:759
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:641
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::map< std::string, Option * > KnownContType
Definition: OptionsCont.h:714
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:74
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:726
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.