00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _Configuration_h_
00020 #define _Configuration_h_
00021
00022
00023 #include "XMLEntity.h"
00024
00025 class Configuration
00026 {
00027 public:
00028 Configuration()
00029 : xmltree(new XMLnode("config")), rootname("config"), filename(), is_file(false)
00030 { }
00031 Configuration(const std::string &fname, const std::string &root)
00032 : xmltree(new XMLnode(root)), rootname(root), filename(), is_file(false)
00033 { if(fname.size()) read_config_file(fname); }
00034
00035 ~Configuration() { if(xmltree!=0) delete xmltree; };
00036
00037 bool read_config_file(const std::string &input_filename, const std::string &root=std::string());
00038 bool read_abs_config_file(const std::string &input_filename, const std::string &root=std::string());
00039
00040 bool read_config_string(const std::string &);
00041
00042 void value(const std::string &key, std::string &ret, const char *defaultvalue="") const;
00043 void value(const std::string &key, bool &ret, bool defaultvalue=false) const;
00044 void value(const std::string &key, int &ret, int defaultvalue=0) const;
00045
00046 void value(const char *key, std::string &ret, const char *defaultvalue="") const
00047 { value(std::string(key), ret, defaultvalue); };
00048 void value(const char *key, bool &ret, bool defaultvalue=false) const
00049 { value(std::string(key), ret, defaultvalue); };
00050 void value(const char *key, int &ret, int defaultvalue=0) const
00051 { value(std::string(key), ret, defaultvalue); };
00052
00053 void set(const std::string &key, const std::string &value, bool write_to_file);
00054 void set(const char *key,const char *value,bool write_to_file);
00055 void set(const char *key,const std::string &value,bool write_to_file);
00056 void set(const char *key,int,bool write_to_file);
00057
00058
00059 std::vector<std::string> listkeys(const std::string &key,bool longformat=true);
00060 std::vector<std::string> listkeys(const char *key,bool longformat=true);
00061
00062 std::string dump(void);
00063 std::ostream &dump(std::ostream &o, const std::string &indentstr);
00064
00065 void write_back(void);
00066
00067 void clear(const std::string &new_root=std::string());
00068
00069 typedef XMLnode::KeyType KeyType;
00070 typedef XMLnode::KeyTypeList KeyTypeList;
00071
00072 void getsubkeys(KeyTypeList &ktl, const std::string &basekey);
00073
00074 private:
00075 XMLnode *xmltree;
00076 std::string rootname;
00077 std::string filename;
00078 bool is_file;
00079 };
00080
00081
00082 extern Configuration *config;
00083
00084 #endif