aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2009-01-30 05:03:04 +0000
committerMax Horn2009-01-30 05:03:04 +0000
commit7b50c293e6c509142e204e1aa11d51204cda9073 (patch)
tree6e0d5a81d881ff00461e7019f1a4a174bb67e59d /common
parent76deee02d6b2638cd04be6cfb50aaf217b6252ee (diff)
downloadscummvm-rg350-7b50c293e6c509142e204e1aa11d51204cda9073.tar.gz
scummvm-rg350-7b50c293e6c509142e204e1aa11d51204cda9073.tar.bz2
scummvm-rg350-7b50c293e6c509142e204e1aa11d51204cda9073.zip
Switched special debug levels to using a hashmap internally
svn-id: r36141
Diffstat (limited to 'common')
-rw-r--r--common/debug.cpp56
-rw-r--r--common/debug.h2
2 files changed, 26 insertions, 32 deletions
diff --git a/common/debug.cpp b/common/debug.cpp
index 1c232c0662..3118183713 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -24,6 +24,7 @@
#include "common/debug.h"
#include "common/util.h"
+#include "common/hashmap.h"
#include "engines/engine.h"
@@ -57,37 +58,24 @@ namespace Common {
namespace {
-static SpecialDebugLevelList gDebugLevels;
+typedef HashMap<String, SpecialDebugLevel, IgnoreCase_Hash, IgnoreCase_EqualTo> DebugLevelMap;
+
+static DebugLevelMap gDebugLevels;
static uint32 gDebugLevelsEnabled = 0;
-struct DebugLevelSort {
+struct DebugLevelComperator {
bool operator()(const SpecialDebugLevel &l, const SpecialDebugLevel &r) {
return (l.name.compareToIgnoreCase(r.name) < 0);
}
};
-struct DebugLevelSearch {
- const String &_name;
-
- DebugLevelSearch(const String &name) : _name(name) {}
-
- bool operator()(const SpecialDebugLevel &l) {
- return _name.equalsIgnoreCase(l.name);
- }
-};
-
}
bool addSpecialDebugLevel(uint32 level, const String &name, const String &description) {
- SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name));
-
- if (i != gDebugLevels.end()) {
- warning("Declared engine debug level '%s' again", name.c_str());
- *i = SpecialDebugLevel(level, name, description);
- } else {
- gDebugLevels.push_back(SpecialDebugLevel(level, name, description));
- sort(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSort());
+ if (gDebugLevels.contains(name)) {
+ warning("Duplicate declaration of engine debug level '%s'", name.c_str());
}
+ gDebugLevels[name] = SpecialDebugLevel(level, name, description);
return true;
}
@@ -98,11 +86,11 @@ void clearAllSpecialDebugLevels() {
}
bool enableSpecialDebugLevel(const String &name) {
- SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name));
+ DebugLevelMap::iterator i = gDebugLevels.find(name);
if (i != gDebugLevels.end()) {
- gDebugLevelsEnabled |= i->level;
- i->enabled = true;
+ gDebugLevelsEnabled |= i->_value.level;
+ i->_value.enabled = true;
return true;
} else {
@@ -110,12 +98,12 @@ bool enableSpecialDebugLevel(const String &name) {
}
}
-bool disableSpecialDebugLevel(const String &option) {
- SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+bool disableSpecialDebugLevel(const String &name) {
+ DebugLevelMap::iterator i = gDebugLevels.find(name);
if (i != gDebugLevels.end()) {
- gDebugLevelsEnabled &= ~i->level;
- i->enabled = false;
+ gDebugLevelsEnabled &= ~i->_value.level;
+ i->_value.enabled = false;
return true;
} else {
@@ -123,8 +111,14 @@ bool disableSpecialDebugLevel(const String &option) {
}
}
-const SpecialDebugLevelList &listSpecialDebugLevels() {
- return gDebugLevels;
+
+SpecialDebugLevelList listSpecialDebugLevels() {
+ SpecialDebugLevelList tmp;
+ for (DebugLevelMap::iterator i = gDebugLevels.begin(); i != gDebugLevels.end(); ++i)
+ tmp.push_back(i->_value);
+ sort(tmp.begin(), tmp.end(), DebugLevelComperator());
+
+ return tmp;
}
bool isSpecialDebugLevelEnabled(uint32 level) {
@@ -141,9 +135,9 @@ bool isSpecialDebugLevelEnabled(const String &name) {
return true;
// Search for the debug level with the given name and check if it is enabled
- SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name));
+ DebugLevelMap::iterator i = gDebugLevels.find(name);
if (i != gDebugLevels.end())
- return gDebugLevelsEnabled & i->level;
+ return i->_value.enabled;
return false;
}
diff --git a/common/debug.h b/common/debug.h
index 5d58af03a6..5ee1dd4791 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -82,7 +82,7 @@ typedef List<SpecialDebugLevel> SpecialDebugLevelList;
* Lists all debug levels
* @return returns a arry with all debug levels
*/
-const SpecialDebugLevelList &listSpecialDebugLevels();
+SpecialDebugLevelList listSpecialDebugLevels();
/**