|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A storage for options (typed value containers) 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef OptionsCont_h 00020 #define OptionsCont_h 00021 // =========================================================================== 00022 // compiler pragmas 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #pragma warning(disable: 4786) 00026 #pragma warning(disable: 4503) 00027 #endif 00028 00029 00030 // =========================================================================== 00031 // included modules 00032 // =========================================================================== 00033 #ifdef _MSC_VER 00034 #include <windows_config.h> 00035 #else 00036 #include <config.h> 00037 #endif 00038 00039 #include <map> 00040 #include <string> 00041 #include <vector> 00042 #include <iostream> 00043 #include "Option.h" 00044 00045 00046 // =========================================================================== 00047 // class definitions 00048 // =========================================================================== 00104 class OptionsCont { 00105 public: 00107 static OptionsCont& getOptions(); 00108 00109 00111 OptionsCont(); 00112 00113 00115 ~OptionsCont(); 00116 00117 00118 00121 00127 void setApplicationName(const std::string& appName, const std::string& fullName); 00128 00129 00134 void setApplicationDescription(const std::string& appDesc); 00135 00136 00141 void addCallExample(const std::string& example); 00142 00143 00148 void setAdditionalHelpMessage(const std::string& add); 00149 00150 00155 void addCopyrightNotice(const std::string& copyrightLine); 00156 00157 00160 void clearCopyrightNotices(); 00161 00162 00171 void addOptionSubTopic(const std::string& topic); 00172 00173 00178 void printHelp(std::ostream& os); 00179 00180 00191 void writeConfiguration(std::ostream& os, bool filled, 00192 bool complete, bool addComments); 00193 00194 00203 void writeSchema(std::ostream& os, bool addComments); 00204 00205 00214 void writeXMLHeader(std::ostream& os, const std::string xmlParams=""); 00216 00217 00218 00219 00222 00228 void doRegister(const std::string& name, Option* v); 00229 00230 00240 void doRegister(const std::string& name, char abbr, Option* v); 00241 00242 00259 void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated=false); 00260 00261 00275 void addDescription(const std::string& name, const std::string& subtopic, 00276 const std::string& description); 00278 00279 00280 00281 00284 00288 bool exists(const std::string& name) const; 00289 00290 00306 bool isSet(const std::string& name, bool failOnNonExistant=true) const; 00307 00308 00322 bool isDefault(const std::string& name) const; 00323 00324 00334 bool isBool(const std::string& name) const; 00335 00336 00354 bool isUsableFileList(const std::string& name) const; 00355 00356 00367 bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const; 00368 00369 00377 void relocateFiles(const std::string& configuration) const; 00378 00379 00389 std::vector<std::string> getSynonymes(const std::string& name) const; 00390 00391 00403 bool isWriteable(const std::string& name); 00405 00406 00407 00408 00411 00422 std::string getString(const std::string& name) const; 00423 00424 00435 SUMOReal getFloat(const std::string& name) const; 00436 00437 00448 int getInt(const std::string& name) const; 00449 00450 00461 bool getBool(const std::string& name) const; 00462 00463 00474 const IntVector& getIntVector(const std::string& name) const; 00475 00476 00493 std::vector<std::string> getStringVector(const std::string& name) const; 00494 00495 00513 bool isInStringVector(const std::string& optionName, 00514 const std::string& itemName); 00516 00517 00518 00519 00522 00542 bool set(const std::string& name, const std::string& value); 00544 00545 00552 void resetWritable(); 00553 00562 friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc); 00563 00564 00566 void clear(); 00567 00568 00585 bool processMetaOptions(bool missingOptions) throw(ProcessError); 00586 00587 00589 const std::vector<std::string> & getSubTopics() const { 00590 return mySubTopics; 00591 } 00592 00593 00595 std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const { 00596 if (mySubTopicEntries.count(subtopic) > 0) { 00597 return mySubTopicEntries.find(subtopic)->second; 00598 } else { 00599 return std::vector<std::string>(); 00600 } 00601 } 00602 00603 00605 std::string getTypeName(const std::string name) { 00606 return getSecure(name)->getTypeName(); 00607 } 00608 00609 private: 00617 Option* getSecure(const std::string& name) const; 00618 00619 00627 void reportDoubleSetting(const std::string& arg) const; 00628 00629 00637 std::string convertChar(char abbr) const; 00638 00639 00651 void splitLines(std::ostream& os, std::string what, 00652 size_t offset, size_t nextOffset); 00653 00654 00655 private: 00657 static OptionsCont myOptions; 00658 00660 typedef std::vector<Option*> ItemAddressContType; 00661 00663 typedef std::map<std::string, Option*> KnownContType; 00664 00666 ItemAddressContType myAddresses; 00667 00669 KnownContType myValues; 00670 00672 std::string myAppName, myFullName, myAppDescription, myAdditionalMessage; 00673 00675 std::vector<std::string> myCallExamples, mySubTopics, myCopyrightNotices; 00676 00678 std::map<std::string, std::vector<std::string> > mySubTopicEntries; 00679 00681 mutable std::map<std::string, bool> myDeprecatedSynonymes; 00682 00684 mutable bool myHaveInformedAboutDeprecatedDivider; 00685 00686 00687 private: 00692 class abbreviation_finder { 00693 public: 00695 explicit abbreviation_finder() { } 00696 00702 bool operator()(const std::string& s) { 00703 return s.length()==1; 00704 } 00705 }; 00706 00707 00708 private: 00710 OptionsCont(const OptionsCont& s); 00711 00713 OptionsCont& operator=(const OptionsCont& s); 00714 00715 }; 00716 00717 00718 #endif 00719 00720 /****************************************************************************/ 00721