Merge pull request #377 from lordhoto/config-manager-cleanup

Config Manager Cleanup
This commit is contained in:
Johannes Schickel 2013-08-12 14:30:22 -07:00
commit 818d3981e3
4 changed files with 29 additions and 10 deletions

View File

@ -827,9 +827,8 @@ void upgradeTargets() {
printf("Upgrading all your existing targets\n");
Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
Common::ConfigManager::DomainMap::iterator iter = domains.begin();
for (iter = domains.begin(); iter != domains.end(); ++iter) {
Common::ConfigManager::DomainMap::iterator iter = ConfMan.beginGameDomains();
for (; iter != ConfMan.endGameDomains(); ++iter) {
Common::ConfigManager::Domain &dom = iter->_value;
Common::String name(iter->_key);
Common::String gameid(dom.getVal("gameid"));

View File

@ -46,12 +46,31 @@ class ConfigManager : public Singleton<ConfigManager> {
public:
class Domain : public StringMap {
class Domain {
private:
StringMap _entries;
StringMap _keyValueComments;
String _domainComment;
public:
typedef StringMap::const_iterator const_iterator;
const_iterator begin() const { return _entries.begin(); }
const_iterator end() const { return _entries.end(); }
bool empty() const { return _entries.empty(); }
bool contains(const String &key) const { return _entries.contains(key); }
String &operator[](const String &key) { return _entries[key]; }
const String &operator[](const String &key) const { return _entries[key]; }
String &getVal(const String &key) { return _entries.getVal(key); }
const String &getVal(const String &key) const { return _entries.getVal(key); }
void clear() { _entries.clear(); }
void erase(const String &key) { _entries.erase(key); }
void setDomainComment(const String &comment);
const String &getDomainComment() const;
@ -142,7 +161,8 @@ public:
bool hasMiscDomain(const String &domName) const;
const DomainMap & getGameDomains() const { return _gameDomains; }
DomainMap & getGameDomains() { return _gameDomains; }
DomainMap::iterator beginGameDomains() { return _gameDomains.begin(); }
DomainMap::iterator endGameDomains() { return _gameDomains.end(); }
static void defragment(); // move in memory to reduce fragmentation
void copyFrom(ConfigManager &source);

View File

@ -372,8 +372,8 @@ SdlMixerManager *EventRecorder::getMixerManager() {
}
}
void EventRecorder::getConfigFromDomain(Common::ConfigManager::Domain *domain) {
for (Common::ConfigManager::Domain::iterator entry = domain->begin(); entry!= domain->end(); ++entry) {
void EventRecorder::getConfigFromDomain(const Common::ConfigManager::Domain *domain) {
for (Common::ConfigManager::Domain::const_iterator entry = domain->begin(); entry!= domain->end(); ++entry) {
_playbackFile->getHeader().settingsRecords[entry->_key] = entry->_value;
}
}
@ -386,7 +386,7 @@ void EventRecorder::getConfig() {
void EventRecorder::applyPlaybackSettings() {
for (Common::StringMap::iterator i = _playbackFile->getHeader().settingsRecords.begin(); i != _playbackFile->getHeader().settingsRecords.end(); ++i) {
for (Common::StringMap::const_iterator i = _playbackFile->getHeader().settingsRecords.begin(); i != _playbackFile->getHeader().settingsRecords.end(); ++i) {
Common::String currentValue = ConfMan.get(i->_key);
if (currentValue != i->_value) {
ConfMan.set(i->_key, i->_value, ConfMan.kTransientDomain);
@ -400,7 +400,7 @@ void EventRecorder::applyPlaybackSettings() {
}
void EventRecorder::removeDifferentEntriesInDomain(Common::ConfigManager::Domain *domain) {
for (Common::ConfigManager::Domain::iterator entry = domain->begin(); entry!= domain->end(); ++entry) {
for (Common::ConfigManager::Domain::const_iterator entry = domain->begin(); entry!= domain->end(); ++entry) {
if (_playbackFile->getHeader().settingsRecords.find(entry->_key) == _playbackFile->getHeader().settingsRecords.end()) {
debugC(1, kDebugLevelEventRec, "playback:action=\"Apply settings\" checksettings:key=%s storedvalue=%s currentvalue="" result=different", entry->_key.c_str(), entry->_value.c_str());
domain->erase(entry->_key);

View File

@ -199,7 +199,7 @@ private:
void setFileHeader();
void setGameMd5(const ADGameDescription *gameDesc);
void getConfig();
void getConfigFromDomain(Common::ConfigManager::Domain *domain);
void getConfigFromDomain(const Common::ConfigManager::Domain *domain);
void removeDifferentEntriesInDomain(Common::ConfigManager::Domain *domain);
void applyPlaybackSettings();