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 /****************************************************************************/
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 // ===========================================================================
90 class OptionsCont {
91 public:
93  static OptionsCont& getOptions();
94 
95 
97  OptionsCont();
98 
99 
101  ~OptionsCont();
102 
103 
104 
107 
113  void setApplicationName(const std::string& appName, const std::string& fullName);
114 
115 
120  void setApplicationDescription(const std::string& appDesc);
121 
122 
128  void addCallExample(const std::string& example, const std::string& desc);
129 
130 
135  void setAdditionalHelpMessage(const std::string& add);
136 
137 
142  void addCopyrightNotice(const std::string& copyrightLine);
143 
144 
147  void clearCopyrightNotices();
148 
149 
158  void addOptionSubTopic(const std::string& topic);
159 
160 
165  void printHelp(std::ostream& os);
166 
172  void printHelpOnTopic(const std::string& topic, int tooLarge, int maxSize, std::ostream& os);
173 
185  void writeConfiguration(std::ostream& os, const bool filled,
186  const bool complete, const bool addComments,
187  const bool inComment = false) const;
188 
189 
197  void writeSchema(std::ostream& os);
198 
199 
208  void writeXMLHeader(std::ostream& os, const bool includeConfig = true) const;
210 
211 
212 
213 
216 
222  void doRegister(const std::string& name, Option* v);
223 
224 
234  void doRegister(const std::string& name, char abbr, Option* v);
235 
236 
253  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
254 
255 
261  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
262 
263 
277  void addDescription(const std::string& name, const std::string& subtopic,
278  const std::string& description);
280 
281 
282 
283 
286 
290  bool exists(const std::string& name) const;
291 
292 
308  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
309 
310 
315  void unSet(const std::string& name, bool failOnNonExistant = true) const;
316 
317 
331  bool isDefault(const std::string& name) const;
332 
333 
343  bool isBool(const std::string& name) const;
344 
345 
363  bool isUsableFileList(const std::string& name) const;
364 
365 
376  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
377 
378 
386  void relocateFiles(const std::string& configuration) const;
387 
388 
398  std::vector<std::string> getSynonymes(const std::string& name) const;
399 
406  const std::string& getDescription(const std::string& name) const;
407 
408 
420  bool isWriteable(const std::string& name);
422 
423 
424 
425 
428 
439  std::string getString(const std::string& name) const;
440 
441 
452  double getFloat(const std::string& name) const;
453 
454 
465  int getInt(const std::string& name) const;
466 
467 
478  bool getBool(const std::string& name) const;
479 
480 
491  const IntVector& getIntVector(const std::string& name) const;
492 
503  const FloatVector& getFloatVector(const std::string& name) const;
504 
505 
522  std::vector<std::string> getStringVector(const std::string& name) const;
523 
524 
542  bool isInStringVector(const std::string& optionName,
543  const std::string& itemName);
545 
546 
547 
548 
551 
571  bool set(const std::string& name, const std::string& value);
572 
592  bool setDefault(const std::string& name, const std::string& value);
593 
606  bool setByRootElement(const std::string& name, const std::string& value);
608 
609 
616  void resetWritable();
617 
626  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
627 
628 
630  void clear();
631 
632 
649  bool processMetaOptions(bool missingOptions);
650 
651 
653  const std::vector<std::string>& getSubTopics() const {
654  return mySubTopics;
655  }
656 
657 
659  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
660  if (mySubTopicEntries.count(subtopic) > 0) {
661  return mySubTopicEntries.find(subtopic)->second;
662  } else {
663  return std::vector<std::string>();
664  }
665  }
666 
667 
669  std::string getTypeName(const std::string name) {
670  return getSecure(name)->getTypeName();
671  }
672 
673 
674  inline const std::string& getFullName() const {
675  return myFullName;
676  }
677 
678 private:
686  Option* getSecure(const std::string& name) const;
687 
688 
696  void reportDoubleSetting(const std::string& arg) const;
697 
698 
706  std::string convertChar(char abbr) const;
707 
708 
720  void splitLines(std::ostream& os, std::string what,
721  int offset, int nextOffset);
722 
723 
724 private:
727 
729  typedef std::vector<Option*> ItemAddressContType;
730 
732  typedef std::map<std::string, Option*> KnownContType;
733 
736 
739 
742 
744  std::vector< std::pair<std::string, std::string> > myCallExamples;
745 
747  std::vector<std::string> mySubTopics, myCopyrightNotices;
748 
750  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
751 
753  std::map<std::string, std::string> myXMLDefaults;
754 
756  mutable std::map<std::string, bool> myDeprecatedSynonymes;
757 
760 
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 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:136
OptionsCont::myCopyrightNotices
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:747
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:756
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:216
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:561
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:230
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:389
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:273
OptionsCont::myHaveInformedAboutDeprecatedDivider
bool myHaveInformedAboutDeprecatedDivider
Information whether a warning a deprecated divider.
Definition: OptionsCont.h:759
OptionsCont::writeXMLHeader
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
Definition: OptionsCont.cpp:898
Option
A class representing a single program option.
Definition: Option.h:77
OptionsCont::getSynonymes
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
Definition: OptionsCont.cpp:285
OptionsCont::reportDoubleSetting
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
Definition: OptionsCont.cpp:412
OptionsCont::myFullName
std::string myFullName
Definition: OptionsCont.h:741
OptionsCont::relocateFiles
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
Definition: OptionsCont.cpp:338
OptionsCont::resetWritable
void resetWritable()
Resets all options to be writeable.
Definition: OptionsCont.cpp:445
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:244
OptionsCont::mySubTopics
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:747
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:202
OptionsCont::getFloatVector
const FloatVector & getFloatVector(const std::string &name) const
Returns the list of double-value of the named option (only for Option_FloatVector)
Definition: OptionsCont.cpp:237
OptionsCont::exists
bool exists(const std::string &name) const
Returns the information whether the named option is known.
Definition: OptionsCont.cpp:130
OptionsCont::getSubTopics
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:653
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:223
OptionsCont::myValues
KnownContType myValues
Definition: OptionsCont.h:738
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
OptionsCont::myAdditionalMessage
std::string myAdditionalMessage
Definition: OptionsCont.h:741
OptionsCont::unSet
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
Definition: OptionsCont.cpp:150
OptionsCont::getDescription
const std::string & getDescription(const std::string &name) const
Returns the option description.
Definition: OptionsCont.cpp:298
OptionsCont::printHelp
void printHelp(std::ostream &os)
Prints the help.
Definition: OptionsCont.cpp:661
OptionsCont::addCopyrightNotice
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
Definition: OptionsCont.cpp:511
OptionsCont::KnownContType
std::map< std::string, Option * > KnownContType
Definition: OptionsCont.h:732
OptionsCont::mySubTopicEntries
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:750
OptionsCont::myAddresses
ItemAddressContType myAddresses
Definition: OptionsCont.h:735
OptionsCont::operator<<
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
Definition: OptionsCont.cpp:304
OptionsCont::getFullName
const std::string & getFullName() const
Definition: OptionsCont.h:674
IntVector
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:41
Option::getTypeName
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:174
OptionsCont::convertChar
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
Definition: OptionsCont.cpp:428
OptionsCont::myCallExamples
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:744
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:473
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:360
OptionsCont::isInStringVector
bool isInStringVector(const std::string &optionName, const std::string &itemName)
Returns the named option is a list of string values containing the specified item.
Definition: OptionsCont.cpp:938
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:485
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:96
OptionsCont::myWriteLicense
bool myWriteLicense
Information whether we should always include license information in file headers.
Definition: OptionsCont.h:762
OptionsCont::doRegister
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
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:505
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
OptionsCont::ItemAddressContType
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:729
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:124
OptionsCont::isBool
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
Definition: OptionsCont.cpp:438
OptionsCont::isDefault
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Definition: OptionsCont.cpp:164
OptionsCont::splitLines
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
Definition: OptionsCont.cpp:530
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:523
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:493
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:209
OptionsCont::myAppName
std::string myAppName
some information on the application
Definition: OptionsCont.h:741
OptionsCont::myOptions
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:726
Option.h
OptionsCont::writeSchema
void writeSchema(std::ostream &os)
Writes the xml schema for the configuration.
Definition: OptionsCont.cpp:853
OptionsCont::addCallExample
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
Definition: OptionsCont.cpp:499
OptionsCont::getSecure
Option * getSecure(const std::string &name) const
Returns the named option.
Definition: OptionsCont.cpp:174
OptionsCont::printHelpOnTopic
void printHelpOnTopic(const std::string &topic, int tooLarge, int maxSize, std::ostream &os)
Prints help on the given topic.
Definition: OptionsCont.cpp:740
OptionsCont::getTypeName
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:669
OptionsCont::~OptionsCont
~OptionsCont()
Destructor.
Definition: OptionsCont.cpp:69
OptionsCont::clearCopyrightNotices
void clearCopyrightNotices()
Removes all copyright information.
Definition: OptionsCont.cpp:517
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:659
config.h
OptionsCont::OptionsCont
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:63
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:779
OptionsCont::isWriteable
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
Definition: OptionsCont.cpp:453
OptionsCont::myXMLDefaults
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:753
OptionsCont::clear
void clear()
Removes all information from the container.
Definition: OptionsCont.cpp:460
OptionsCont::getStringVector
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)
Definition: OptionsCont.cpp:921
FloatVector
std::vector< double > FloatVector
Definition of a vector of doubles.
Definition: Option.h:46
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:263
OptionsCont::myAppDescription
std::string myAppDescription
Definition: OptionsCont.h:741