OptionsCont.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A storage for options (typed value containers)
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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() throw();
00108 
00109 
00111     OptionsCont() throw();
00112 
00113 
00115     ~OptionsCont() throw();
00116 
00117 
00118 
00121 
00127     void setApplicationName(const std::string &appName, const std::string &fullName) throw();
00128 
00129 
00134     void setApplicationDescription(const std::string &appDesc) throw();
00135 
00136 
00141     void addCallExample(const std::string &example) throw();
00142 
00143 
00148     void setAdditionalHelpMessage(const std::string &add) throw();
00149 
00150 
00159     void addOptionSubTopic(const std::string &topic) throw();
00160 
00161 
00166     void printHelp(std::ostream &os) throw();
00167 
00168 
00179     void writeConfiguration(std::ostream &os, bool filled,
00180                             bool complete, bool addComments) throw();
00181 
00182 
00191     void writeXMLHeader(std::ostream &os, const bool writeConfig=true) throw();
00193 
00194 
00195 
00196 
00199 
00205     void doRegister(const std::string &name, Option *v) throw(InvalidArgument);
00206 
00207 
00217     void doRegister(const std::string &name, char abbr, Option *v) throw(InvalidArgument);
00218 
00219 
00235     void addSynonyme(const std::string &name1, const std::string &name2) throw(InvalidArgument);
00236 
00237 
00251     void addDescription(const std::string &name, const std::string &subtopic,
00252                         const std::string &description) throw(InvalidArgument);
00254 
00255 
00256 
00257 
00260 
00264     bool exists(const std::string &name) const throw();
00265 
00266 
00280     bool isSet(const std::string &name) const throw(InvalidArgument);
00281 
00282 
00296     bool isDefault(const std::string &name) const throw(InvalidArgument);
00297 
00298 
00308     bool isBool(const std::string &name) const throw(InvalidArgument);
00309 
00310 
00328     bool isUsableFileList(const std::string &name) const throw(InvalidArgument);
00329 
00330 
00341     bool checkDependingSuboptions(const std::string &name, const std::string &prefix) const throw(InvalidArgument);
00342 
00343 
00351     void relocateFiles(const std::string &configuration) const throw();
00352 
00353 
00363     std::vector<std::string> getSynonymes(const std::string &name) const throw(InvalidArgument);
00364 
00365 
00377     bool isWriteable(const std::string &name) throw(InvalidArgument);
00379 
00380 
00381 
00382 
00385 
00396     std::string getString(const std::string &name) const throw(InvalidArgument);
00397 
00398 
00409     SUMOReal getFloat(const std::string &name) const throw(InvalidArgument);
00410 
00411 
00422     int getInt(const std::string &name) const throw(InvalidArgument);
00423 
00424 
00435     bool getBool(const std::string &name) const throw(InvalidArgument);
00436 
00437 
00448     const IntVector &getIntVector(const std::string &name) const throw(InvalidArgument);
00449 
00450 
00467     std::vector<std::string> getStringVector(const std::string &name) const throw(InvalidArgument);
00468 
00469 
00487     bool isInStringVector(const std::string &optionName,
00488                           const std::string &itemName) throw(InvalidArgument);
00490 
00491 
00492 
00493 
00496 
00516     bool set(const std::string &name, const std::string &value) throw(InvalidArgument);
00517 
00518 
00538     bool set(const std::string &name, bool value) throw(InvalidArgument);
00540 
00541 
00548     void resetWritable() throw();
00549 
00558     friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
00559 
00560 
00562     void clear() throw();
00563 
00564 
00581     bool processMetaOptions(bool missingOptions) throw(ProcessError);
00582 
00583 
00584 private:
00592     Option *getSecure(const std::string &name) const throw(InvalidArgument);
00593 
00594 
00602     void reportDoubleSetting(const std::string &arg) const throw();
00603 
00604 
00612     std::string convertChar(char abbr) const throw();
00613 
00614 
00626     void splitLines(std::ostream &os, std::string what,
00627                     size_t offset, size_t nextOffset) throw();
00628 
00629 
00630 private:
00632     static OptionsCont myOptions;
00633 
00635     typedef std::vector<Option*> ItemAddressContType;
00636 
00638     typedef std::map<std::string, Option*> KnownContType;
00639 
00641     ItemAddressContType myAddresses;
00642 
00644     KnownContType myValues;
00645 
00647     std::string myAppName, myFullName, myAppDescription, myAdditionalMessage;
00648 
00650     std::vector<std::string> myCallExamples, mySubTopics;
00651 
00653     std::map<std::string, std::vector<std::string> > mySubTopicEntries;
00654 
00656     mutable bool myHaveInformedAboutDeprecatedDivider;
00657 
00658 
00659 private:
00664     class abbreviation_finder {
00665     public:
00667         explicit abbreviation_finder() { }
00668 
00674         bool operator()(const std::string &s) {
00675             return s.length()==1;
00676         }
00677     };
00678 
00679 
00680 private:
00682     OptionsCont(const OptionsCont &s);
00683 
00685     OptionsCont &operator=(const OptionsCont &s);
00686 
00687 };
00688 
00689 
00690 #endif
00691 
00692 /****************************************************************************/
00693 

Generated on Wed May 5 00:06:35 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6