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 
00145     void addCallExample(const std::string& example);
00146 
00147 
00152     void setAdditionalHelpMessage(const std::string& add);
00153 
00154 
00159     void addCopyrightNotice(const std::string& copyrightLine);
00160 
00161 
00164     void clearCopyrightNotices();
00165 
00166 
00175     void addOptionSubTopic(const std::string& topic);
00176 
00177 
00182     void printHelp(std::ostream& os);
00183 
00184 
00195     void writeConfiguration(std::ostream& os, bool filled,
00196                             bool complete, bool addComments);
00197 
00198 
00207     void writeSchema(std::ostream& os, bool addComments);
00208 
00209 
00218     void writeXMLHeader(std::ostream& os, const std::string xmlParams = "");
00220 
00221 
00222 
00223 
00226 
00232     void doRegister(const std::string& name, Option* v);
00233 
00234 
00244     void doRegister(const std::string& name, char abbr, Option* v);
00245 
00246 
00263     void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
00264 
00265 
00279     void addDescription(const std::string& name, const std::string& subtopic,
00280                         const std::string& description);
00282 
00283 
00284 
00285 
00288 
00292     bool exists(const std::string& name) const;
00293 
00294 
00310     bool isSet(const std::string& name, bool failOnNonExistant = true) const;
00311 
00312 
00326     bool isDefault(const std::string& name) const;
00327 
00328 
00338     bool isBool(const std::string& name) const;
00339 
00340 
00358     bool isUsableFileList(const std::string& name) const;
00359 
00360 
00371     bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
00372 
00373 
00381     void relocateFiles(const std::string& configuration) const;
00382 
00383 
00393     std::vector<std::string> getSynonymes(const std::string& name) const;
00394 
00395 
00407     bool isWriteable(const std::string& name);
00409 
00410 
00411 
00412 
00415 
00426     std::string getString(const std::string& name) const;
00427 
00428 
00439     SUMOReal getFloat(const std::string& name) const;
00440 
00441 
00452     int getInt(const std::string& name) const;
00453 
00454 
00465     bool getBool(const std::string& name) const;
00466 
00467 
00478     const IntVector& getIntVector(const std::string& name) const;
00479 
00480 
00497     std::vector<std::string> getStringVector(const std::string& name) const;
00498 
00499 
00517     bool isInStringVector(const std::string& optionName,
00518                           const std::string& itemName);
00520 
00521 
00522 
00523 
00526 
00546     bool set(const std::string& name, const std::string& value);
00548 
00549 
00556     void resetWritable();
00557 
00566     friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
00567 
00568 
00570     void clear();
00571 
00572 
00589     bool processMetaOptions(bool missingOptions) ;
00590 
00591 
00593     const std::vector<std::string> & getSubTopics() const {
00594         return mySubTopics;
00595     }
00596 
00597 
00599     std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
00600         if (mySubTopicEntries.count(subtopic) > 0) {
00601             return mySubTopicEntries.find(subtopic)->second;
00602         } else {
00603             return std::vector<std::string>();
00604         }
00605     }
00606 
00607 
00609     std::string getTypeName(const std::string name) {
00610         return getSecure(name)->getTypeName();
00611     }
00612 
00613 private:
00621     Option* getSecure(const std::string& name) const;
00622 
00623 
00631     void reportDoubleSetting(const std::string& arg) const;
00632 
00633 
00641     std::string convertChar(char abbr) const;
00642 
00643 
00655     void splitLines(std::ostream& os, std::string what,
00656                     size_t offset, size_t nextOffset);
00657 
00658 
00659 private:
00661     static OptionsCont myOptions;
00662 
00664     typedef std::vector<Option*> ItemAddressContType;
00665 
00667     typedef std::map<std::string, Option*> KnownContType;
00668 
00670     ItemAddressContType myAddresses;
00671 
00673     KnownContType myValues;
00674 
00676     std::string myAppName, myFullName, myAppDescription, myAdditionalMessage;
00677 
00679     std::vector<std::string> myCallExamples, mySubTopics, myCopyrightNotices;
00680 
00682     std::map<std::string, std::vector<std::string> > mySubTopicEntries;
00683 
00685     mutable std::map<std::string, bool> myDeprecatedSynonymes;
00686 
00688     mutable bool myHaveInformedAboutDeprecatedDivider;
00689 
00690 
00691 private:
00696     class abbreviation_finder {
00697     public:
00699         explicit abbreviation_finder() { }
00700 
00706         bool operator()(const std::string& s) {
00707             return s.length() == 1;
00708         }
00709     };
00710 
00711 
00712 private:
00714     OptionsCont(const OptionsCont& s);
00715 
00717     OptionsCont& operator=(const OptionsCont& s);
00718 
00719 };
00720 
00721 
00722 #endif
00723 
00724 /****************************************************************************/
00725 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines