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-2017 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 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <map>
35 #include <string>
36 #include <vector>
37 #include <iostream>
38 #include "Option.h"
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
99 class OptionsCont {
100 public:
102  static OptionsCont& getOptions();
103 
104 
106  OptionsCont();
107 
108 
110  ~OptionsCont();
111 
112 
113 
116 
122  void setApplicationName(const std::string& appName, const std::string& fullName);
123 
124 
129  void setApplicationDescription(const std::string& appDesc);
130 
131 
137  void addCallExample(const std::string& example, const std::string& desc);
138 
139 
144  void setAdditionalHelpMessage(const std::string& add);
145 
146 
151  void addCopyrightNotice(const std::string& copyrightLine);
152 
153 
156  void clearCopyrightNotices();
157 
158 
167  void addOptionSubTopic(const std::string& topic);
168 
169 
174  void printHelp(std::ostream& os);
175 
176 
188  void writeConfiguration(std::ostream& os, const bool filled,
189  const bool complete, const bool addComments,
190  const bool maskDoubleHyphen = false) const;
191 
192 
201  void writeSchema(std::ostream& os, bool addComments);
202 
203 
212  void writeXMLHeader(std::ostream& os);
214 
215 
216 
217 
220 
226  void doRegister(const std::string& name, Option* v);
227 
228 
238  void doRegister(const std::string& name, char abbr, Option* v);
239 
240 
257  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
258 
259 
265  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
266 
267 
281  void addDescription(const std::string& name, const std::string& subtopic,
282  const std::string& description);
284 
285 
286 
287 
290 
294  bool exists(const std::string& name) const;
295 
296 
312  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
313 
314 
319  void unSet(const std::string& name, bool failOnNonExistant = true) const;
320 
321 
335  bool isDefault(const std::string& name) const;
336 
337 
347  bool isBool(const std::string& name) const;
348 
349 
367  bool isUsableFileList(const std::string& name) const;
368 
369 
380  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
381 
382 
390  void relocateFiles(const std::string& configuration) const;
391 
392 
402  std::vector<std::string> getSynonymes(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 
489 
506  std::vector<std::string> getStringVector(const std::string& name) const;
507 
508 
526  bool isInStringVector(const std::string& optionName,
527  const std::string& itemName);
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 
719  ItemAddressContType myAddresses;
720 
722  KnownContType myValues;
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:
752  public:
754  explicit abbreviation_finder() { }
755 
761  bool operator()(const std::string& s) {
762  return s.length() == 1;
763  }
764  };
765 
766 
767 private:
769  OptionsCont(const OptionsCont& s);
770 
772  OptionsCont& operator=(const OptionsCont& s);
773 
774 };
775 
776 
777 #endif
778 
779 /****************************************************************************/
780 
std::string myAppName
some information on the application
Definition: OptionsCont.h:725
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:82
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:731
std::string myFullName
Definition: OptionsCont.h:725
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.
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:637
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:713
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:743
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:710
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.
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:737
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:653
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:725
ItemAddressContType myAddresses
Definition: OptionsCont.h:719
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:740
void clear()
Removes all information from the container.
void writeXMLHeader(std::ostream &os)
Writes a standard XML header, including the configuration.
std::string myAdditionalMessage
Definition: OptionsCont.h:725
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:48
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:76
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.
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:751
A class representing a single program option.
Definition: Option.h:79
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::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:722
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:643
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:734
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:177
A storage for options typed value containers)
Definition: OptionsCont.h:99
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:731
const std::string & getFullName() const
Definition: OptionsCont.h:658
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const bool maskDoubleHyphen=false) const
Writes the configuration.
OptionsCont & operator=(const OptionsCont &s)
bool operator()(const std::string &s)
The comparing function.
Definition: OptionsCont.h:761
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:716
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:70
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:728
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.