SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2001-2013 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 
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  SUMOReal 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);
556 
557 
564  void resetWritable();
565 
574  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
575 
576 
578  void clear();
579 
580 
597  bool processMetaOptions(bool missingOptions);
598 
599 
601  const std::vector<std::string>& getSubTopics() const {
602  return mySubTopics;
603  }
604 
605 
607  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
608  if (mySubTopicEntries.count(subtopic) > 0) {
609  return mySubTopicEntries.find(subtopic)->second;
610  } else {
611  return std::vector<std::string>();
612  }
613  }
614 
615 
617  std::string getTypeName(const std::string name) {
618  return getSecure(name)->getTypeName();
619  }
620 
621 
622  inline const std::string& getFullName() const {
623  return myFullName;
624  }
625 
626 private:
634  Option* getSecure(const std::string& name) const;
635 
636 
644  void reportDoubleSetting(const std::string& arg) const;
645 
646 
654  std::string convertChar(char abbr) const;
655 
656 
668  void splitLines(std::ostream& os, std::string what,
669  size_t offset, size_t nextOffset);
670 
671 
672 private:
675 
677  typedef std::vector<Option*> ItemAddressContType;
678 
680  typedef std::map<std::string, Option*> KnownContType;
681 
684 
687 
690 
692  std::vector< std::pair<std::string, std::string> > myCallExamples;
693 
695  std::vector<std::string> mySubTopics, myCopyrightNotices;
696 
698  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
699 
701  mutable std::map<std::string, bool> myDeprecatedSynonymes;
702 
705 
706 
707 private:
713  public:
715  explicit abbreviation_finder() { }
716 
722  bool operator()(const std::string& s) {
723  return s.length() == 1;
724  }
725  };
726 
727 
728 private:
730  OptionsCont(const OptionsCont& s);
731 
733  OptionsCont& operator=(const OptionsCont& s);
734 
735 };
736 
737 
738 #endif
739 
740 /****************************************************************************/
741 
std::string myAppName
some information on the application
Definition: OptionsCont.h:689
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:84
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:695
std::string myFullName
Definition: OptionsCont.h:689
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:601
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:677
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:704
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:174
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:674
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:622
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:617
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:689
ItemAddressContType myAddresses
Definition: OptionsCont.h:683
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
std::map< std::string, bool > myDeprecatedSynonymes
A map from deprecated options to a bool indicating whether we warned about deprecation.
Definition: OptionsCont.h:701
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:689
std::vector< int > IntVector
Definition of a vector of unsigned ints.
Definition: Option.h:47
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:78
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:712
A class representing a single program option.
Definition: Option.h:78
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
KnownContType myValues
Definition: OptionsCont.h:686
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:698
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:695
#define SUMOReal
Definition: config.h:215
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:722
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:607
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:680
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:72
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:692
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.