SUMO - Simulation of Urban MObility
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 // compiler pragmas
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #pragma warning(disable: 4786)
30 #pragma warning(disable: 4503)
31 #endif
32 
33 
34 // ===========================================================================
35 // included modules
36 // ===========================================================================
37 #ifdef _MSC_VER
38 #include <windows_config.h>
39 #else
40 #include <config.h>
41 #endif
42 
43 #include <map>
44 #include <string>
45 #include <vector>
46 #include <iostream>
47 #include "Option.h"
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
108 class OptionsCont {
109 public:
111  static OptionsCont& getOptions();
112 
113 
115  OptionsCont();
116 
117 
119  ~OptionsCont();
120 
121 
122 
125 
131  void setApplicationName(const std::string& appName, const std::string& fullName);
132 
133 
138  void setApplicationDescription(const std::string& appDesc);
139 
140 
146  void addCallExample(const std::string& example, const std::string& desc);
147 
148 
153  void setAdditionalHelpMessage(const std::string& add);
154 
155 
160  void addCopyrightNotice(const std::string& copyrightLine);
161 
162 
165  void clearCopyrightNotices();
166 
167 
176  void addOptionSubTopic(const std::string& topic);
177 
178 
183  void printHelp(std::ostream& os);
184 
185 
196  void writeConfiguration(std::ostream& os, bool filled,
197  bool complete, bool addComments) const;
198 
199 
208  void writeSchema(std::ostream& os, bool addComments);
209 
210 
219  void writeXMLHeader(std::ostream& os);
221 
222 
223 
224 
227 
233  void doRegister(const std::string& name, Option* v);
234 
235 
245  void doRegister(const std::string& name, char abbr, Option* v);
246 
247 
264  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
265 
266 
272  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
273 
274 
288  void addDescription(const std::string& name, const std::string& subtopic,
289  const std::string& description);
291 
292 
293 
294 
297 
301  bool exists(const std::string& name) const;
302 
303 
319  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
320 
321 
326  void unSet(const std::string& name, bool failOnNonExistant = true) const;
327 
328 
342  bool isDefault(const std::string& name) const;
343 
344 
354  bool isBool(const std::string& name) const;
355 
356 
374  bool isUsableFileList(const std::string& name) const;
375 
376 
387  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
388 
389 
397  void relocateFiles(const std::string& configuration) const;
398 
399 
409  std::vector<std::string> getSynonymes(const std::string& name) const;
410 
411 
423  bool isWriteable(const std::string& name);
425 
426 
427 
428 
431 
442  std::string getString(const std::string& name) const;
443 
444 
455  SUMOReal getFloat(const std::string& name) const;
456 
457 
468  int getInt(const std::string& name) const;
469 
470 
481  bool getBool(const std::string& name) const;
482 
483 
494  const IntVector& getIntVector(const std::string& name) const;
495 
496 
513  std::vector<std::string> getStringVector(const std::string& name) const;
514 
515 
533  bool isInStringVector(const std::string& optionName,
534  const std::string& itemName);
536 
537 
538 
539 
542 
562  bool set(const std::string& name, const std::string& value);
563 
583  bool setDefault(const std::string& name, const std::string& value);
584 
597  bool setByRootElement(const std::string& name, const std::string& value);
599 
600 
607  void resetWritable();
608 
617  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
618 
619 
621  void clear();
622 
623 
640  bool processMetaOptions(bool missingOptions);
641 
642 
644  const std::vector<std::string>& getSubTopics() const {
645  return mySubTopics;
646  }
647 
648 
650  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
651  if (mySubTopicEntries.count(subtopic) > 0) {
652  return mySubTopicEntries.find(subtopic)->second;
653  } else {
654  return std::vector<std::string>();
655  }
656  }
657 
658 
660  std::string getTypeName(const std::string name) {
661  return getSecure(name)->getTypeName();
662  }
663 
664 
665  inline const std::string& getFullName() const {
666  return myFullName;
667  }
668 
669 private:
677  Option* getSecure(const std::string& name) const;
678 
679 
687  void reportDoubleSetting(const std::string& arg) const;
688 
689 
697  std::string convertChar(char abbr) const;
698 
699 
711  void splitLines(std::ostream& os, std::string what,
712  size_t offset, size_t nextOffset);
713 
714 
715 private:
718 
720  typedef std::vector<Option*> ItemAddressContType;
721 
723  typedef std::map<std::string, Option*> KnownContType;
724 
726  ItemAddressContType myAddresses;
727 
729  KnownContType myValues;
730 
733 
735  std::vector< std::pair<std::string, std::string> > myCallExamples;
736 
738  std::vector<std::string> mySubTopics, myCopyrightNotices;
739 
741  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
742 
744  std::map<std::string, std::string> myXMLDefaults;
745 
747  mutable std::map<std::string, bool> myDeprecatedSynonymes;
748 
751 
752 
753 private:
759  public:
761  explicit abbreviation_finder() { }
762 
768  bool operator()(const std::string& s) {
769  return s.length() == 1;
770  }
771  };
772 
773 
774 private:
776  OptionsCont(const OptionsCont& s);
777 
779  OptionsCont& operator=(const OptionsCont& s);
780 
781 };
782 
783 
784 #endif
785 
786 /****************************************************************************/
787 
std::string myAppName
some information on the application
Definition: OptionsCont.h:732
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:738
std::string myFullName
Definition: OptionsCont.h:732
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:644
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:720
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:750
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
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:717
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:665
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:744
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:660
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:732
ItemAddressContType myAddresses
Definition: OptionsCont.h:726
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:747
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:732
std::vector< int > IntVector
Definition of a vector of unsigned 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 splitLines(std::ostream &os, std::string what, size_t offset, size_t nextOffset)
Writes the given string &#39;formatted&#39;.
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:758
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.
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:729
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:741
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
A storage for options typed value containers)
Definition: OptionsCont.h:108
Option * getSecure(const std::string &name) const
Returns the named option.
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:738
#define SUMOReal
Definition: config.h:213
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:768
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:650
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:723
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:74
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:735
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.