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, const std::string& defaultValue);
00147
00158 std::string get(const std::string& key, const char* defaultValue);
00159
00160
00169 int get(const std::string& key, int defaultValue);
00170
00171
00180 double get(const std::string& key, double defaultValue);
00181
00182
00191 bool get(const std::string& key, bool defaultValue);
00192
00201 template <class T>
00202 T get(const std::string& key);
00203
00210 const KeyVector& getValueKeys() const;
00211
00212
00219 const KeyVector& getSubKeys() const;
00220
00221 private:
00222 KeyVector valueKeys;
00223 KeyVector subKeys;
00224
00225 std::map<std::string, std::string> values;
00226 std::map<std::string, ConfigParser> subs;
00227 std::string trim(std::string s);
00228
00229
00230 };
00231 }
00232
00233
00234
00235 #endif