00001
00002
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef __CONFIG_H
00051 #define __CONFIG_H
00052
00053 extern "C" {
00054 #include <stdlib.h>
00055 #include <pthread.h>
00056 };
00057
00058 #include <string>
00059 #include <fstream>
00060 #include <map>
00061 #include <vector>
00062
00063 #include <loki/SmartPtr.h>
00064
00065 using std::string;
00066
00076 #undef CONFIGURATION_DEBUGGING
00077
00083 class Config : public std::map<string,string> {
00084 protected:
00085 Config(const string&);
00086
00087 public:
00088 virtual ~Config();
00089
00091 virtual void load_entry(const string&) = 0;
00092
00096
00097 protected:
00099 string filename;
00100
00101 private:
00102 static const char* keytexts[];
00103 protected:
00105 static const std::vector<std::string> config_keys;
00106 };
00107
00109 typedef Loki::SmartPtr<Config,
00110 Loki::RefCountedMTAdj<Loki::ObjectLevelLockable>::RefCountedMT>
00111 ConfigP;
00112
00121 class ConfigFactory {
00127 public:
00130 static Config *config_object(const string&);
00131
00132 private:
00133 template <class CFG_type>
00134 static Config *new_config(const string&);
00135 };
00136
00143 class ConfigException : public std::exception {
00144 public:
00145 ConfigException(const string&);
00146 ConfigException(const string&, const string&, const int);
00147 virtual ~ConfigException() throw() {}
00148
00149
00150 virtual const char *what(void) const throw();
00151
00152 void set_file(const string&);
00153 void set_line(const int);
00154
00155 protected:
00156 string reason;
00157 string file;
00158 int line;
00159 };
00160
00164 class ConfigBadFile : public ConfigException {
00165 public:
00166 ConfigBadFile(const std::string &thefile, const int err=0)
00167 : ConfigException(""),saved_errno(err) { set_file(thefile); }
00168
00169 virtual const char *what(void) const throw();
00170 private:
00171 int saved_errno;
00172 };
00173
00175 class ConfigParseException : public ConfigException {
00176 public:
00177 ConfigParseException(const int l, const string &r);
00178 };
00179
00185 class ConfigUnfoundException : public ConfigException {
00186 public:
00187 ConfigUnfoundException(const string &node, const string &r = "");
00188 virtual ~ConfigUnfoundException() throw() {};
00189
00190 const string &which(void) { return(node); }
00191
00192 virtual const char *what(void) const throw();
00193
00194 private:
00195 string node;
00196 };
00197
00199
00200 #endif