void TagLib::debug(const String &s)
{
- getDebugListener()->listen(s);
+ getDebugListener()->printMessage(s);
+}
+
+void TagLib::debugData(const ByteVector &v)
+{
+ getDebugListener()->printData(v);
}
namespace TagLib {
class String;
+ class ByteVector;
#ifndef DO_NOT_DOCUMENT
* \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
#ifndef NDEBUG
# include <iostream>
+# include <bitset>
# ifdef _WIN32
# include <windows.h>
# endif
class DefaultListener : public DebugListener
{
public:
- virtual void listen(const String &msg)
+ virtual void printMessage(const String &msg)
{
#ifndef NDEBUG
# ifdef _WIN32
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;
}
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 &);
};
/*!
*
* \see DebugListener
*/
- void setDebugListener(DebugListener *listener);
+ TAGLIB_EXPORT void setDebugListener(DebugListener *listener);
#ifndef DO_NOT_DOCUMENT
/*!
* \internal
*/
- DebugListener *getDebugListener();
+ TAGLIB_EXPORT DebugListener *getDebugListener();
#endif
}