SUMO - Simulation of Urban MObility
OptionsCont.h
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // A storage for options (typed value containers)
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 #ifndef OptionsCont_h
00024 #define OptionsCont_h
00025 // ===========================================================================
00026 // compiler pragmas
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #pragma warning(disable: 4786)
00030 #pragma warning(disable: 4503)
00031 #endif
00032 
00033 
00034 // ===========================================================================
00035 // included modules
00036 // ===========================================================================
00037 #ifdef _MSC_VER
00038 #include <windows_config.h>
00039 #else
00040 #include <config.h>
00041 #endif
00042 
00043 #include <map>
00044 #include <string>
00045 #include <vector>
00046 #include <iostream>
00047 #include "Option.h"
00048 
00049 
00050 // ===========================================================================
00051 // class definitions
00052 // ===========================================================================
00108 class OptionsCont {
00109 public:
00111     static OptionsCont& getOptions();
00112 
00113 
00115     OptionsCont();
00116 
00117 
00119     ~OptionsCont();
00120 
00121 
00122 
00125 
00131     void setApplicationName(const std::string& appName, const std::string& fullName);
00132 
00133 
00138     void setApplicationDescription(const std::string& appDesc);
00139 
00140 
00146     void addCallExample(const std::string& example, const std::string& desc);
00147 
00148 
00153     void setAdditionalHelpMessage(const std::string& add);
00154 
00155 
00160     void addCopyrightNotice(const std::string& copyrightLine);
00161 
00162 
00165     void clearCopyrightNotices();
00166 
00167 
00176     void addOptionSubTopic(const std::string& topic);
00177 
00178 
00183     void printHelp(std::ostream& os);
00184 
00185 
00196     void writeConfiguration(std::ostream& os, bool filled,
00197                             bool complete, bool addComments);
00198 
00199 
00208     void writeSchema(std::ostream& os, bool addComments);
00209 
00210 
00219     void writeXMLHeader(std::ostream& os, const std::string xmlParams = "");
00221 
00222 
00223 
00224 
00227 
00233     void doRegister(const std::string& name, Option* v);
00234 
00235 
00245     void doRegister(const std::string& name, char abbr, Option* v);
00246 
00247 
00264     void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
00265 
00266 
00280     void addDescription(const std::string& name, const std::string& subtopic,
00281                         const std::string& description);
00283 
00284 
00285 
00286 
00289 
00293     bool exists(const std::string& name) const;
00294 
00295 
00311     bool isSet(const std::string& name, bool failOnNonExistant = true) const;
00312 
00313 
00327     bool isDefault(const std::string& name) const;
00328 
00329 
00339     bool isBool(const std::string& name) const;
00340 
00341 
00359     bool isUsableFileList(const std::string& name) const;
00360 
00361 
00372     bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
00373 
00374 
00382     void relocateFiles(const std::string& configuration) const;
00383 
00384 
00394     std::vector<std::string> getSynonymes(const std::string& name) const;
00395 
00396 
00408     bool isWriteable(const std::string& name);
00410 
00411 
00412 
00413 
00416 
00427     std::string getString(const std::string& name) const;
00428 
00429 
00440     SUMOReal getFloat(const std::string& name) const;
00441 
00442 
00453     int getInt(const std::string& name) const;
00454 
00455 
00466     bool getBool(const std::string& name) const;
00467 
00468 
00479     const IntVector& getIntVector(const std::string& name) const;
00480 
00481 
00498     std::vector<std::string> getStringVector(const std::string& name) const;
00499 
00500 
00518     bool isInStringVector(const std::string& optionName,
00519                           const std::string& itemName);
00521 
00522 
00523 
00524 
00527 
00547     bool set(const std::string& name, const std::string& value);
00549 
00550 
00557     void resetWritable();
00558 
00567     friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
00568 
00569 
00571     void clear();
00572 
00573 
00590     bool processMetaOptions(bool missingOptions) ;
00591 
00592 
00594     const std::vector<std::string> & getSubTopics() const {
00595         return mySubTopics;
00596     }
00597 
00598 
00600     std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
00601         if (mySubTopicEntries.count(subtopic) > 0) {
00602             return mySubTopicEntries.find(subtopic)->second;
00603         } else {
00604             return std::vector<std::string>();
00605         }
00606     }
00607 
00608 
00610     std::string getTypeName(const std::string name) {
00611         return getSecure(name)->getTypeName();
00612     }
00613 
00614 private:
00622     Option* getSecure(const std::string& name) const;
00623 
00624 
00632     void reportDoubleSetting(const std::string& arg) const;
00633 
00634 
00642     std::string convertChar(char abbr) const;
00643 
00644 
00656     void splitLines(std::ostream& os, std::string what,
00657                     size_t offset, size_t nextOffset);
00658 
00659 
00660 private:
00662     static OptionsCont myOptions;
00663 
00665     typedef std::vector<Option*> ItemAddressContType;
00666 
00668     typedef std::map<std::string, Option*> KnownContType;
00669 
00671     ItemAddressContType myAddresses;
00672 
00674     KnownContType myValues;
00675 
00677     std::string myAppName, myFullName, myAppDescription, myAdditionalMessage;
00678 
00680     std::vector< std::pair<std::string, std::string> > myCallExamples;
00681 
00683     std::vector<std::string> mySubTopics, myCopyrightNotices;
00684 
00686     std::map<std::string, std::vector<std::string> > mySubTopicEntries;
00687 
00689     mutable std::map<std::string, bool> myDeprecatedSynonymes;
00690 
00692     mutable bool myHaveInformedAboutDeprecatedDivider;
00693 
00694 
00695 private:
00700     class abbreviation_finder {
00701     public:
00703         explicit abbreviation_finder() { }
00704 
00710         bool operator()(const std::string& s) {
00711             return s.length() == 1;
00712         }
00713     };
00714 
00715 
00716 private:
00718     OptionsCont(const OptionsCont& s);
00719 
00721     OptionsCont& operator=(const OptionsCont& s);
00722 
00723 };
00724 
00725 
00726 #endif
00727 
00728 /****************************************************************************/
00729 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines