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 
00093     static char const *const kKeymapperDomain;
00094 
00095 #ifdef USE_CLOUD
00096 
00097     static char const *const kCloudDomain;
00098 #endif
00099 
00100     void                loadDefaultConfigFile();
00101     void                loadConfigFile(const String &filename);
00102 
00108     Domain *            getDomain(const String &domName);
00109     const Domain *      getDomain(const String &domName) const;
00110 
00111 
00112     //
00113     // Generic access methods: No domain specified, use the values from the
00114     // various domains in the order of their priority.
00115     //
00116 
00117     bool                hasKey(const String &key) const;
00118     const String &      get(const String &key) const;
00119     void                set(const String &key, const String &value);
00120 
00125     void                setAndFlush(const String &key, const Common::String &value);
00126 
00127 #if 1
00128     //
00129     // Domain specific access methods: Acces *one specific* domain and modify it.
00130     // TODO: I'd like to get rid of most of those if possible, or at least reduce
00131     // their usage, by using getDomain as often as possible. For example in the
00132     // options dialog code...
00133     //
00134 
00135     bool                hasKey(const String &key, const String &domName) const;
00136     const String &      get(const String &key, const String &domName) const;
00137     void                set(const String &key, const String &value, const String &domName);
00138 
00139     void                removeKey(const String &key, const String &domName);
00140 #endif
00141 
00142     //
00143     // Some additional convenience accessors.
00144     //
00145     int                 getInt(const String &key, const String &domName = String()) const;
00146     bool                getBool(const String &key, const String &domName = String()) const;
00147     void                setInt(const String &key, int value, const String &domName = String());
00148     void                setBool(const String &key, bool value, const String &domName = String());
00149 
00150 
00151     void                registerDefault(const String &key, const String &value);
00152     void                registerDefault(const String &key, const char *value);
00153     void                registerDefault(const String &key, int value);
00154     void                registerDefault(const String &key, bool value);
00155 
00156     void                flushToDisk();
00157 
00158     void                setActiveDomain(const String &domName);
00159     Domain *            getActiveDomain() { return _activeDomain; }
00160     const Domain *      getActiveDomain() const { return _activeDomain; }
00161     const String &      getActiveDomainName() const { return _activeDomainName; }
00162 
00163     void                addGameDomain(const String &domName);
00164     void                removeGameDomain(const String &domName);
00165     void                renameGameDomain(const String &oldName, const String &newName);
00166 
00167     void                addMiscDomain(const String &domName);
00168     void                removeMiscDomain(const String &domName);
00169     void                renameMiscDomain(const String &oldName, const String &newName);
00170 
00171     bool                hasGameDomain(const String &domName) const;
00172     bool                hasMiscDomain(const String &domName) const;
00173 
00174     const DomainMap &   getGameDomains() const { return _gameDomains; }
00175     DomainMap::iterator beginGameDomains() { return _gameDomains.begin(); }
00176     DomainMap::iterator endGameDomains() { return _gameDomains.end(); }
00177 
00178     static void         defragment(); // move in memory to reduce fragmentation
00179     void                copyFrom(ConfigManager &source);
00180 
00181 private:
00182     friend class Singleton<SingletonBaseType>;
00183     ConfigManager();
00184 
00185     void            loadFromStream(SeekableReadStream &stream);
00186     void            addDomain(const String &domainName, const Domain &domain);
00187     void            writeDomain(WriteStream &stream, const String &name, const Domain &domain);
00188     void            renameDomain(const String &oldName, const String &newName, DomainMap &map);
00189 
00190     Domain          _transientDomain;
00191     DomainMap       _gameDomains;
00192     DomainMap       _miscDomains; // Any other domains
00193     Domain          _appDomain;
00194     Domain          _defaultsDomain;
00195 
00196     Domain          _keymapperDomain;
00197 
00198 #ifdef USE_CLOUD
00199     Domain          _cloudDomain;
00200 #endif
00201 
00202     Array<String>   _domainSaveOrder;
00203 
00204     String          _activeDomainName;
00205     Domain *        _activeDomain;
00206 
00207     String          _filename;
00208 };
00209 
00210 } // End of namespace Common
00211 
00213 #define ConfMan     Common::ConfigManager::instance()
00214 
00215 #endif


Generated on Sat Sep 12 2020 05:00:56 for ResidualVM by doxygen 1.7.1
curved edge   curved edge