ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

config-manager.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_CONFIG_MANAGER_H
00024 #define COMMON_CONFIG_MANAGER_H
00025 
00026 #include "common/array.h"
00027 #include "common/hashmap.h"
00028 #include "common/singleton.h"
00029 #include "common/str.h"
00030 #include "common/hash-str.h"
00031 
00032 namespace Common {
00033 
00034 class WriteStream;
00035 class SeekableReadStream;
00036 
00045 class ConfigManager : public Singleton<ConfigManager> {
00046 
00047 public:
00048 
00049     class Domain {
00050     private:
00051         StringMap _entries;
00052         StringMap _keyValueComments;
00053         String _domainComment;
00054 
00055     public:
00056         typedef StringMap::const_iterator const_iterator;
00057         const_iterator begin() const { return _entries.begin(); }
00058         const_iterator end()   const { return _entries.end(); }
00059 
00060         bool empty() const { return _entries.empty(); }
00061 
00062         bool contains(const String &key) const { return _entries.contains(key); }
00063 
00064         String &operator[](const String &key) { return _entries[key]; }
00065         const String &operator[](const String &key) const { return _entries[key]; }
00066 
00067         void setVal(const String &key, const String &value) { _entries.setVal(key, value); }
00068 
00069         String &getVal(const String &key) { return _entries.getVal(key); }
00070         const String &getVal(const String &key) const { return _entries.getVal(key); }
00071 
00072         void clear() { _entries.clear(); }
00073 
00074         void erase(const String &key) { _entries.erase(key); }
00075 
00076         void setDomainComment(const String &comment);
00077         const String &getDomainComment() const;
00078 
00079         void setKVComment(const String &key, const String &comment);
00080         const String &getKVComment(const String &key) const;
00081         bool hasKVComment(const String &key) const;
00082     };
00083 
00084     typedef HashMap<String, Domain, IgnoreCase_Hash, IgnoreCase_EqualTo> DomainMap;
00085 
00087     static char const *const kApplicationDomain;
00088 
00090     static char const *const kTransientDomain;
00091 
00092 #ifdef ENABLE_KEYMAPPER
00093 
00094     static char const *const kKeymapperDomain;
00095 #endif
00096 
00097 #ifdef USE_CLOUD
00098 
00099     static char const *const kCloudDomain;
00100 #endif
00101 
00102     void                loadDefaultConfigFile();
00103     void                loadConfigFile(const String &filename);
00104 
00110     Domain *            getDomain(const String &domName);
00111     const Domain *      getDomain(const String &domName) const;
00112 
00113 
00114     //
00115     // Generic access methods: No domain specified, use the values from the
00116     // various domains in the order of their priority.
00117     //
00118 
00119     bool                hasKey(const String &key) const;
00120     const String &      get(const String &key) const;
00121     void                set(const String &key, const String &value);
00122 
00123 #if 1
00124     //
00125     // Domain specific access methods: Acces *one specific* domain and modify it.
00126     // TODO: I'd like to get rid of most of those if possible, or at least reduce
00127     // their usage, by using getDomain as often as possible. For example in the
00128     // options dialog code...
00129     //
00130 
00131     bool                hasKey(const String &key, const String &domName) const;
00132     const String &      get(const String &key, const String &domName) const;
00133     void                set(const String &key, const String &value, const String &domName);
00134 
00135     void                removeKey(const String &key, const String &domName);
00136 #endif
00137 
00138     //
00139     // Some additional convenience accessors.
00140     //
00141     int                 getInt(const String &key, const String &domName = String()) const;
00142     bool                getBool(const String &key, const String &domName = String()) const;
00143     void                setInt(const String &key, int value, const String &domName = String());
00144     void                setBool(const String &key, bool value, const String &domName = String());
00145 
00146 
00147     void                registerDefault(const String &key, const String &value);
00148     void                registerDefault(const String &key, const char *value);
00149     void                registerDefault(const String &key, int value);
00150     void                registerDefault(const String &key, bool value);
00151 
00152     void                flushToDisk();
00153 
00154     void                setActiveDomain(const String &domName);
00155     Domain *            getActiveDomain() { return _activeDomain; }
00156     const Domain *      getActiveDomain() const { return _activeDomain; }
00157     const String &      getActiveDomainName() const { return _activeDomainName; }
00158 
00159     void                addGameDomain(const String &domName);
00160     void                removeGameDomain(const String &domName);
00161     void                renameGameDomain(const String &oldName, const String &newName);
00162 
00163     void                addMiscDomain(const String &domName);
00164     void                removeMiscDomain(const String &domName);
00165     void                renameMiscDomain(const String &oldName, const String &newName);
00166 
00167     bool                hasGameDomain(const String &domName) const;
00168     bool                hasMiscDomain(const String &domName) const;
00169 
00170     const DomainMap &   getGameDomains() const { return _gameDomains; }
00171     DomainMap::iterator beginGameDomains() { return _gameDomains.begin(); }
00172     DomainMap::iterator endGameDomains() { return _gameDomains.end(); }
00173 
00174     static void         defragment(); // move in memory to reduce fragmentation
00175     void                copyFrom(ConfigManager &source);
00176 
00177 private:
00178     friend class Singleton<SingletonBaseType>;
00179     ConfigManager();
00180 
00181     void            loadFromStream(SeekableReadStream &stream);
00182     void            addDomain(const String &domainName, const Domain &domain);
00183     void            writeDomain(WriteStream &stream, const String &name, const Domain &domain);
00184     void            renameDomain(const String &oldName, const String &newName, DomainMap &map);
00185 
00186     Domain          _transientDomain;
00187     DomainMap       _gameDomains;
00188     DomainMap       _miscDomains; // Any other domains
00189     Domain          _appDomain;
00190     Domain          _defaultsDomain;
00191 
00192 #ifdef ENABLE_KEYMAPPER
00193     Domain          _keymapperDomain;
00194 #endif
00195 
00196 #ifdef USE_CLOUD
00197     Domain          _cloudDomain;
00198 #endif
00199 
00200     Array<String>   _domainSaveOrder;
00201 
00202     String          _activeDomainName;
00203     Domain *        _activeDomain;
00204 
00205     String          _filename;
00206 };
00207 
00208 } // End of namespace Common
00209 
00211 #define ConfMan     Common::ConfigManager::instance()
00212 
00213 #endif


Generated on Sat Nov 16 2019 05:00:32 for ResidualVM by doxygen 1.7.1
curved edge   curved edge