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) const;
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 
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