dbinfo.h
Go to the documentation of this file.00001 #ifndef DBINFO_HH
00002 #define DBINFO_HH
00003
00004
00005 #include <iostream>
00006 #include <fstream>
00007 #include <string>
00008 #include <map>
00009 #include <memory>
00010
00011
00012 using namespace std;
00013
00014
00015 struct aceparam {
00016 string host;
00017 int port;
00018 string path;
00019 aceparam() :host(), port(0), path("") {}
00020
00021 aceparam(const aceparam& ap) { host=ap.host; port=ap.port; path=ap.path; }
00022 aceparam(const string &h, const int p, const string &pa) : host(h), port(p), path(pa) {}
00023 aceparam& operator=(const aceparam& ap);
00024 friend ostream& operator<<(ostream &ou, const aceparam& ap) {
00025 ou << ap.host << ", " << ap.port << ", " << ap.path;
00026 return ou;
00027 }
00028 };
00029
00030
00031 class dbinfo {
00032 public:
00033 dbinfo() { if(hostmap.empty()) init(); }
00038 string getAddress(const string &hn);
00039 bool mapEmpty() const { return hostmap.empty(); }
00040
00045 static void init();
00049 static map<string, string> hostmap;
00050 };
00051
00052 class acedbinfo : public dbinfo {
00053 private:
00054 map<string, aceparam> info;
00055 public:
00056 acedbinfo();
00057 int getPort(const string &dbn);
00058 string getHost(const string &dbn);
00059 string getPath(const string &dbn);
00060 pair<string, int> connectInfo(const string &dbn);
00061 friend ostream& operator<<(ostream &ou, const acedbinfo& ai);
00062 };
00063
00064 class pgdbinfo : public dbinfo {
00065 private:
00066 map<string, string> info;
00067 public:
00068
00069 pgdbinfo();
00070 string getHost(const string &dbn);
00071 string getHostAddress(const string &dbn) { return getAddress(getHost(dbn)); }
00072 };
00073
00078 class MysqlDBInfo {
00079 private:
00082 string user;
00083 string password;
00085 static auto_ptr<MysqlDBInfo> onlyone;
00086
00087 protected:
00093 MysqlDBInfo();
00094
00095 public:
00097 ~MysqlDBInfo() { }
00101 string getUser() const { return user; }
00102 string getPassword() const { return password; }
00106 static MysqlDBInfo& getAuthenInfo() { if (onlyone.get() == 0) onlyone=auto_ptr<MysqlDBInfo>(new MysqlDBInfo); return *onlyone; }
00107 };
00108
00109 #endif