Eclipse 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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // A storage for options (typed value containers)
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <map>
27 #include <string>
28 #include <vector>
29 #include <iostream>
30 #include "Option.h"
31 
32 
33 // ===========================================================================
34 // class definitions
35 // ===========================================================================
89 class OptionsCont {
90 public:
92  static OptionsCont& getOptions();
93 
94 
96  OptionsCont();
97 
98 
100  ~OptionsCont();
101 
102 
103 
106 
112  void setApplicationName(const std::string& appName, const std::string& fullName);
113 
114 
119  void setApplicationDescription(const std::string& appDesc);
120 
121 
127  void addCallExample(const std::string& example, const std::string& desc);
128 
129 
134  void setAdditionalHelpMessage(const std::string& add);
135 
136 
141  void addCopyrightNotice(const std::string& copyrightLine);
142 
143 
146  void clearCopyrightNotices();
147 
148 
157  void addOptionSubTopic(const std::string& topic);
158 
159 
164  void printHelp(std::ostream& os);
165 
171  void printHelpOnTopic(const std::string& topic, int tooLarge, int maxSize, std::ostream& os);
172 
184  void writeConfiguration(std::ostream& os, const bool filled,
185  const bool complete, const bool addComments,
186  const bool inComment = false) const;
187 
188 
196  void writeSchema(std::ostream& os);
197 
198 
207  void writeXMLHeader(std::ostream& os, const bool includeConfig = true) const;
209 
210 
211 
212 
215 
221  void doRegister(const std::string& name, Option* v);
222 
223 
233  void doRegister(const std::string& name, char abbr, Option* v);
234 
235 
252  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
253 
254 
260  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
261 
262 
276  void addDescription(const std::string& name, const std::string& subtopic,
277  const std::string& description);
279 
280 
281 
282 
285 
289  bool exists(const std::string& name) const;
290 
291 
307  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
308 
309 
314  void unSet(const std::string& name, bool failOnNonExistant = true) const;
315 
316 
330  bool isDefault(const std::string& name) const;
331 
332 
342  bool isBool(const std::string& name) const;
343 
344 
362  bool isUsableFileList(const std::string& name) const;
363 
364 
375  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
376 
377 
385  void relocateFiles(const std::string& configuration) const;
386 
387 
397  std::vector<std::string> getSynonymes(const std::string& name) const;
398 
405  const std::string& getDescription(const std::string& name) const;
406 
407 
419  bool isWriteable(const std::string& name);
421 
422 
423 
424 
427 
437  std::string getValueString(const std::string& name) const;
438 
449  std::string getString(const std::string& name) const;
450 
451 
462  double getFloat(const std::string& name) const;
463 
464 
475  int getInt(const std::string& name) const;
476 
477 
488  bool getBool(const std::string& name) const;
489 
490 
501  const IntVector& getIntVector(const std::string& name) const;
502 
518  const StringVector& getStringVector(const std::string& name) const;
519 
537  bool isInStringVector(const std::string& optionName,
538  const std::string& itemName) const;
540 
541 
542 
543 
546 
566  bool set(const std::string& name, const std::string& value);
567 
587  bool setDefault(const std::string& name, const std::string& value);
588 
601  bool setByRootElement(const std::string& name, const std::string& value);
603 
604 
611  void resetWritable();
612 
621  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
622 
623 
625  void clear();
626 
627 
644  bool processMetaOptions(bool missingOptions);
645 
646 
648  const std::vector<std::string>& getSubTopics() const {
649  return mySubTopics;
650  }
651 
652 
654  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
655  if (mySubTopicEntries.count(subtopic) > 0) {
656  return mySubTopicEntries.find(subtopic)->second;
657  } else {
658  return std::vector<std::string>();
659  }
660  }
661 
662 
664  std::string getTypeName(const std::string name) {
665  return getSecure(name)->getTypeName();
666  }
667 
668 
669  inline const std::string& getFullName() const {
670  return myFullName;
671  }
672 
673 private:
681  Option* getSecure(const std::string& name) const;
682 
683 
691  void reportDoubleSetting(const std::string& arg) const;
692 
693 
701  std::string convertChar(char abbr) const;
702 
703 
715  void splitLines(std::ostream& os, std::string what,
716  int offset, int nextOffset);
717 
718 
719 private:
722 
724  typedef std::vector<Option*> ItemAddressContType;
725 
727  typedef std::map<std::string, Option*> KnownContType;
728 
731 
734 
737 
739  std::vector< std::pair<std::string, std::string> > myCallExamples;
740 
742  std::vector<std::string> mySubTopics, myCopyrightNotices;
743 
745  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
746 
748  std::map<std::string, std::string> myXMLDefaults;
749 
751  mutable std::map<std::string, bool> myDeprecatedSynonymes;
752 
755 
756 
757 private:
760 
763 
764 };
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:43
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:38
A class representing a single program option.
Definition: Option.h:73
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:172
A storage for options typed value containers)
Definition: OptionsCont.h:89
void setAdditionalHelpMessage(const std::string &add)
Sets an additional message to be printed at the begin of the help screen.
~OptionsCont()
Destructor.
Definition: OptionsCont.cpp:69
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:739
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:745
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
OptionsCont(const OptionsCont &s)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const bool inComment=false) const
Writes the configuration.
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:724
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:654
void printHelpOnTopic(const std::string &topic, int tooLarge, int maxSize, std::ostream &os)
Prints help on the given topic.
const std::string & getFullName() const
Definition: OptionsCont.h:669
std::string myAdditionalMessage
Definition: OptionsCont.h:736
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:742
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector)
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:742
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool myWriteLicense
Information whether we should always include license information in file headers.
Definition: OptionsCont.h:754
ItemAddressContType myAddresses
Definition: OptionsCont.h:730
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
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
KnownContType myValues
Definition: OptionsCont.h:733
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:648
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:664
void writeSchema(std::ostream &os)
Writes the xml schema for the configuration.
void clear()
Removes all information from the container.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void clearCopyrightNotices()
Removes all copyright information.
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
OptionsCont & operator=(const OptionsCont &s)
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:63
void printHelp(std::ostream &os)
Prints the help.
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
std::string myAppDescription
Definition: OptionsCont.h:736
std::map< std::string, Option * > KnownContType
Definition: OptionsCont.h:727
const std::string & getDescription(const std::string &name) const
Returns the option description.
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:751
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:721
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.
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:748
std::string myAppName
some information on the application
Definition: OptionsCont.h:736
void resetWritable()
Resets all options to be writeable.
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.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
std::string myFullName
Definition: OptionsCont.h:736
Option * getSecure(const std::string &name) const
Returns the named option.
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
bool isInStringVector(const std::string &optionName, const std::string &itemName) const
Returns the named option is a list of string values containing the specified item.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.