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.sourceforge.net/
13 // Copyright (C) 2001-2012 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);
198 
199 
208  void writeSchema(std::ostream& os, bool addComments);
209 
210 
219  void writeXMLHeader(std::ostream& os, const std::string xmlParams = "");
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 
327  bool isDefault(const std::string& name) const;
328 
329 
339  bool isBool(const std::string& name) const;
340 
341 
359  bool isUsableFileList(const std::string& name) const;
360 
361 
372  bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
373 
374 
382  void relocateFiles(const std::string& configuration) const;
383 
384 
394  std::vector<std::string> getSynonymes(const std::string& name) const;
395 
396 
408  bool isWriteable(const std::string& name);
410 
411 
412 
413 
416 
427  std::string getString(const std::string& name) const;
428 
429 
440  SUMOReal getFloat(const std::string& name) const;
441 
442 
453  int getInt(const std::string& name) const;
454 
455 
466  bool getBool(const std::string& name) const;
467 
468 
479  const IntVector& getIntVector(const std::string& name) const;
480 
481 
498  std::vector<std::string> getStringVector(const std::string& name) const;
499 
500 
518  bool isInStringVector(const std::string& optionName,
519  const std::string& itemName);
521 
522 
523 
524 
527 
547  bool set(const std::string& name, const std::string& value);
549 
550 
557  void resetWritable();
558 
567  friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
568 
569 
571  void clear();
572 
573 
590  bool processMetaOptions(bool missingOptions) ;
591 
592 
594  const std::vector<std::string> & getSubTopics() const {
595  return mySubTopics;
596  }
597 
598 
600  std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
601  if (mySubTopicEntries.count(subtopic) > 0) {
602  return mySubTopicEntries.find(subtopic)->second;
603  } else {
604  return std::vector<std::string>();
605  }
606  }
607 
608 
610  std::string getTypeName(const std::string name) {
611  return getSecure(name)->getTypeName();
612  }
613 
614 private:
622  Option* getSecure(const std::string& name) const;
623 
624 
632  void reportDoubleSetting(const std::string& arg) const;
633 
634 
642  std::string convertChar(char abbr) const;
643 
644 
656  void splitLines(std::ostream& os, std::string what,
657  size_t offset, size_t nextOffset);
658 
659 
660 private:
663 
665  typedef std::vector<Option*> ItemAddressContType;
666 
668  typedef std::map<std::string, Option*> KnownContType;
669 
672 
675 
678 
680  std::vector< std::pair<std::string, std::string> > myCallExamples;
681 
683  std::vector<std::string> mySubTopics, myCopyrightNotices;
684 
686  std::map<std::string, std::vector<std::string> > mySubTopicEntries;
687 
689  mutable std::map<std::string, bool> myDeprecatedSynonymes;
690 
693 
694 
695 private:
701  public:
703  explicit abbreviation_finder() { }
704 
710  bool operator()(const std::string& s) {
711  return s.length() == 1;
712  }
713  };
714 
715 
716 private:
718  OptionsCont(const OptionsCont& s);
719 
721  OptionsCont& operator=(const OptionsCont& s);
722 
723 };
724 
725 
726 #endif
727 
728 /****************************************************************************/
729