[Scummvm-cvs-logs] SF.net SVN: scummvm: [21477] scummvm/trunk/common
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Mar 28 04:37:01 CEST 2006
Revision: 21477
Author: fingolfin
Date: 2006-03-28 04:35:50 -0800 (Tue, 28 Mar 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=21477&view=rev
Log Message:
-----------
- Renamed Map::remove to Map::erase (matching the STL and HashMap)
- Added Map::find() (see also HashMap), and made the ConfigManager use it
Modified Paths:
--------------
scummvm/trunk/common/config-manager.cpp
scummvm/trunk/common/map.h
Modified: scummvm/trunk/common/config-manager.cpp
===================================================================
--- scummvm/trunk/common/config-manager.cpp 2006-03-28 12:34:34 UTC (rev 21476)
+++ scummvm/trunk/common/config-manager.cpp 2006-03-28 12:35:50 UTC (rev 21477)
@@ -339,11 +339,11 @@
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 @@
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 @@
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::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 @@
_gameDomains[newName].merge(_gameDomains[oldName]);
- _gameDomains.remove(oldName);
+ _gameDomains.erase(oldName);
}
bool ConfigManager::hasGameDomain(const String &domain) const {
@@ -516,11 +516,14 @@
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
}
Modified: scummvm/trunk/common/map.h
===================================================================
--- scummvm/trunk/common/map.h 2006-03-28 12:34:34 UTC (rev 21476)
+++ scummvm/trunk/common/map.h 2006-03-28 12:35:50 UTC (rev 21477)
@@ -166,13 +166,13 @@
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 @@
// Finally free the allocated memory
delete node;
+
+ return 1;
}
-
+
void merge(const Map<Key, Value, Comparator> &map) {
merge(map._root);
}
@@ -225,6 +227,14 @@
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) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list