SettingManager.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2004 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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

Generated on Fri Jul 27 22:27:36 2007 for pentagram by  doxygen 1.4.7