From e18546560e875bce9d9290ce72ff0c2b6915b091 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 02:51:20 +0900 Subject: [PATCH 1/9] Enabled users to define custom debug message listeners --- taglib/CMakeLists.txt | 2 + taglib/toolkit/tdebug.cpp | 24 +-------- taglib/toolkit/tdebug.h | 29 ++--------- taglib/toolkit/tdebuglistener.cpp | 81 +++++++++++++++++++++++++++++++ taglib/toolkit/tdebuglistener.h | 71 +++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 47 deletions(-) create mode 100644 taglib/toolkit/tdebuglistener.cpp create mode 100644 taglib/toolkit/tdebuglistener.h diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 352f7e2e..23fa60df 100755 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -51,6 +51,7 @@ set(tag_HDRS toolkit/tmap.tcc toolkit/tpropertymap.h toolkit/trefcounter.h + toolkit/tdebuglistener.h mpeg/mpegfile.h mpeg/mpegproperties.h mpeg/mpegheader.h @@ -291,6 +292,7 @@ set(toolkit_SRCS toolkit/tdebug.cpp toolkit/tpropertymap.cpp toolkit/trefcounter.cpp + toolkit/tdebuglistener.cpp toolkit/unicode.cpp ) diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 522b68c9..129aee84 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -23,33 +23,13 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#ifndef NDEBUG -#include -#include - #include "tdebug.h" #include "tstring.h" +#include "tdebuglistener.h" using namespace TagLib; void TagLib::debug(const String &s) { - std::cerr << "TagLib: " << s << std::endl; + getDebugListener()->listen(s); } - -void TagLib::debugData(const ByteVector &v) -{ - for(uint i = 0; i < v.size(); i++) { - - std::cout << "*** [" << i << "] - '" << char(v[i]) << "' - int " << int(v[i]) - << std::endl; - - std::bitset<8> b(v[i]); - - for(int j = 0; j < 8; j++) - std::cout << i << ":" << j << " " << b.test(j) << std::endl; - - std::cout << std::endl; - } -} -#endif diff --git a/taglib/toolkit/tdebug.h b/taglib/toolkit/tdebug.h index 5204fe70..e0c6615f 100644 --- a/taglib/toolkit/tdebug.h +++ b/taglib/toolkit/tdebug.h @@ -29,14 +29,13 @@ namespace TagLib { class String; - class ByteVector; #ifndef DO_NOT_DOCUMENT -#ifndef NDEBUG /*! - * A simple function that prints debugging output to cerr if debugging is - * not disabled. + * A simple function that outputs the debug messages to the listener. + * The default listener redirects the messages to \a stderr when NDEBUG is + * not defined. * * \warning Do not use this outside of TagLib, it could lead to undefined * symbols in your build if TagLib is built with NDEBUG defined and your @@ -45,27 +44,7 @@ namespace TagLib { * \internal */ void debug(const String &s); - - /*! - * For debugging binary data. - * - * \warning Do not use this outside of TagLib, it could lead to undefined - * symbols in your build if TagLib is built with NDEBUG defined and your - * application is not. - * - * \internal - */ - void debugData(const ByteVector &v); - -#else - - // Define these to an empty statement if debugging is disabled. - -#define debug(x) -#define debugData(x) - -#endif -#endif } #endif +#endif diff --git a/taglib/toolkit/tdebuglistener.cpp b/taglib/toolkit/tdebuglistener.cpp new file mode 100644 index 00000000..499134aa --- /dev/null +++ b/taglib/toolkit/tdebuglistener.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + copyright : (C) 2013 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#include "tdebuglistener.h" + +#ifndef NDEBUG +# include +# ifdef _WIN32 +# include +# endif +#endif + +using namespace TagLib; + +namespace +{ + class DefaultListener : public DebugListener + { + public: + virtual void listen(const String &msg) + { +#ifndef NDEBUG +# ifdef _WIN32 + + std::string s; + const wstring wstr = msg.toWString(); + const int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL); + if(len != 0) { + s.resize(len); + WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &s[0], len, NULL, NULL); + } + + std::cerr << "TagLib: " << s << std::endl; + +# else + + std::cerr << "TagLib: " << msg << std::endl; + +# endif +#endif + } + }; + + DefaultListener defaultListener; + DebugListener *traceListener = &defaultListener; +} + +void TagLib::setDebugListener(DebugListener *listener) +{ + if(listener) + traceListener = listener; + else + traceListener = &defaultListener; +} + +DebugListener *TagLib::getDebugListener() +{ + return traceListener; +} diff --git a/taglib/toolkit/tdebuglistener.h b/taglib/toolkit/tdebuglistener.h new file mode 100644 index 00000000..5d66c91a --- /dev/null +++ b/taglib/toolkit/tdebuglistener.h @@ -0,0 +1,71 @@ +/*************************************************************************** + copyright : (C) 2013 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#ifndef TAGLIB_DEBUGLISTENER_H +#define TAGLIB_DEBUGLISTENER_H + +#include "taglib_export.h" +#include "tstring.h" + +namespace TagLib +{ + //! An abstraction for the listener to the debug messages. + + /*! + * This class enables you to handle the debug messages in your preferred + * way by subclassing this class, reimplementing listen() and setting your + * reimplementation as the default with setDebugListener(). + * + * \see setDebugListener() + */ + class TAGLIB_EXPORT DebugListener + { + public: + virtual void listen(const String &msg) = 0; + }; + + /*! + * Sets the listener that decides how the debug messages are redirected. + * If the parameter \a listener is null, the previous listener is released + * and default stderr listener is restored. + * + * \note The caller is responsible for deleting the previous listener + * as needed after it is released. + * + * \see DebugListener + */ + void setDebugListener(DebugListener *listener); + +#ifndef DO_NOT_DOCUMENT + + /*! + * \internal + */ + DebugListener *getDebugListener(); + +#endif +} + +#endif From 3b2d6206714dc0fecec45d8a51f66e38e7054b2f Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 09:59:36 +0900 Subject: [PATCH 2/9] Enabled users to define custom debug message listeners --- taglib/toolkit/tdebug.cpp | 7 +++++- taglib/toolkit/tdebug.h | 12 ++++++++++ taglib/toolkit/tdebuglistener.cpp | 39 +++++++++++++++++++++++++++---- taglib/toolkit/tdebuglistener.h | 15 +++++++++--- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 129aee84..95d5c55f 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -31,5 +31,10 @@ using namespace TagLib; void TagLib::debug(const String &s) { - getDebugListener()->listen(s); + getDebugListener()->printMessage(s); +} + +void TagLib::debugData(const ByteVector &v) +{ + getDebugListener()->printData(v); } diff --git a/taglib/toolkit/tdebug.h b/taglib/toolkit/tdebug.h index e0c6615f..bd94d159 100644 --- a/taglib/toolkit/tdebug.h +++ b/taglib/toolkit/tdebug.h @@ -29,6 +29,7 @@ namespace TagLib { class String; + class ByteVector; #ifndef DO_NOT_DOCUMENT @@ -44,6 +45,17 @@ namespace TagLib { * \internal */ void debug(const String &s); + + /*! + * For debugging binary data. + * + * \warning Do not use this outside of TagLib, it could lead to undefined + * symbols in your build if TagLib is built with NDEBUG defined and your + * application is not. + * + * \internal + */ + void debugData(const ByteVector &v); } #endif diff --git a/taglib/toolkit/tdebuglistener.cpp b/taglib/toolkit/tdebuglistener.cpp index 499134aa..bce94312 100644 --- a/taglib/toolkit/tdebuglistener.cpp +++ b/taglib/toolkit/tdebuglistener.cpp @@ -27,6 +27,7 @@ #ifndef NDEBUG # include +# include # ifdef _WIN32 # include # endif @@ -39,7 +40,7 @@ namespace class DefaultListener : public DebugListener { public: - virtual void listen(const String &msg) + virtual void printMessage(const String &msg) { #ifndef NDEBUG # ifdef _WIN32 @@ -59,23 +60,51 @@ namespace std::cerr << "TagLib: " << msg << std::endl; # endif +#endif + } + + virtual void printData(const ByteVector &v) + { +#ifndef NDEBUG + + for(size_t i = 0; i < v.size(); i++) + { + std::cout << "*** [" << i << "] - '" << char(v[i]) << "' - int " << int(v[i]) + << std::endl; + + std::bitset<8> b(v[i]); + + for(int j = 0; j < 8; j++) + std::cout << i << ":" << j << " " << b.test(j) << std::endl; + + std::cout << std::endl; + } + #endif } }; DefaultListener defaultListener; - DebugListener *traceListener = &defaultListener; + DebugListener *debugListener = &defaultListener; +} + +TagLib::DebugListener::DebugListener() +{ +} + +TagLib::DebugListener::~DebugListener() +{ } void TagLib::setDebugListener(DebugListener *listener) { if(listener) - traceListener = listener; + debugListener = listener; else - traceListener = &defaultListener; + debugListener = &defaultListener; } DebugListener *TagLib::getDebugListener() { - return traceListener; + return debugListener; } diff --git a/taglib/toolkit/tdebuglistener.h b/taglib/toolkit/tdebuglistener.h index 5d66c91a..3dd3a734 100644 --- a/taglib/toolkit/tdebuglistener.h +++ b/taglib/toolkit/tdebuglistener.h @@ -43,7 +43,16 @@ namespace TagLib class TAGLIB_EXPORT DebugListener { public: - virtual void listen(const String &msg) = 0; + DebugListener(); + virtual ~DebugListener(); + + virtual void printMessage(const String &msg) = 0; + virtual void printData(const ByteVector &data) = 0; + + private: + // Noncopyable + DebugListener(const DebugListener &); + DebugListener &operator=(const DebugListener &); }; /*! @@ -56,14 +65,14 @@ namespace TagLib * * \see DebugListener */ - void setDebugListener(DebugListener *listener); + TAGLIB_EXPORT void setDebugListener(DebugListener *listener); #ifndef DO_NOT_DOCUMENT /*! * \internal */ - DebugListener *getDebugListener(); + TAGLIB_EXPORT DebugListener *getDebugListener(); #endif } From 448648d61be288fb0c4193d2937f2c9bccf6763d Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 21:40:30 +0900 Subject: [PATCH 3/9] Simplified DebugListener class --- taglib/toolkit/tdebug.cpp | 52 +++++++++++++++++++++++++++++-- taglib/toolkit/tdebuglistener.cpp | 30 +++--------------- taglib/toolkit/tdebuglistener.h | 5 ++- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 95d5c55f..133aad39 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -23,18 +23,66 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ +#include "config.h" + #include "tdebug.h" #include "tstring.h" #include "tdebuglistener.h" +#include +#include +#include + using namespace TagLib; +namespace +{ + String format(const char *fmt, ...) + { + va_list args; + va_start(args, fmt); + + char buf[256]; + +#if defined(HAVE_SNPRINTF) + + vsnprintf(buf, sizeof(buf), fmt, args); + +#elif defined(HAVE_SPRINTF_S) + + vsprintf_s(buf, fmt, args); + +#else + + // Be careful. May cause a buffer overflow. + vsprintf(buf, fmt, args); + +#endif + + va_end(args); + + return String(buf); + } +} + void TagLib::debug(const String &s) { - getDebugListener()->printMessage(s); + getDebugListener()->printMessage("TagLib: " + s + "\n"); } void TagLib::debugData(const ByteVector &v) { - getDebugListener()->printData(v); + for(size_t i = 0; i < v.size(); ++i) + { + String msg + = format("*** [%d] - char '%c' - int %d, 0x%02x, 0b", i, v[i], v[i], v[i]); + + std::bitset<8> b(v[i]); + for(int j = 7; j >= 0; --j) + msg += format("%d", (b.test(j) ? 1 : 0)); + + msg += "\n"; + + getDebugListener()->printMessage(msg); + } } diff --git a/taglib/toolkit/tdebuglistener.cpp b/taglib/toolkit/tdebuglistener.cpp index bce94312..3b138e51 100644 --- a/taglib/toolkit/tdebuglistener.cpp +++ b/taglib/toolkit/tdebuglistener.cpp @@ -45,41 +45,21 @@ namespace #ifndef NDEBUG # ifdef _WIN32 - std::string s; const wstring wstr = msg.toWString(); const int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL); if(len != 0) { - s.resize(len); - WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &s[0], len, NULL, NULL); + std::vector buf(len); + WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &buf[0], len, NULL, NULL); + + std::cerr << std::string(&buf[0]); } - std::cerr << "TagLib: " << s << std::endl; # else - std::cerr << "TagLib: " << msg << std::endl; + std::cerr << msg; # endif -#endif - } - - virtual void printData(const ByteVector &v) - { -#ifndef NDEBUG - - for(size_t i = 0; i < v.size(); i++) - { - std::cout << "*** [" << i << "] - '" << char(v[i]) << "' - int " << int(v[i]) - << std::endl; - - std::bitset<8> b(v[i]); - - for(int j = 0; j < 8; j++) - std::cout << i << ":" << j << " " << b.test(j) << std::endl; - - std::cout << std::endl; - } - #endif } }; diff --git a/taglib/toolkit/tdebuglistener.h b/taglib/toolkit/tdebuglistener.h index 3dd3a734..cd1c52e5 100644 --- a/taglib/toolkit/tdebuglistener.h +++ b/taglib/toolkit/tdebuglistener.h @@ -35,8 +35,8 @@ namespace TagLib /*! * This class enables you to handle the debug messages in your preferred - * way by subclassing this class, reimplementing listen() and setting your - * reimplementation as the default with setDebugListener(). + * way by subclassing this class, reimplementing printMessage() and setting + * your reimplementation as the default with setDebugListener(). * * \see setDebugListener() */ @@ -47,7 +47,6 @@ namespace TagLib virtual ~DebugListener(); virtual void printMessage(const String &msg) = 0; - virtual void printData(const ByteVector &data) = 0; private: // Noncopyable From 12953b3fdc7a5fb18718e81f1ab33cb23f7bcd65 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 22:26:13 +0900 Subject: [PATCH 4/9] Removed TAGLIB_EXPORT from getDebugListener --- taglib/toolkit/tdebuglistener.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taglib/toolkit/tdebuglistener.h b/taglib/toolkit/tdebuglistener.h index cd1c52e5..d5c4d169 100644 --- a/taglib/toolkit/tdebuglistener.h +++ b/taglib/toolkit/tdebuglistener.h @@ -71,7 +71,7 @@ namespace TagLib /*! * \internal */ - TAGLIB_EXPORT DebugListener *getDebugListener(); + DebugListener *getDebugListener(); #endif } From 2f29ed003c182c7ecc72c6182fc5267558918ef7 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 9 Jun 2013 23:52:05 +0900 Subject: [PATCH 5/9] Added a CMake option that allows to show debug messages in release mode --- CMakeLists.txt | 5 +++++ taglib/taglib_config.h.cmake | 1 + taglib/toolkit/tdebug.cpp | 9 +++++++++ taglib/toolkit/tdebuglistener.cpp | 20 ++++++++------------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbcf8d89..80bc2dd3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,11 @@ if(WITH_MP4) set(TAGLIB_WITH_MP4 TRUE) endif() +option(TRACE_IN_RELEASE "Output debug messages even in release mode" OFF) +if(TRACE_IN_RELEASE) + set(TAGLIB_TRACE_IN_RELEASE TRUE) +endif() + configure_file(taglib/taglib_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib_config.h) add_subdirectory(taglib) diff --git a/taglib/taglib_config.h.cmake b/taglib/taglib_config.h.cmake index 1560c247..4ccb0158 100644 --- a/taglib/taglib_config.h.cmake +++ b/taglib/taglib_config.h.cmake @@ -3,3 +3,4 @@ #define TAGLIB_WITH_ASF 1 #define TAGLIB_WITH_MP4 1 +#cmakedefine TAGLIB_TRACE_IN_RELEASE 1 diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 133aad39..f4025e9b 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -24,6 +24,7 @@ ***************************************************************************/ #include "config.h" +#include "taglib_config.h" #include "tdebug.h" #include "tstring.h" @@ -67,11 +68,17 @@ namespace void TagLib::debug(const String &s) { +#if !defined(NDEBUG) || defined(TAGLIB_TRACE_IN_RELEASE) + getDebugListener()->printMessage("TagLib: " + s + "\n"); + +#endif } void TagLib::debugData(const ByteVector &v) { +#if !defined(NDEBUG) || defined(TAGLIB_TRACE_IN_RELEASE) + for(size_t i = 0; i < v.size(); ++i) { String msg @@ -85,4 +92,6 @@ void TagLib::debugData(const ByteVector &v) getDebugListener()->printMessage(msg); } + +#endif } diff --git a/taglib/toolkit/tdebuglistener.cpp b/taglib/toolkit/tdebuglistener.cpp index 3b138e51..b472dee9 100644 --- a/taglib/toolkit/tdebuglistener.cpp +++ b/taglib/toolkit/tdebuglistener.cpp @@ -25,12 +25,11 @@ #include "tdebuglistener.h" -#ifndef NDEBUG -# include -# include -# ifdef _WIN32 -# include -# endif +#include +#include + +#ifdef _WIN32 +# include #endif using namespace TagLib; @@ -42,8 +41,7 @@ namespace public: virtual void printMessage(const String &msg) { -#ifndef NDEBUG -# ifdef _WIN32 +#ifdef _WIN32 const wstring wstr = msg.toWString(); const int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL); @@ -54,13 +52,11 @@ namespace std::cerr << std::string(&buf[0]); } - -# else +#else std::cerr << msg; -# endif -#endif +#endif } }; From 6d2e0e80502ee438b2b33710ab5886930cea062e Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 10 Jun 2013 01:19:47 +0900 Subject: [PATCH 6/9] Moved a macro from taglib_config.h to config.h --- CMakeLists.txt | 2 +- config.h.cmake | 3 +++ taglib/taglib_config.h.cmake | 2 -- taglib/toolkit/tdebug.cpp | 5 ++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80bc2dd3..91e1901d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,7 @@ endif() option(TRACE_IN_RELEASE "Output debug messages even in release mode" OFF) if(TRACE_IN_RELEASE) - set(TAGLIB_TRACE_IN_RELEASE TRUE) + set(TRACE_IN_RELEASE TRUE) endif() configure_file(taglib/taglib_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib_config.h) diff --git a/config.h.cmake b/config.h.cmake index 15d2f997..f8dcbbde 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -31,4 +31,7 @@ /* Defined if you have libz */ #cmakedefine HAVE_ZLIB 1 +/* Indicates whether debug messages are shown even in release mode */ +#cmakedefine TRACE_IN_RELEASE 1 + #cmakedefine TESTS_DIR "@TESTS_DIR@" diff --git a/taglib/taglib_config.h.cmake b/taglib/taglib_config.h.cmake index 4ccb0158..0f499e2c 100644 --- a/taglib/taglib_config.h.cmake +++ b/taglib/taglib_config.h.cmake @@ -2,5 +2,3 @@ #define TAGLIB_WITH_ASF 1 #define TAGLIB_WITH_MP4 1 - -#cmakedefine TAGLIB_TRACE_IN_RELEASE 1 diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index f4025e9b..c838d57a 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -24,7 +24,6 @@ ***************************************************************************/ #include "config.h" -#include "taglib_config.h" #include "tdebug.h" #include "tstring.h" @@ -68,7 +67,7 @@ namespace void TagLib::debug(const String &s) { -#if !defined(NDEBUG) || defined(TAGLIB_TRACE_IN_RELEASE) +#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) getDebugListener()->printMessage("TagLib: " + s + "\n"); @@ -77,7 +76,7 @@ void TagLib::debug(const String &s) void TagLib::debugData(const ByteVector &v) { -#if !defined(NDEBUG) || defined(TAGLIB_TRACE_IN_RELEASE) +#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) for(size_t i = 0; i < v.size(); ++i) { From 886236b978ebc5288a4ed77e14737dafd4298889 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 10 Jun 2013 16:24:28 +0900 Subject: [PATCH 7/9] Removed getDebugListener() --- taglib/toolkit/tdebug.cpp | 46 +++++++++++++++++-------------- taglib/toolkit/tdebuglistener.cpp | 35 ++++++++++++----------- taglib/toolkit/tdebuglistener.h | 9 ------ 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index c838d57a..8c9c354f 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -65,32 +65,38 @@ namespace } } -void TagLib::debug(const String &s) +namespace TagLib { + // The instance is defined in tdebuglistener.cpp. + extern DebugListener *debugListener; + + void debug(const String &s) + { #if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) - getDebugListener()->printMessage("TagLib: " + s + "\n"); + debugListener->printMessage("TagLib: " + s + "\n"); #endif -} - -void TagLib::debugData(const ByteVector &v) -{ -#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) - - for(size_t i = 0; i < v.size(); ++i) - { - String msg - = format("*** [%d] - char '%c' - int %d, 0x%02x, 0b", i, v[i], v[i], v[i]); - - std::bitset<8> b(v[i]); - for(int j = 7; j >= 0; --j) - msg += format("%d", (b.test(j) ? 1 : 0)); - - msg += "\n"; - - getDebugListener()->printMessage(msg); } + void debugData(const ByteVector &v) + { +#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) + + for(size_t i = 0; i < v.size(); ++i) + { + String msg + = format("*** [%d] - char '%c' - int %d, 0x%02x, 0b", i, v[i], v[i], v[i]); + + std::bitset<8> b(v[i]); + for(int j = 7; j >= 0; --j) + msg += format("%d", (b.test(j) ? 1 : 0)); + + msg += "\n"; + + debugListener->printMessage(msg); + } + #endif + } } diff --git a/taglib/toolkit/tdebuglistener.cpp b/taglib/toolkit/tdebuglistener.cpp index b472dee9..48912222 100644 --- a/taglib/toolkit/tdebuglistener.cpp +++ b/taglib/toolkit/tdebuglistener.cpp @@ -61,26 +61,25 @@ namespace }; DefaultListener defaultListener; +} + +namespace TagLib +{ DebugListener *debugListener = &defaultListener; -} -TagLib::DebugListener::DebugListener() -{ -} + DebugListener::DebugListener() + { + } -TagLib::DebugListener::~DebugListener() -{ -} + DebugListener::~DebugListener() + { + } -void TagLib::setDebugListener(DebugListener *listener) -{ - if(listener) - debugListener = listener; - else - debugListener = &defaultListener; -} - -DebugListener *TagLib::getDebugListener() -{ - return debugListener; + void setDebugListener(DebugListener *listener) + { + if(listener) + debugListener = listener; + else + debugListener = &defaultListener; + } } diff --git a/taglib/toolkit/tdebuglistener.h b/taglib/toolkit/tdebuglistener.h index d5c4d169..c067a126 100644 --- a/taglib/toolkit/tdebuglistener.h +++ b/taglib/toolkit/tdebuglistener.h @@ -65,15 +65,6 @@ namespace TagLib * \see DebugListener */ TAGLIB_EXPORT void setDebugListener(DebugListener *listener); - -#ifndef DO_NOT_DOCUMENT - - /*! - * \internal - */ - DebugListener *getDebugListener(); - -#endif } #endif From 496b58e0c9604a346def53caef533ab8a54af1c6 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 11 Jun 2013 19:23:46 +0900 Subject: [PATCH 8/9] Updated the comment for DebugListener class --- taglib/toolkit/tdebuglistener.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/taglib/toolkit/tdebuglistener.h b/taglib/toolkit/tdebuglistener.h index c067a126..a32f285f 100644 --- a/taglib/toolkit/tdebuglistener.h +++ b/taglib/toolkit/tdebuglistener.h @@ -46,6 +46,10 @@ namespace TagLib DebugListener(); virtual ~DebugListener(); + /*! + * When overridden in a derived class, redirects \a msg to your preferred + * channel such as stderr, Windows debugger or so forth. + */ virtual void printMessage(const String &msg) = 0; private: From b84b3afc9c42eb47a9b9a6b285c53c6e9b30ac59 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 15 Jun 2013 13:21:07 +0900 Subject: [PATCH 9/9] Making use of std::bitset::to_string() --- taglib/toolkit/tdebug.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 8c9c354f..65c51efe 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -85,14 +85,9 @@ namespace TagLib for(size_t i = 0; i < v.size(); ++i) { - String msg - = format("*** [%d] - char '%c' - int %d, 0x%02x, 0b", i, v[i], v[i], v[i]); - - std::bitset<8> b(v[i]); - for(int j = 7; j >= 0; --j) - msg += format("%d", (b.test(j) ? 1 : 0)); - - msg += "\n"; + std::string bits = std::bitset<8>(v[i]).to_string(); + String msg = format("*** [%d] - char '%c' - int %d, 0x%02x, 0b%s\n", + i, v[i], v[i], v[i], bits.c_str()); debugListener->printMessage(msg); }