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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // A storage for options (typed value containers)
21 /****************************************************************************/
22 #ifndef OptionsCont_h
23 #define OptionsCont_h
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 #include <iostream>
37 #include "Option.h"
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
98 class OptionsCont {
99 public:
101  static OptionsCont& getOptions();
102 
103 
105  OptionsCont();
106 
107 
109  ~OptionsCont();
110 
111 
112 
115 
121  void setApplicationName(const std::string& appName, const std::string& fullName);
122 
123 
128  void setApplicationDescription(const std::string& appDesc);
129 
130 
136  void addCallExample(const std::string& example, const std::string& desc);
137 
138 
143  void setAdditionalHelpMessage(const std::string& add);
144 
145 
150  void addCopyrightNotice(const std::string& copyrightLine);
151 
152 
155  void clearCopyrightNotices();
156 
157 
166  void addOptionSubTopic(const std::string& topic);
167 
168 
173  void printHelp(std::ostream& os);
174 
175 
187  void writeConfiguration(std::ostream& os, const bool filled,
188  const bool complete, const bool addComments,
189  const bool maskDoubleHyphen = false) const;
190 
191 
200  void writeSchema(std::ostream& os, bool addComments);
201 
202 
211  void writeXMLHeader(std::ostream& os);
213 
214 
215 
216 
219 
225  void doRegister(const std::string& name, Option* v);
226 
227 
237  void doRegister(const std::string& name, char abbr, Option* v);
238 
239 
256  void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
257 
258 
264  void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
265 
266 
280  void addDescription(const std::string& name, const std::string& subtopic,
281  const std::string& description);
283 
284 
285 
286 
289 
293  bool exists(const std::string& name) const;
294 
295 
311  bool isSet(const std::string& name, bool failOnNonExistant = true) const;
312 
313 
318  void unSet(const std::string& name, bool failOnNonExistant = true) const;
319 
320 
334  bool isDefault(const std::string& name) const;
335 
336 
346  bool isBool(const std::string& name) const;
347 
348 
366  bool isUsableFileList(const std::string& name) const;
367 
368 
379  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
380 
381 
389  void relocateFiles(const std::string& configuration) const;
390 
391 
401  std::vector<std::string> getSynonymes(const std::string& name) const;
402 
403 
415  bool isWriteable(const std::string& name);
417 
418 
419 
420 
423 
434  std::string getString(const std::string& name) const;
435 
436 
447  double getFloat(const std::string& name) const;
448 
449 
460  int getInt(const std::string& name) const;
461 
462 
473  bool getBool(const std::string& name) const;
474 
475 
486  const IntVector& getIntVector(const std::string& name) const;
487 
488 
505  std::vector<std::string> getStringVector(const std::string& name) const;
506 
507 
525  bool isInStringVector(const std::string& optionName,
526  const std::string& itemName);
528 
529 
530 
531 
534 
554  bool set(const std::string& name, const std::string& value);
555 
575  bool setDefault(const std::string& name, const std::string& value);
576 
589  bool setByRootElement(const std::string& name, const std::string& value);
591 
592 
599  void resetWritable();
600 
609  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
610 
611 
613  void clear();
614 
615 
632  bool processMetaOptions(bool missingOptions);
633 
634 
636  const std::vector<std::string>& getSubTopics() const {
637  return mySubTopics;
638  }
639 
640 
642  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
643  if (mySubTopicEntries.count(subtopic) > 0) {
644  return mySubTopicEntries.find(subtopic)->second;
645  } else {
646  return std::vector<std::string>();
647  }
648  }
649 
650 
652  std::string getTypeName(const std::string name) {
653  return getSecure(name)->getTypeName();
654  }
655 
656 
657  inline const std::string& getFullName() const {
658  return myFullName;
659  }
660 
661 private:
669  Option* getSecure(const std::string& name) const;
670 
671 
679  void reportDoubleSetting(const std::string& arg) const;
680 
681 
689  std::string convertChar(char abbr) const;
690 
691 
703  void splitLines(std::ostream& os, std::string what,
704  int offset, int nextOffset);
705 
706 
707 private:
710 
712  typedef std::vector<Option*> ItemAddressContType;
713 
715  typedef std::map<std::string, Option*> KnownContType;
716 
718  ItemAddressContType myAddresses;
719 
721  KnownContType myValues;
722 
725 
727  std::vector< std::pair<std::string, std::string> > myCallExamples;
728 
730  std::vector<std::string> mySubTopics, myCopyrightNotices;
731 
733  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
734 
736  std::map<std::string, std::string> myXMLDefaults;
737 
739  mutable std::map<std::string, bool> myDeprecatedSynonymes;
740 
743 
744 
745 private:
747  OptionsCont(const OptionsCont& s);
748 
750  OptionsCont& operator=(const OptionsCont& s);
751 
752 };
753 
754 
755 #endif
756 
757 /****************************************************************************/
758 
std::string myAppName
some information on the application
Definition: OptionsCont.h:724
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:81
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:730
std::string myFullName
Definition: OptionsCont.h:724
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:636
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:712
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:742
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:709
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:736
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:652
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:724
ItemAddressContType myAddresses
Definition: OptionsCont.h:718
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:739
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:724
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:47
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:75
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 representing a single program option.
Definition: Option.h:78
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:721
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:642
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:733
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:176
A storage for options typed value containers)
Definition: OptionsCont.h:98
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:730
const std::string & getFullName() const
Definition: OptionsCont.h:657
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)
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:715
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:69
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:727
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.