00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SETTINGMANAGER_H
00020 #define SETTINGMANAGER_H
00021
00022 #include <string>
00023 #include "istring.h"
00024 #include <map>
00025 #include <vector>
00026
00027 class ConfigFileManager;
00028
00029 class SettingManager
00030 {
00031 public:
00032 SettingManager();
00033 ~SettingManager();
00034
00035 static SettingManager* get_instance() { return settingmanager; }
00036
00037 enum Domain {
00038 DOM_DEFAULTS = 0,
00039 DOM_GLOBAL = 1,
00040 DOM_GAME = 2,
00041 DOM_CURRENT = 100
00042 };
00043
00048 bool readConfigFile(std::string fname, bool readonly=false);
00049
00051 void write();
00052
00054 bool exists(Pentagram::istring key, Domain dom = DOM_CURRENT);
00055
00057 bool get(Pentagram::istring key,std::string &ret,Domain dom = DOM_CURRENT);
00059 bool get(Pentagram::istring key, int &ret, Domain dom = DOM_CURRENT);
00061 bool get(Pentagram::istring key, bool &ret, Domain dom = DOM_CURRENT);
00062
00064 void set(Pentagram::istring key,std::string value,Domain dom=DOM_CURRENT);
00066 void set(Pentagram::istring key,const char* value,Domain dom=DOM_CURRENT);
00068 void set(Pentagram::istring key, int value, Domain dom = DOM_CURRENT);
00070 void set(Pentagram::istring key, bool value, Domain dom = DOM_CURRENT);
00071
00073 void unset(Pentagram::istring key, Domain dom = DOM_CURRENT);
00074
00076 void setDefault(Pentagram::istring key, std::string value);
00078 void setDefault(Pentagram::istring key, const char* value);
00080 void setDefault(Pentagram::istring key, int value);
00082 void setDefault(Pentagram::istring key, bool value);
00083
00085 void setCurrentDomain(Domain dom);
00087 void setDomainName(Domain dom, Pentagram::istring section);
00088
00089 typedef void (*ConfigCallback)(Pentagram::istring key);
00090
00092 void registerCallback(Pentagram::istring key, ConfigCallback callback);
00094 void unregisterCallback(Pentagram::istring key, ConfigCallback callback);
00095
00097 std::vector<Pentagram::istring> listGames();
00098
00102 std::vector<Pentagram::istring> listDataKeys(Pentagram::istring section);
00103
00107 std::map<Pentagram::istring,std::string> listDataValues(
00108 Pentagram::istring section);
00109
00110 private:
00111
00112 bool findKeyDomain(Pentagram::istring key, Domain dom, Domain& keydom);
00113 Pentagram::istring getConfigKey(Pentagram::istring key, Domain dom);
00114 void callCallbacks(Pentagram::istring key);
00115
00116 std::map<Pentagram::istring, std::vector<ConfigCallback> > callbacks;
00117 std::vector<Pentagram::istring> domains;
00118
00119 Domain currentDomain;
00120
00121 ConfigFileManager* conffileman;
00122
00123 static SettingManager* settingmanager;
00124 };
00125
00126 #endif