diff options
author | Max Horn | 2010-04-27 21:40:52 +0000 |
---|---|---|
committer | Max Horn | 2010-04-27 21:40:52 +0000 |
commit | 460d69e8855f849e2200c49b198936b1201e0c91 (patch) | |
tree | 31bfcaf8c2603d01c9d971fb3b40390e0798ec02 /common | |
parent | 445dccd59bc77e760e649bae982d78f0c3ca6b04 (diff) | |
download | scummvm-rg350-460d69e8855f849e2200c49b198936b1201e0c91.tar.gz scummvm-rg350-460d69e8855f849e2200c49b198936b1201e0c91.tar.bz2 scummvm-rg350-460d69e8855f849e2200c49b198936b1201e0c91.zip |
COMMON: Move DebugChannel stuff into a new DebugMan singleton
svn-id: r48821
Diffstat (limited to 'common')
-rw-r--r-- | common/debug.cpp | 31 | ||||
-rw-r--r-- | common/debug.h | 20 |
2 files changed, 33 insertions, 18 deletions
diff --git a/common/debug.cpp b/common/debug.cpp index 86371f4091..30f4534f56 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -24,8 +24,6 @@ #include "common/debug.h" #include "common/util.h" -#include "common/hashmap.h" -#include "common/hash-str.h" #include <stdarg.h> // For va_list etc. @@ -48,24 +46,21 @@ // TODO: Move gDebugLevel into namespace Common. int gDebugLevel = -1; +DECLARE_SINGLETON(Common::DebugManager) + namespace Common { namespace { -typedef HashMap<String, DebugChannel, IgnoreCase_Hash, IgnoreCase_EqualTo> DebugChannelMap; - -static DebugChannelMap gDebugChannels; -static uint32 gDebugChannelsEnabled = 0; - struct DebugLevelComperator { - bool operator()(const DebugChannel &l, const DebugChannel &r) { + bool operator()(const DebugManager::DebugChannel &l, const DebugManager::DebugChannel &r) { return (l.name.compareToIgnoreCase(r.name) < 0); } }; } // end of anonymous namespace -bool addDebugChannel(uint32 channel, const String &name, const String &description) { +bool DebugManager::addDebugChannel(uint32 channel, const String &name, const String &description) { if (gDebugChannels.contains(name)) warning("Duplicate declaration of engine debug channel '%s'", name.c_str()); @@ -74,12 +69,12 @@ bool addDebugChannel(uint32 channel, const String &name, const String &descripti return true; } -void clearAllDebugChannels() { +void DebugManager::clearAllDebugChannels() { gDebugChannelsEnabled = 0; gDebugChannels.clear(); } -bool enableDebugChannel(const String &name) { +bool DebugManager::enableDebugChannel(const String &name) { DebugChannelMap::iterator i = gDebugChannels.find(name); if (i != gDebugChannels.end()) { @@ -92,7 +87,7 @@ bool enableDebugChannel(const String &name) { } } -bool disableDebugChannel(const String &name) { +bool DebugManager::disableDebugChannel(const String &name) { DebugChannelMap::iterator i = gDebugChannels.find(name); if (i != gDebugChannels.end()) { @@ -106,7 +101,7 @@ bool disableDebugChannel(const String &name) { } -DebugChannelList listDebugChannels() { +DebugManager::DebugChannelList DebugManager::listDebugChannels() { DebugChannelList tmp; for (DebugChannelMap::iterator i = gDebugChannels.begin(); i != gDebugChannels.end(); ++i) tmp.push_back(i->_value); @@ -115,7 +110,7 @@ DebugChannelList listDebugChannels() { return tmp; } -bool isDebugChannelEnabled(uint32 channel) { +bool DebugManager::isDebugChannelEnabled(uint32 channel) { // Debug level 11 turns on all special debug level messages if (gDebugLevel == 11) return true; @@ -206,7 +201,7 @@ void debugC(int level, uint32 debugChannels, const char *s, ...) { // Debug level 11 turns on all special debug level messages if (gDebugLevel != 11) - if (level > gDebugLevel || !(Common::gDebugChannelsEnabled & debugChannels)) + if (level > gDebugLevel || !(DebugMan.isDebugChannelEnabled(debugChannels))) return; va_start(va, s); @@ -219,7 +214,7 @@ void debugCN(int level, uint32 debugChannels, const char *s, ...) { // Debug level 11 turns on all special debug level messages if (gDebugLevel != 11) - if (level > gDebugLevel || !(Common::gDebugChannelsEnabled & debugChannels)) + if (level > gDebugLevel || !(DebugMan.isDebugChannelEnabled(debugChannels))) return; va_start(va, s); @@ -232,7 +227,7 @@ void debugC(uint32 debugChannels, const char *s, ...) { // Debug level 11 turns on all special debug level messages if (gDebugLevel != 11) - if (!(Common::gDebugChannelsEnabled & debugChannels)) + if (!(DebugMan.isDebugChannelEnabled(debugChannels))) return; va_start(va, s); @@ -245,7 +240,7 @@ void debugCN(uint32 debugChannels, const char *s, ...) { // Debug level 11 turns on all special debug level messages if (gDebugLevel != 11) - if (!(Common::gDebugChannelsEnabled & debugChannels)) + if (!(DebugMan.isDebugChannelEnabled(debugChannels))) return; va_start(va, s); diff --git a/common/debug.h b/common/debug.h index d1c89ebd9c..ffb674e40d 100644 --- a/common/debug.h +++ b/common/debug.h @@ -26,13 +26,20 @@ #define COMMON_DEBUG_H #include "common/scummsys.h" +#include "common/singleton.h" #include "common/textconsole.h" #include "common/list.h" #include "common/str.h" +#include "common/hashmap.h" +#include "common/hash-str.h" + namespace Common { +// TODO: Find a better name for this +class DebugManager : public Singleton<DebugManager> { +public: struct DebugChannel { DebugChannel() : channel(0), enabled(false) {} @@ -109,6 +116,19 @@ DebugChannelList listDebugChannels(); bool isDebugChannelEnabled(uint32 channel); +private: + typedef HashMap<String, DebugChannel, IgnoreCase_Hash, IgnoreCase_EqualTo> DebugChannelMap; + + DebugChannelMap gDebugChannels; + uint32 gDebugChannelsEnabled; + + friend class Singleton<SingletonBaseType>; + DebugManager() : gDebugChannelsEnabled(0) {} +}; + +/** Shortcut for accessing the debug manager. */ +#define DebugMan Common::DebugManager::instance() + /** * Set the output formatter used by debug() and related functions. */ |