aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2006-03-28 12:35:50 +0000
committerMax Horn2006-03-28 12:35:50 +0000
commit37c79be74011eae8a78e369b455c565ebe5b6c8d (patch)
tree21b0be7617e1b09c3e136b135cee4563dfbf4f01
parent41991f88a930d55804e2ed5b30cf04c4c3943c68 (diff)
downloadscummvm-rg350-37c79be74011eae8a78e369b455c565ebe5b6c8d.tar.gz
scummvm-rg350-37c79be74011eae8a78e369b455c565ebe5b6c8d.tar.bz2
scummvm-rg350-37c79be74011eae8a78e369b455c565ebe5b6c8d.zip
- Renamed Map::remove to Map::erase (matching the STL and HashMap)
- Added Map::find() (see also HashMap), and made the ConfigManager use it svn-id: r21477
-rw-r--r--common/config-manager.cpp25
-rw-r--r--common/map.h16
2 files changed, 27 insertions, 14 deletions
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 17f7d3bd62..4c4839e4ee 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -339,11 +339,11 @@ void ConfigManager::removeKey(const String &key, const String &dom) {
assert(isValidDomainName(dom));
if (dom == kTransientDomain)
- _transientDomain.remove(key);
+ _transientDomain.erase(key);
else if (_gameDomains.contains(dom))
- _gameDomains[dom].remove(key);
+ _gameDomains[dom].erase(key);
else if (_globalDomains.contains(dom))
- _globalDomains[dom].remove(key);
+ _globalDomains[dom].erase(key);
else
error("Removing key '%s' from non-existent domain '%s'", key.c_str(), dom.c_str());
}
@@ -414,7 +414,7 @@ void ConfigManager::set(const String &key, const String &value, const String &do
assert(isValidDomainName(dom));
if (dom.empty()) {
// Remove the transient domain value
- _transientDomain.remove(key);
+ _transientDomain.erase(key);
if (_activeDomain.empty())
_globalDomains[kApplicationDomain][key] = value;
@@ -429,11 +429,11 @@ void ConfigManager::set(const String &key, const String &value, const String &do
if (_globalDomains.contains(dom)) {
_globalDomains[dom][key] = value;
if (_activeDomain.empty() || !_gameDomains[_activeDomain].contains(key))
- _transientDomain.remove(key);
+ _transientDomain.erase(key);
} else {
_gameDomains[dom][key] = value;
if (dom == _activeDomain)
- _transientDomain.remove(key);
+ _transientDomain.erase(key);
}
}
}
@@ -489,7 +489,7 @@ void ConfigManager::setActiveDomain(const String &domain) {
void ConfigManager::removeGameDomain(const String &domain) {
assert(!domain.empty());
assert(isValidDomainName(domain));
- _gameDomains.remove(domain);
+ _gameDomains.erase(domain);
}
void ConfigManager::renameGameDomain(const String &oldName, const String &newName) {
@@ -503,7 +503,7 @@ void ConfigManager::renameGameDomain(const String &oldName, const String &newNam
_gameDomains[newName].merge(_gameDomains[oldName]);
- _gameDomains.remove(oldName);
+ _gameDomains.erase(oldName);
}
bool ConfigManager::hasGameDomain(const String &domain) const {
@@ -516,11 +516,14 @@ bool ConfigManager::hasGameDomain(const String &domain) const {
const String &ConfigManager::Domain::get(const String &key) const {
- Node *node = findNode(_root, key);
+ const_iterator iter(find(key));
+ if (iter != end())
+ return iter->_value;
+
#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
- return node ? node->_value : String::emptyString;
+ return String::emptyString;
#else
- return node ? node->_value : ConfMan._emptyString;
+ return ConfMan._emptyString;
#endif
}
diff --git a/common/map.h b/common/map.h
index caedd8eb9b..bbc9709507 100644
--- a/common/map.h
+++ b/common/map.h
@@ -166,13 +166,13 @@ public:
return node->_value;
}
- void remove(const Key &key) {
+ size_t erase(const Key &key) {
// TODO - implement efficiently. Indeed, maybe switch to using red-black trees?
// For now, just a lame, bad remove algorithm. Rule: don't remove elements
// from one of our maps if you need to be efficient :-)
Node *node = findNode(_root, key);
if (!node)
- return;
+ return 0; // key wasn't present, so no work has to be done
// Now we have to remove 'node'. There are two simple cases and one hard.
Node *parent = node->_parent;
@@ -206,8 +206,10 @@ public:
// Finally free the allocated memory
delete node;
- }
+ return 1;
+ }
+
void merge(const Map<Key, Value, Comparator> &map) {
merge(map._root);
}
@@ -225,6 +227,14 @@ public:
return const_iterator();
}
+ const_iterator find(const Key &key) const {
+ Node *node = findNode(_root, key);
+ if (node)
+ return const_iterator(node);
+ return end();
+ }
+
+
protected:
/** Merge the content of the given tree into this tree. */
void merge(const Node *node) {