mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-10 04:43:26 +00:00
- 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
This commit is contained in:
parent
41991f88a9
commit
37c79be740
@ -339,11 +339,11 @@ void ConfigManager::removeKey(const String &key, const String &dom) {
|
|||||||
assert(isValidDomainName(dom));
|
assert(isValidDomainName(dom));
|
||||||
|
|
||||||
if (dom == kTransientDomain)
|
if (dom == kTransientDomain)
|
||||||
_transientDomain.remove(key);
|
_transientDomain.erase(key);
|
||||||
else if (_gameDomains.contains(dom))
|
else if (_gameDomains.contains(dom))
|
||||||
_gameDomains[dom].remove(key);
|
_gameDomains[dom].erase(key);
|
||||||
else if (_globalDomains.contains(dom))
|
else if (_globalDomains.contains(dom))
|
||||||
_globalDomains[dom].remove(key);
|
_globalDomains[dom].erase(key);
|
||||||
else
|
else
|
||||||
error("Removing key '%s' from non-existent domain '%s'", key.c_str(), dom.c_str());
|
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));
|
assert(isValidDomainName(dom));
|
||||||
if (dom.empty()) {
|
if (dom.empty()) {
|
||||||
// Remove the transient domain value
|
// Remove the transient domain value
|
||||||
_transientDomain.remove(key);
|
_transientDomain.erase(key);
|
||||||
|
|
||||||
if (_activeDomain.empty())
|
if (_activeDomain.empty())
|
||||||
_globalDomains[kApplicationDomain][key] = value;
|
_globalDomains[kApplicationDomain][key] = value;
|
||||||
@ -429,11 +429,11 @@ void ConfigManager::set(const String &key, const String &value, const String &do
|
|||||||
if (_globalDomains.contains(dom)) {
|
if (_globalDomains.contains(dom)) {
|
||||||
_globalDomains[dom][key] = value;
|
_globalDomains[dom][key] = value;
|
||||||
if (_activeDomain.empty() || !_gameDomains[_activeDomain].contains(key))
|
if (_activeDomain.empty() || !_gameDomains[_activeDomain].contains(key))
|
||||||
_transientDomain.remove(key);
|
_transientDomain.erase(key);
|
||||||
} else {
|
} else {
|
||||||
_gameDomains[dom][key] = value;
|
_gameDomains[dom][key] = value;
|
||||||
if (dom == _activeDomain)
|
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) {
|
void ConfigManager::removeGameDomain(const String &domain) {
|
||||||
assert(!domain.empty());
|
assert(!domain.empty());
|
||||||
assert(isValidDomainName(domain));
|
assert(isValidDomainName(domain));
|
||||||
_gameDomains.remove(domain);
|
_gameDomains.erase(domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigManager::renameGameDomain(const String &oldName, const String &newName) {
|
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[newName].merge(_gameDomains[oldName]);
|
||||||
|
|
||||||
_gameDomains.remove(oldName);
|
_gameDomains.erase(oldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigManager::hasGameDomain(const String &domain) const {
|
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 {
|
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__))
|
#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
|
||||||
return node ? node->_value : String::emptyString;
|
return String::emptyString;
|
||||||
#else
|
#else
|
||||||
return node ? node->_value : ConfMan._emptyString;
|
return ConfMan._emptyString;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
common/map.h
16
common/map.h
@ -166,13 +166,13 @@ public:
|
|||||||
return node->_value;
|
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?
|
// TODO - implement efficiently. Indeed, maybe switch to using red-black trees?
|
||||||
// For now, just a lame, bad remove algorithm. Rule: don't remove elements
|
// For now, just a lame, bad remove algorithm. Rule: don't remove elements
|
||||||
// from one of our maps if you need to be efficient :-)
|
// from one of our maps if you need to be efficient :-)
|
||||||
Node *node = findNode(_root, key);
|
Node *node = findNode(_root, key);
|
||||||
if (!node)
|
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.
|
// Now we have to remove 'node'. There are two simple cases and one hard.
|
||||||
Node *parent = node->_parent;
|
Node *parent = node->_parent;
|
||||||
@ -206,8 +206,10 @@ public:
|
|||||||
|
|
||||||
// Finally free the allocated memory
|
// Finally free the allocated memory
|
||||||
delete node;
|
delete node;
|
||||||
}
|
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void merge(const Map<Key, Value, Comparator> &map) {
|
void merge(const Map<Key, Value, Comparator> &map) {
|
||||||
merge(map._root);
|
merge(map._root);
|
||||||
}
|
}
|
||||||
@ -225,6 +227,14 @@ public:
|
|||||||
return const_iterator();
|
return const_iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_iterator find(const Key &key) const {
|
||||||
|
Node *node = findNode(_root, key);
|
||||||
|
if (node)
|
||||||
|
return const_iterator(node);
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Merge the content of the given tree into this tree. */
|
/** Merge the content of the given tree into this tree. */
|
||||||
void merge(const Node *node) {
|
void merge(const Node *node) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user