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-2019 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 // A storage for options (typed value containers)
18 /****************************************************************************/
19 #ifndef OptionsCont_h
20 #define OptionsCont_h
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
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 
438  std::string getString(const std::string& name) const;
439 
440 
451  double getFloat(const std::string& name) const;
452 
453 
464  int getInt(const std::string& name) const;
465 
466 
477  bool getBool(const std::string& name) const;
478 
479 
490  const IntVector& getIntVector(const std::string& name) const;
491 
507  const StringVector& getStringVector(const std::string& name) const;
508 
526  bool isInStringVector(const std::string& optionName,
527  const std::string& itemName) const;
529 
530 
531 
532 
535 
555  bool set(const std::string& name, const std::string& value);
556 
576  bool setDefault(const std::string& name, const std::string& value);
577 
590  bool setByRootElement(const std::string& name, const std::string& value);
592 
593 
600  void resetWritable();
601 
610  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
611 
612 
614  void clear();
615 
616 
633  bool processMetaOptions(bool missingOptions);
634 
635 
637  const std::vector<std::string>& getSubTopics() const {
638  return mySubTopics;
639  }
640 
641 
643  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
644  if (mySubTopicEntries.count(subtopic) > 0) {
645  return mySubTopicEntries.find(subtopic)->second;
646  } else {
647  return std::vector<std::string>();
648  }
649  }
650 
651 
653  std::string getTypeName(const std::string name) {
654  return getSecure(name)->getTypeName();
655  }
656 
657 
658  inline const std::string& getFullName() const {
659  return myFullName;
660  }
661 
662 private:
670  Option* getSecure(const std::string& name) const;
671 
672 
680  void reportDoubleSetting(const std::string& arg) const;
681 
682 
690  std::string convertChar(char abbr) const;
691 
692 
704  void splitLines(std::ostream& os, std::string what,
705  int offset, int nextOffset);
706 
707 
708 private:
711 
713  typedef std::vector<Option*> ItemAddressContType;
714 
716  typedef std::map<std::string, Option*> KnownContType;
717 
720 
723 
726 
728  std::vector< std::pair<std::string, std::string> > myCallExamples;
729 
731  std::vector<std::string> mySubTopics, myCopyrightNotices;
732 
734  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
735 
737  std::map<std::string, std::string> myXMLDefaults;
738 
740  mutable std::map<std::string, bool> myDeprecatedSynonymes;
741 
744 
745 
746 private:
748  OptionsCont(const OptionsCont& s);
749 
751  OptionsCont& operator=(const OptionsCont& s);
752 
753 };
754 
755 
756 #endif
757 
758 /****************************************************************************/
759 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
OptionsCont::myCopyrightNotices
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:731
OptionsCont::myDeprecatedSynonymes
std::map< std::string, bool > myDeprecatedSynonymes
A map from deprecated options to a bool indicating whether we warned about deprecation.
Definition: OptionsCont.h:740
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:215
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:557
OptionsCont::getIntVector
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector)
Definition: OptionsCont.cpp:229
OptionsCont::checkDependingSuboptions
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.
Definition: OptionsCont.cpp:385
OptionsCont::setByRootElement
bool setByRootElement(const std::string &name, const std::string &value)
Sets the given value for the option which can handle the given XML root.
Definition: OptionsCont.cpp:270
OptionsCont::writeXMLHeader
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
Definition: OptionsCont.cpp:897
Option
A class representing a single program option.
Definition: Option.h:75
OptionsCont::getSynonymes
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
Definition: OptionsCont.cpp:282
OptionsCont::reportDoubleSetting
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
Definition: OptionsCont.cpp:408
OptionsCont::myFullName
std::string myFullName
Definition: OptionsCont.h:725
OptionsCont::relocateFiles
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
Definition: OptionsCont.cpp:335
OptionsCont::resetWritable
void resetWritable()
Resets all options to be writeable.
Definition: OptionsCont.cpp:441
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:241
OptionsCont::mySubTopics
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:731
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
OptionsCont::exists
bool exists(const std::string &name) const
Returns the information whether the named option is known.
Definition: OptionsCont.cpp:129
OptionsCont::getSubTopics
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:637
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
OptionsCont::myValues
KnownContType myValues
Definition: OptionsCont.h:722
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
OptionsCont::myAdditionalMessage
std::string myAdditionalMessage
Definition: OptionsCont.h:725
OptionsCont::unSet
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
Definition: OptionsCont.cpp:149
OptionsCont::getDescription
const std::string & getDescription(const std::string &name) const
Returns the option description.
Definition: OptionsCont.cpp:295
OptionsCont::printHelp
void printHelp(std::ostream &os)
Prints the help.
Definition: OptionsCont.cpp:657
OptionsCont::addCopyrightNotice
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
Definition: OptionsCont.cpp:507
OptionsCont::KnownContType
std::map< std::string, Option * > KnownContType
Definition: OptionsCont.h:716
OptionsCont::mySubTopicEntries
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:734
OptionsCont::myAddresses
ItemAddressContType myAddresses
Definition: OptionsCont.h:719
OptionsCont::operator<<
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
Definition: OptionsCont.cpp:301
OptionsCont::getFullName
const std::string & getFullName() const
Definition: OptionsCont.h:658
IntVector
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:40
OptionsCont::getStringVector
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
Definition: OptionsCont.cpp:235
Option::getTypeName
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:173
OptionsCont::convertChar
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
Definition: OptionsCont.cpp:424
OptionsCont::myCallExamples
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:728
OptionsCont::addDescription
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
Definition: OptionsCont.cpp:469
OptionsCont::isUsableFileList
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
Definition: OptionsCont.cpp:356
StringVector
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:45
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:481
OptionsCont::addSynonyme
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:95
OptionsCont::myWriteLicense
bool myWriteLicense
Information whether we should always include license information in file headers.
Definition: OptionsCont.h:743
OptionsCont::doRegister
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:74
OptionsCont::isInStringVector
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.
Definition: OptionsCont.cpp:920
OptionsCont::setAdditionalHelpMessage
void setAdditionalHelpMessage(const std::string &add)
Sets an additional message to be printed at the begin of the help screen.
Definition: OptionsCont.cpp:501
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
OptionsCont::ItemAddressContType
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:713
OptionsCont::addXMLDefault
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.
Definition: OptionsCont.cpp:123
OptionsCont::isBool
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
Definition: OptionsCont.cpp:434
OptionsCont::isDefault
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Definition: OptionsCont.cpp:163
OptionsCont::splitLines
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
Definition: OptionsCont.cpp:526
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:519
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:489
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:208
OptionsCont::myAppName
std::string myAppName
some information on the application
Definition: OptionsCont.h:725
OptionsCont::myOptions
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:710
Option.h
OptionsCont::writeSchema
void writeSchema(std::ostream &os)
Writes the xml schema for the configuration.
Definition: OptionsCont.cpp:849
OptionsCont::addCallExample
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
Definition: OptionsCont.cpp:495
OptionsCont::getSecure
Option * getSecure(const std::string &name) const
Returns the named option.
Definition: OptionsCont.cpp:173
OptionsCont::printHelpOnTopic
void printHelpOnTopic(const std::string &topic, int tooLarge, int maxSize, std::ostream &os)
Prints help on the given topic.
Definition: OptionsCont.cpp:736
OptionsCont::getTypeName
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:653
OptionsCont::~OptionsCont
~OptionsCont()
Destructor.
Definition: OptionsCont.cpp:68
OptionsCont::clearCopyrightNotices
void clearCopyrightNotices()
Removes all copyright information.
Definition: OptionsCont.cpp:513
OptionsCont::operator=
OptionsCont & operator=(const OptionsCont &s)
OptionsCont::getSubTopicsEntries
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:643
config.h
OptionsCont::OptionsCont
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:62
OptionsCont::writeConfiguration
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const bool inComment=false) const
Writes the configuration.
Definition: OptionsCont.cpp:775
OptionsCont::isWriteable
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
Definition: OptionsCont.cpp:449
OptionsCont::myXMLDefaults
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:737
OptionsCont::clear
void clear()
Removes all information from the container.
Definition: OptionsCont.cpp:456
OptionsCont::setDefault
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
Definition: OptionsCont.cpp:260
OptionsCont::myAppDescription
std::string myAppDescription
Definition: OptionsCont.h:725