SUMO - Simulation of Urban MObility
OptionsCont.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 /****************************************************************************/
18 // A storage for options (typed value containers)
19 /****************************************************************************/
20 #ifndef OptionsCont_h
21 #define OptionsCont_h
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <map>
28 #include <string>
29 #include <vector>
30 #include <iostream>
31 #include "Option.h"
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
92 class OptionsCont {
93 public:
95  static OptionsCont& getOptions();
96 
97 
99  OptionsCont();
100 
101 
103  ~OptionsCont();
104 
105 
106 
109 
115  void setApplicationName(const std::string& appName, const std::string& fullName);
116 
117 
122  void setApplicationDescription(const std::string& appDesc);
123 
124 
130  void addCallExample(const std::string& example, const std::string& desc);
131 
132 
137  void setAdditionalHelpMessage(const std::string& add);
138 
139 
144  void addCopyrightNotice(const std::string& copyrightLine);
145 
146 
149  void clearCopyrightNotices();
150 
151 
160  void addOptionSubTopic(const std::string& topic);
161 
162 
167  void printHelp(std::ostream& os);
168 
169 
181  void writeConfiguration(std::ostream& os, const bool filled,
182  const bool complete, const bool addComments,
183  const bool inComment = false) const;
184 
185 
193  void writeSchema(std::ostream& os);
194 
195 
204  void writeXMLHeader(std::ostream& os, const bool includeConfig = true) const;
206 
207 
208 
209 
212 
218  void doRegister(const std::string& name, Option* v);
219 
220 
230  void doRegister(const std::string& name, char abbr, Option* v);
231 
232 
249  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
250 
251 
257  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
258 
259 
273  void addDescription(const std::string& name, const std::string& subtopic,
274  const std::string& description);
276 
277 
278 
279 
282 
286  bool exists(const std::string& name) const;
287 
288 
304  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
305 
306 
311  void unSet(const std::string& name, bool failOnNonExistant = true) const;
312 
313 
327  bool isDefault(const std::string& name) const;
328 
329 
339  bool isBool(const std::string& name) const;
340 
341 
359  bool isUsableFileList(const std::string& name) const;
360 
361 
372  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
373 
374 
382  void relocateFiles(const std::string& configuration) const;
383 
384 
394  std::vector<std::string> getSynonymes(const std::string& name) const;
395 
402  const std::string& getDescription(const std::string& name) const;
403 
404 
416  bool isWriteable(const std::string& name);
418 
419 
420 
421 
424 
435  std::string getString(const std::string& name) const;
436 
437 
448  double getFloat(const std::string& name) const;
449 
450 
461  int getInt(const std::string& name) const;
462 
463 
474  bool getBool(const std::string& name) const;
475 
476 
487  const IntVector& getIntVector(const std::string& name) const;
488 
499  const FloatVector& getFloatVector(const std::string& name) const;
500 
501 
518  std::vector<std::string> getStringVector(const std::string& name) const;
519 
520 
538  bool isInStringVector(const std::string& optionName,
539  const std::string& itemName);
541 
542 
543 
544 
547 
567  bool set(const std::string& name, const std::string& value);
568 
588  bool setDefault(const std::string& name, const std::string& value);
589 
602  bool setByRootElement(const std::string& name, const std::string& value);
604 
605 
612  void resetWritable();
613 
622  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
623 
624 
626  void clear();
627 
628 
645  bool processMetaOptions(bool missingOptions);
646 
647 
649  const std::vector<std::string>& getSubTopics() const {
650  return mySubTopics;
651  }
652 
653 
655  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
656  if (mySubTopicEntries.count(subtopic) > 0) {
657  return mySubTopicEntries.find(subtopic)->second;
658  } else {
659  return std::vector<std::string>();
660  }
661  }
662 
663 
665  std::string getTypeName(const std::string name) {
666  return getSecure(name)->getTypeName();
667  }
668 
669 
670  inline const std::string& getFullName() const {
671  return myFullName;
672  }
673 
674 private:
682  Option* getSecure(const std::string& name) const;
683 
684 
692  void reportDoubleSetting(const std::string& arg) const;
693 
694 
702  std::string convertChar(char abbr) const;
703 
704 
716  void splitLines(std::ostream& os, std::string what,
717  int offset, int nextOffset);
718 
719 
720 private:
723 
725  typedef std::vector<Option*> ItemAddressContType;
726 
728  typedef std::map<std::string, Option*> KnownContType;
729 
731  ItemAddressContType myAddresses;
732 
734  KnownContType myValues;
735 
738 
740  std::vector< std::pair<std::string, std::string> > myCallExamples;
741 
743  std::vector<std::string> mySubTopics, myCopyrightNotices;
744 
746  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
747 
749  std::map<std::string, std::string> myXMLDefaults;
750 
752  mutable std::map<std::string, bool> myDeprecatedSynonymes;
753 
756 
759 
760 
761 private:
763  OptionsCont(const OptionsCont& s);
764 
766  OptionsCont& operator=(const OptionsCont& s);
767 
768 };
769 
770 
771 #endif
772 
773 /****************************************************************************/
774 
std::string myAppName
some information on the application
Definition: OptionsCont.h:737
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:743
std::string myFullName
Definition: OptionsCont.h:737
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void resetWritable()
Resets all options to be writeable.
std::vector< double > FloatVector
Definition of a vector of doubles.
Definition: Option.h:46
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.
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:649
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:725
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void clearCopyrightNotices()
Removes all copyright information.
void printHelp(std::ostream &os)
Prints the help.
bool myHaveInformedAboutDeprecatedDivider
Information whether a warning a deprecated divider.
Definition: OptionsCont.h:755
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string &#39;formatted&#39;.
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:722
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:749
const FloatVector & getFloatVector(const std::string &name) const
Returns the list of double-value of the named option (only for Option_FloatVector) ...
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const bool inComment=false) const
Writes the configuration.
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:665
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
Definition: OptionsCont.cpp:96
std::string myAppDescription
Definition: OptionsCont.h:737
ItemAddressContType myAddresses
Definition: OptionsCont.h:731
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
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:752
void clear()
Removes all information from the container.
std::string myAdditionalMessage
Definition: OptionsCont.h:737
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:41
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 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.
Option * getSecure(const std::string &name) const
Returns the named option.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
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) ...
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
~OptionsCont()
Destructor.
Definition: OptionsCont.cpp:69
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.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
const std::string & getDescription(const std::string &name) const
Returns the option description.
A class representing a single program option.
Definition: Option.h:77
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. ...
bool myWriteLicense
Information whether we should always include license information in file headers. ...
Definition: OptionsCont.h:758
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
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:734
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector) ...
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:655
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:746
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:174
A storage for options typed value containers)
Definition: OptionsCont.h:92
void writeSchema(std::ostream &os)
Writes the xml schema for the configuration.
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:743
const std::string & getFullName() const
Definition: OptionsCont.h:670
OptionsCont & operator=(const OptionsCont &s)
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
std::map< std::string, Option * > KnownContType
Definition: OptionsCont.h:728
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:63
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:740
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.