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
00055 class ConfigParser
00056 {
00057 public:
00058
00059 typedef std::vector<std::string> KeyVector;
00060
00063 ConfigParser();
00064
00065
00072 void parseFile(std::string file);
00073
00074
00082 void parseCmd(int argc, char* argv []);
00083
00084
00092 bool hasKey(const std::string& key);
00093
00094
00102 bool hasSub(const std::string& sub);
00103
00104
00113 std::string& operator[] (const std::string& key);
00114
00115
00118 void report() const;
00119
00120
00127 void report(const std::string prefix) const;
00128
00129
00135 ConfigParser& sub(const std::string& sub);
00136
00137
00146 std::string get(const std::string& key, std::string defaultValue);
00147
00148
00149 std::string get(const std::string& key, char* defaultValue);
00150
00151
00160 int get(const std::string& key, int defaultValue);
00161
00162
00171 double get(const std::string& key, double defaultValue);
00172
00173
00182 bool get(const std::string& key, bool defaultValue);
00183
00184
00191 const KeyVector& getValueKeys() const;
00192
00193
00200 const KeyVector& getSubKeys() const;
00201
00202 private:
00203 KeyVector valueKeys;
00204 KeyVector subKeys;
00205
00206 std::map<std::string, std::string> values;
00207 std::map<std::string, ConfigParser> subs;
00208 std::string trim(std::string s);
00209
00210
00211 };
00212 }
00213
00214
00215
00216 #endif