[Scummvm-cvs-logs] SF.net SVN: scummvm: [32195] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue May 20 18:37:35 CEST 2008


Revision: 32195
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32195&view=rev
Author:   lordhoto
Date:     2008-05-20 09:37:32 -0700 (Tue, 20 May 2008)

Log Message:
-----------
Cleaned up engine debug level code.

Modified Paths:
--------------
    scummvm/trunk/common/util.cpp
    scummvm/trunk/common/util.h
    scummvm/trunk/engines/scumm/debugger.cpp
    scummvm/trunk/gui/debugger.cpp

Modified: scummvm/trunk/common/util.cpp
===================================================================
--- scummvm/trunk/common/util.cpp	2008-05-20 15:54:27 UTC (rev 32194)
+++ scummvm/trunk/common/util.cpp	2008-05-20 16:37:32 UTC (rev 32195)
@@ -394,18 +394,40 @@
 
 #pragma mark -
 
-static Array<EngineDebugLevel> gDebugLevels;
-static uint32 gDebugLevelsEnabled = 0;
+namespace {
 
+DebugLevelContainer gDebugLevels;
+uint32 gDebugLevelsEnabled = 0;
+
+struct DebugLevelSort {
+	bool operator()(const EngineDebugLevel &l, const EngineDebugLevel &r) {
+		return (l.option.compareToIgnoreCase(r.option) < 0);
+	}
+};
+
+struct DebugLevelSearch {
+	const String &_option;
+
+	DebugLevelSearch(const String &option) : _option(option) {}
+
+	bool operator()(const EngineDebugLevel &l) {
+		return _option.equalsIgnoreCase(l.option);
+	}
+};
+
+}
+
 bool addSpecialDebugLevel(uint32 level, const String &option, const String &description) {
-	for (uint i = 0; i < gDebugLevels.size(); ++i) {
-		if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) {
-			warning("Declared engine debug level '%s' again", option.c_str());
-			gDebugLevels[i] = EngineDebugLevel(level, option, description);
-			return true;
-		}
+	DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+
+	if (i != gDebugLevels.end()) {
+		warning("Declared engine debug level '%s' again", option.c_str());
+		*i = EngineDebugLevel(level, option, description);
+	} else {
+		gDebugLevels.push_back(EngineDebugLevel(level, option, description));
+		sort(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSort());
 	}
-	gDebugLevels.push_back(EngineDebugLevel(level, option, description));
+
 	return true;
 }
 
@@ -415,43 +437,43 @@
 }
 
 bool enableSpecialDebugLevel(const String &option) {
-	for (uint i = 0; i < gDebugLevels.size(); ++i) {
-		if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) {
-			gDebugLevelsEnabled |= gDebugLevels[i].level;
-			gDebugLevels[i].enabled = true;
-			return true;
-		}
+	DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+
+	if (i != gDebugLevels.end()) {
+		gDebugLevelsEnabled |= i->level;
+		i->enabled = true;
+
+		return true;
+	} else {
+		return false;
 	}
-	return false;
 }
 
 void enableSpecialDebugLevelList(const String &option) {
-	uint start = 0;
-	uint end = 0;
+	StringTokenizer tokenizer(option, " ,");
+	String token;
 
-	const char *str = option.c_str();
-	for (end = start + 1; end <= option.size(); ++end) {
-		if (str[end] == ',' || end == option.size()) {
-			if (!enableSpecialDebugLevel(Common::String(&str[start], end-start))) {
-				warning("Engine does not support debug level '%s'", Common::String(&str[start], end-start).c_str());
-			}
-			start = end + 1;
-		}
+	while (!tokenizer.empty()) {
+		token = tokenizer.nextToken();
+		if (!enableSpecialDebugLevel(token))
+			warning("Engine does not support debug level '%s'", token.c_str());
 	}
 }
 
 bool disableSpecialDebugLevel(const String &option) {
-	for (uint i = 0; i < gDebugLevels.size(); ++i) {
-		if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) {
-			gDebugLevelsEnabled &= ~gDebugLevels[i].level;
-			gDebugLevels[i].enabled = false;
-			return true;
-		}
+	DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option));
+
+	if (i != gDebugLevels.end()) {
+		gDebugLevelsEnabled &= ~i->level;
+		i->enabled = false;
+
+		return true;
+	} else {
+		return false;
 	}
-	return false;
 }
 
-const Array<EngineDebugLevel> &listSpecialDebugLevels() {
+const DebugLevelContainer &listSpecialDebugLevels() {
 	return gDebugLevels;
 }
 

Modified: scummvm/trunk/common/util.h
===================================================================
--- scummvm/trunk/common/util.h	2008-05-20 15:54:27 UTC (rev 32194)
+++ scummvm/trunk/common/util.h	2008-05-20 16:37:32 UTC (rev 32195)
@@ -27,7 +27,7 @@
 
 #include "common/scummsys.h"
 #include "common/str.h"
-#include "common/array.h"
+#include "common/list.h"
 
 #ifdef MIN
 #undef MIN
@@ -308,11 +308,13 @@
  */
 bool disableSpecialDebugLevel(const String &option);
 
+typedef List<EngineDebugLevel> DebugLevelContainer;
+
 /**
  * Lists all debug levels
  * @return returns a arry with all debug levels
  */
-const Array<EngineDebugLevel> &listSpecialDebugLevels();
+const DebugLevelContainer &listSpecialDebugLevels();
 
 /**
  * Return the active debug flag mask (i.e. all active debug flags ORed

Modified: scummvm/trunk/engines/scumm/debugger.cpp
===================================================================
--- scummvm/trunk/engines/scumm/debugger.cpp	2008-05-20 15:54:27 UTC (rev 32194)
+++ scummvm/trunk/engines/scumm/debugger.cpp	2008-05-20 16:37:32 UTC (rev 32195)
@@ -498,25 +498,24 @@
 }
 
 bool ScummDebugger::Cmd_Debug(int argc, const char **argv) {
-	Common::Array<Common::EngineDebugLevel> lvls = Common::listSpecialDebugLevels();
+	const Common::DebugLevelContainer &lvls = Common::listSpecialDebugLevels();
 
 	bool setFlag = false;	// Remove or add debug channel?
 
 	if ((argc == 1) && (Common::getEnabledSpecialDebugLevels() == 0)) {
 		DebugPrintf("No debug flags are enabled\n");
 		DebugPrintf("Available Channels: ");
-		for (uint i = 0; i < lvls.size(); i++) {
-			DebugPrintf("%s, ", lvls[i].option.c_str());
+		for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
+			DebugPrintf("%s, ", i->option.c_str());
 		}
 		DebugPrintf("\n");
 		return true;
 	}
 
 	if ((argc == 1) && (Common::getEnabledSpecialDebugLevels() > 0)) {
-		for (uint i = 0; i < lvls.size(); i++) {
-			if (lvls[i].enabled)
-				DebugPrintf("%s - %s\n", lvls[i].option.c_str(),
-							 lvls[i].description.c_str());
+		for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
+			if (i->enabled)
+				DebugPrintf("%s - %s\n", i->option.c_str(), i->description.c_str());
 		}
 		return true;
 	}
@@ -529,25 +528,24 @@
 	} else {
 		DebugPrintf("Syntax: Debug +CHANNEL, or Debug -CHANNEL\n");
 		DebugPrintf("Available Channels: ");
-		for (uint i = 0; i < lvls.size(); i++) {
-			DebugPrintf("%s, ", lvls[i].option.c_str());
-			DebugPrintf("\n");
+		for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
+			DebugPrintf("%s\n", i->option.c_str());
 		}
 	}
 
 	// Identify flag
 	const char *realFlag = argv[1] + 1;
-	for (uint i = 0; i < lvls.size(); i++) {
-		if ((scumm_stricmp(lvls[i].option.c_str(), realFlag)) == 0) {
+	for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) {
+		if (i->option.equalsIgnoreCase(realFlag)) {
 			if (setFlag) {
-				enableSpecialDebugLevel(lvls[i].option);
+				enableSpecialDebugLevel(i->option);
 				DebugPrintf("Enable ");
 			} else {
-				disableSpecialDebugLevel(lvls[i].option);
+				disableSpecialDebugLevel(i->option);
 				DebugPrintf("Disable ");
 			}
 
-			DebugPrintf("%s\n", lvls[i].description.c_str());
+			DebugPrintf("%s\n", i->description.c_str());
 			return true;
 		}
 	}

Modified: scummvm/trunk/gui/debugger.cpp
===================================================================
--- scummvm/trunk/gui/debugger.cpp	2008-05-20 15:54:27 UTC (rev 32194)
+++ scummvm/trunk/gui/debugger.cpp	2008-05-20 16:37:32 UTC (rev 32195)
@@ -406,7 +406,7 @@
 }
 
 bool Debugger::Cmd_DebugFlagsList(int argc, const char **argv) {
-	const Common::Array<Common::EngineDebugLevel> &debugLevels = Common::listSpecialDebugLevels();
+	const Common::DebugLevelContainer &debugLevels = Common::listSpecialDebugLevels();
 
 	DebugPrintf("Engine debug levels:\n");
 	DebugPrintf("--------------------\n");
@@ -414,8 +414,8 @@
 		DebugPrintf("No engine debug levels\n");
 		return true;
 	}
-	for (uint i = 0; i < debugLevels.size(); ++i) {
-		DebugPrintf("'%s' - Description: %s\n", debugLevels[i].option.c_str(), debugLevels[i].description.c_str());
+	for (Common::DebugLevelContainer::const_iterator i = debugLevels.begin(); i != debugLevels.end(); ++i) {
+		DebugPrintf("'%s' - Description: %s\n", i->option.c_str(), i->description.c_str());
 	}
 	DebugPrintf("\n");
 	return true;


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