diff options
author | Max Horn | 2009-01-30 04:42:30 +0000 |
---|---|---|
committer | Max Horn | 2009-01-30 04:42:30 +0000 |
commit | de7c89e38143ccac34e5228d5591a2738f27a661 (patch) | |
tree | 5f383e7ab19e9aafa14477a8e28dc384491b6297 /common | |
parent | 9861da62f049fcd3436df38ff06d8e8839dbfdab (diff) | |
download | scummvm-rg350-de7c89e38143ccac34e5228d5591a2738f27a661.tar.gz scummvm-rg350-de7c89e38143ccac34e5228d5591a2738f27a661.tar.bz2 scummvm-rg350-de7c89e38143ccac34e5228d5591a2738f27a661.zip |
Some work on the 'special debug levels' aka 'engine debug levels' code
svn-id: r36139
Diffstat (limited to 'common')
-rw-r--r-- | common/debug.cpp | 58 | ||||
-rw-r--r-- | common/debug.h | 55 |
2 files changed, 75 insertions, 38 deletions
diff --git a/common/debug.cpp b/common/debug.cpp index 6c8d94a829..af3e6d8018 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -57,35 +57,35 @@ namespace Common { namespace { -DebugLevelContainer gDebugLevels; +SpecialDebugLevelList gDebugLevels; uint32 gDebugLevelsEnabled = 0; struct DebugLevelSort { - bool operator()(const EngineDebugLevel &l, const EngineDebugLevel &r) { - return (l.option.compareToIgnoreCase(r.option) < 0); + bool operator()(const SpecialDebugLevel &l, const SpecialDebugLevel &r) { + return (l.name.compareToIgnoreCase(r.name) < 0); } }; struct DebugLevelSearch { - const String &_option; + const String &_name; - DebugLevelSearch(const String &option) : _option(option) {} + DebugLevelSearch(const String &name) : _name(name) {} - bool operator()(const EngineDebugLevel &l) { - return _option.equalsIgnoreCase(l.option); + bool operator()(const SpecialDebugLevel &l) { + return _name.equalsIgnoreCase(l.name); } }; } -bool addSpecialDebugLevel(uint32 level, const String &option, const String &description) { - DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); +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", option.c_str()); - *i = EngineDebugLevel(level, option, description); + warning("Declared engine debug level '%s' again", name.c_str()); + *i = SpecialDebugLevel(level, name, description); } else { - gDebugLevels.push_back(EngineDebugLevel(level, option, description)); + gDebugLevels.push_back(SpecialDebugLevel(level, name, description)); sort(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSort()); } @@ -97,8 +97,8 @@ void clearAllSpecialDebugLevels() { gDebugLevels.clear(); } -bool enableSpecialDebugLevel(const String &option) { - DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); +bool enableSpecialDebugLevel(const String &name) { + SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name)); if (i != gDebugLevels.end()) { gDebugLevelsEnabled |= i->level; @@ -110,8 +110,8 @@ bool enableSpecialDebugLevel(const String &option) { } } -void enableSpecialDebugLevelList(const String &option) { - StringTokenizer tokenizer(option, " ,"); +void enableSpecialDebugLevelList(const String &names) { + StringTokenizer tokenizer(names, " ,"); String token; while (!tokenizer.empty()) { @@ -122,7 +122,7 @@ void enableSpecialDebugLevelList(const String &option) { } bool disableSpecialDebugLevel(const String &option) { - DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); + SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); if (i != gDebugLevels.end()) { gDebugLevelsEnabled &= ~i->level; @@ -134,7 +134,7 @@ bool disableSpecialDebugLevel(const String &option) { } } -const DebugLevelContainer &listSpecialDebugLevels() { +const SpecialDebugLevelList &listSpecialDebugLevels() { return gDebugLevels; } @@ -142,6 +142,27 @@ uint32 getEnabledSpecialDebugLevels() { return gDebugLevelsEnabled; } +bool isSpecialDebugLevelEnabled(uint32 level) { + // FIXME: Seems gDebugLevel 11 has a special meaning? Document that! + if (gDebugLevel == 11) + return true; +// return gDebugLevelsEnabled & (1 << level); + return gDebugLevelsEnabled & level; +} + +bool isSpecialDebugLevelEnabled(const String &name) { + // FIXME: Seems gDebugLevel 11 has a special meaning? Document that! + if (gDebugLevel == 11) + 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)); + if (i != gDebugLevels.end()) + return gDebugLevelsEnabled & i->level; + return false; +} + + } // End of namespace Common @@ -217,6 +238,7 @@ void debugN(int level, const char *s, ...) { void debugC(int level, uint32 engine_level, const char *s, ...) { va_list va; + // FIXME: Seems gDebugLevel 11 has a special meaning? Document that! if (gDebugLevel != 11) if (level > gDebugLevel || !(Common::gDebugLevelsEnabled & engine_level)) return; diff --git a/common/debug.h b/common/debug.h index d446a53d0e..8d01cde539 100644 --- a/common/debug.h +++ b/common/debug.h @@ -33,12 +33,12 @@ namespace Common { -struct EngineDebugLevel { - EngineDebugLevel() : option(""), description(""), level(0), enabled(false) {} - EngineDebugLevel(uint32 l, const String &o, const String &d) - : option(o), description(d), level(l), enabled(false) {} +struct SpecialDebugLevel { + SpecialDebugLevel() : level(0), enabled(false) {} + SpecialDebugLevel(uint32 l, const String &n, const String &d) + : name(n), description(d), level(l), enabled(false) {} - String option; + String name; String description; uint32 level; @@ -48,42 +48,46 @@ struct EngineDebugLevel { /** * Adds a engine debug level. * @param level the level flag (should be OR-able i.e. first one should be 1 than 2,4,...) - * @param option the option name which is used in the debugger/on the command line to enable + * @param name the option name which is used in the debugger/on the command line to enable * this special debug level, the option will be compared case !insentiv! later * @param description the description which shows up in the debugger * @return true on success false on failure */ -bool addSpecialDebugLevel(uint32 level, const String &option, const String &description); +bool addSpecialDebugLevel(uint32 level, const String &name, const String &description); /** - * Resets all engine debug levels + * Resets all engine debug levels. */ void clearAllSpecialDebugLevels(); /** - * Enables a engine debug level - * @param option the option which should be enabled - * @return true on success false on failure + * Enables an engine debug level. + * @param name the name of the debug level to enable + * @return true on success, false on failure */ -bool enableSpecialDebugLevel(const String &option); +bool enableSpecialDebugLevel(const String &name); -// only used for parsing the levels from the commandline -void enableSpecialDebugLevelList(const String &option); +/** + * Enables a list of engine debug levels, given as a comma-separated list + * of level names. + * @param name the list of names of debug levels to enable + */ +void enableSpecialDebugLevelList(const String &names); /** - * Disables a engine debug level - * @param option the option to disable - * @return true on success false on failure + * Disables an engine debug level + * @param name the name of the debug level to disable + * @return true on success, false on failure */ -bool disableSpecialDebugLevel(const String &option); +bool disableSpecialDebugLevel(const String &name); -typedef List<EngineDebugLevel> DebugLevelContainer; +typedef List<SpecialDebugLevel> SpecialDebugLevelList; /** * Lists all debug levels * @return returns a arry with all debug levels */ -const DebugLevelContainer &listSpecialDebugLevels(); +const SpecialDebugLevelList &listSpecialDebugLevels(); /** * Return the active debug flag mask (i.e. all active debug flags ORed @@ -92,6 +96,17 @@ const DebugLevelContainer &listSpecialDebugLevels(); uint32 getEnabledSpecialDebugLevels(); +/** + * Test whether the given debug level is enabled. + */ +bool isSpecialDebugLevelEnabled(uint32 level); + +/** + * Test whether the given debug level is enabled. + */ +bool isSpecialDebugLevelEnabled(const String &name); + + } // End of namespace Common |