configparser.hh
Go to the documentation of this file.00001 #ifndef DUNE_CONFIGPARSER_HH
00002 #define DUNE_CONFIGPARSER_HH
00003
00004
00005 #include <map>
00006 #include <vector>
00007 #include <string>
00008 #include <iostream>
00009
00010 namespace Dune {
00011
00058 class ConfigParser
00059 {
00060 public:
00061
00062 typedef std::vector<std::string> KeyVector;
00063
00066 ConfigParser();
00067
00068
00075 void parseFile(std::string file);
00076
00077
00085 void parseCmd(int argc, char* argv []);
00086
00087
00095 bool hasKey(const std::string& key);
00096
00097
00105 bool hasSub(const std::string& sub);
00106
00107
00116 std::string& operator[] (const std::string& key);
00117
00118
00121 void report() const;
00122
00123
00130 void report(const std::string prefix) const;
00131
00132
00138 ConfigParser& sub(const std::string& sub);
00139
00140
00149 std::string get(const std::string& key, const std::string& defaultValue);
00150
00161 std::string get(const std::string& key, const char* defaultValue);
00162
00163
00172 int get(const std::string& key, int defaultValue);
00173
00174
00183 double get(const std::string& key, double defaultValue);
00184
00185
00194 bool get(const std::string& key, bool defaultValue);
00195
00204 template <class T>
00205 T get(const std::string& key);
00206
00213 const KeyVector& getValueKeys() const;
00214
00215
00222 const KeyVector& getSubKeys() const;
00223
00224 private:
00225 KeyVector valueKeys;
00226 KeyVector subKeys;
00227
00228 std::map<std::string, std::string> values;
00229 std::map<std::string, ConfigParser> subs;
00230 static std::string ltrim(const std::string& s);
00231 static std::string rtrim(const std::string& s);
00232 };
00233 }
00234
00235
00236
00237 #endif