From d7523d78430a6962a373332f5fb29c04244c6f57 Mon Sep 17 00:00:00 2001 From: Joel Verhagen Date: Thu, 23 May 2013 13:42:51 -0400 Subject: [PATCH 01/23] Added TAGLIB_EXPORT to RefCounter for Windows build --- taglib/toolkit/trefcounter.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/taglib/toolkit/trefcounter.h b/taglib/toolkit/trefcounter.h index 2d4ea7c8..53c6f1c0 100644 --- a/taglib/toolkit/trefcounter.h +++ b/taglib/toolkit/trefcounter.h @@ -26,6 +26,7 @@ #ifndef TAGLIB_REFCOUNTER_H #define TAGLIB_REFCOUNTER_H +#include "taglib_export.h" #include "taglib.h" #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class. @@ -37,7 +38,7 @@ */ namespace TagLib { - class RefCounter + class TAGLIB_EXPORT RefCounter { public: RefCounter(); From b3f3eeeec7f875e68a386c4839b577ff91d02bec Mon Sep 17 00:00:00 2001 From: Festus Hagen Date: Sat, 25 May 2013 01:51:26 -0400 Subject: [PATCH 02/23] Added FindShlwapi.cmake in lieu of pragma comment() in fileref.h. --- ConfigureChecks.cmake | 10 ++++++++++ cmake/modules/FindShlwapi.cmake | 14 ++++++++++++++ taglib/CMakeLists.txt | 8 ++++++++ taglib/fileref.h | 4 ---- 4 files changed, 32 insertions(+), 4 deletions(-) mode change 100644 => 100755 ConfigureChecks.cmake create mode 100755 cmake/modules/FindShlwapi.cmake mode change 100644 => 100755 taglib/CMakeLists.txt mode change 100644 => 100755 taglib/fileref.h diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake old mode 100644 new mode 100755 index 46611a00..eda7a2b6 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -218,6 +218,16 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) + +if(WIN32) + find_package(SHLWAPI) + if(SHLWAPI_FOUND) + set(HAVE_SHLWAPI 1) + else() + set(HAVE_SHLWAPI 0) + endif() +endif() + find_package(CppUnit) if(NOT CppUnit_FOUND AND BUILD_TESTS) message(STATUS "CppUnit not found, disabling tests.") diff --git a/cmake/modules/FindShlwapi.cmake b/cmake/modules/FindShlwapi.cmake new file mode 100755 index 00000000..cba253f0 --- /dev/null +++ b/cmake/modules/FindShlwapi.cmake @@ -0,0 +1,14 @@ +# * +# * It is what it is, you can do with it as you please. +# * +# * Just don't blame me if it teaches your computer to smoke! +# * +# * -Enjoy +# * fh :)_~ +# * +FIND_PATH(SHLWAPI_INCLUDE_DIR shlwapi.h) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SHLWAPI REQUIRED_VARS SHLWAPI_LIBRARY SHLWAPI_INCLUDE_DIR) +IF(SHLWAPI_FOUND) + SET(SHLWAPI_LIBRARIES ${SHLWAPI_LIBRARY} ) +ENDIF(SHLWAPI_FOUND) + diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt old mode 100644 new mode 100755 index 352f7e2e..03eb15b5 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -30,6 +30,10 @@ if(ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIR}) endif() +if(SHLWAPI_FOUND) + include_directories(${SHLWAPI_INCLUDE_DIR}) +endif() + set(tag_HDRS tag.h fileref.h @@ -311,6 +315,10 @@ if(ZLIB_FOUND) target_link_libraries(tag ${ZLIB_LIBRARIES}) endif() +if(SHLWAPI_FOUND) + target_link_libraries(tag ${SHLWAPI_LIBRARIES}) +endif() + set_target_properties(tag PROPERTIES VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH} SOVERSION ${TAGLIB_SOVERSION_MAJOR} diff --git a/taglib/fileref.h b/taglib/fileref.h old mode 100644 new mode 100755 index 95a7506d..0f0c21a4 --- a/taglib/fileref.h +++ b/taglib/fileref.h @@ -32,10 +32,6 @@ #include "taglib_export.h" #include "audioproperties.h" -#if _WIN32 -# pragma comment(lib, "shlwapi.lib") -#endif - namespace TagLib { class Tag; From 42d268c2c999ed43fd89f3a8bfeca614e184d951 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 26 May 2013 04:17:18 +0900 Subject: [PATCH 03/23] Fixed shlwapi.h and shlwapi.lib detection for MSVC --- ConfigureChecks.cmake | 2 +- taglib/CMakeLists.txt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index eda7a2b6..192c1441 100755 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -219,7 +219,7 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) -if(WIN32) +if(WIN32 AND NOT MSVC) find_package(SHLWAPI) if(SHLWAPI_FOUND) set(HAVE_SHLWAPI 1) diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 03eb15b5..1753fa33 100755 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -30,7 +30,7 @@ if(ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIR}) endif() -if(SHLWAPI_FOUND) +if(NOT MSVC AND SHLWAPI_FOUND) include_directories(${SHLWAPI_INCLUDE_DIR}) endif() @@ -315,8 +315,12 @@ if(ZLIB_FOUND) target_link_libraries(tag ${ZLIB_LIBRARIES}) endif() -if(SHLWAPI_FOUND) - target_link_libraries(tag ${SHLWAPI_LIBRARIES}) +if(MSVC) + target_link_libraries(tag shlwapi.lib) +else() + if(SHLWAPI_FOUND) + target_link_libraries(tag ${SHLWAPI_LIBRARIES}) + endif() endif() set_target_properties(tag PROPERTIES From 93f304a91d83ca3f58dfcdc47aecd183ee128813 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 26 May 2013 14:38:36 +0900 Subject: [PATCH 04/23] Fixed some MSVC specific warnings --- taglib/toolkit/tiostream.cpp | 37 +++++++++++++++++++++++++----------- taglib/toolkit/tiostream.h | 8 ++++++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/taglib/toolkit/tiostream.cpp b/taglib/toolkit/tiostream.cpp index 2832e414..ee4e4a61 100644 --- a/taglib/toolkit/tiostream.cpp +++ b/taglib/toolkit/tiostream.cpp @@ -69,44 +69,59 @@ namespace } } -// If WinNT, stores a Unicode string into m_wname directly. -// If Win9x, converts and stores it into m_name to avoid calling Unicode version functions. +class FileName::FileNamePrivate +{ +public: + std::wstring wname; + std::string name; +}; FileName::FileName(const wchar_t *name) - : m_wname(SystemSupportsUnicode ? name : L"") - , m_name (SystemSupportsUnicode ? "" : unicodeToAnsi(name)) + : d(new FileNamePrivate()) { + // If Windows NT, stores a Unicode string directly. + // If Windows 9x, stores it converting into an ANSI string. + if(SystemSupportsUnicode) + d->wname = name; + else + d->name = unicodeToAnsi(name); } FileName::FileName(const char *name) - : m_name(name) + : d(new FileNamePrivate()) { + d->name = name; } FileName::FileName(const FileName &name) - : m_wname(name.m_wname) - , m_name (name.m_name) + : d(new FileNamePrivate(*name.d)) { } +FileName &FileName::operator==(const FileName &name) +{ + *d = *name.d; + return *this; +} + FileName::operator const wchar_t *() const { - return m_wname.c_str(); + return d->wname.c_str(); } FileName::operator const char *() const { - return m_name.c_str(); + return d->name.c_str(); } const std::wstring &FileName::wstr() const { - return m_wname; + return d->wname; } const std::string &FileName::str() const { - return m_name; + return d->name; } #endif // _WIN32 diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index 2cb80977..498b3a45 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -40,6 +40,7 @@ namespace TagLib { FileName(const char *name); FileName(const FileName &name); + FileName &operator==(const FileName &name); operator const wchar_t *() const; operator const char *() const; @@ -48,11 +49,14 @@ namespace TagLib { const std::string &str() const; private: - const std::string m_name; - const std::wstring m_wname; + class FileNamePrivate; + FileNamePrivate *d; }; + #else + typedef const char *FileName; + #endif //! An abstract class that provides operations on a sequence of bytes From e73afa33250abeb6543f40023062dd7188a3e359 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 28 May 2013 00:02:09 +0900 Subject: [PATCH 05/23] Fixed memory leak of ByteVector --- taglib/toolkit/tbytevector.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 84d3f004..11cc67d5 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -508,7 +508,6 @@ ByteVector::ByteVector(const ByteVector &v) ByteVector::ByteVector(const ByteVector &v, uint offset, uint length) : d(new ByteVectorPrivate(v.d, offset, length)) { - d->ref(); } ByteVector::ByteVector(char c) From f77a84486e316c3f841f568adccf97e2fabc3050 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 30 May 2013 02:04:10 +0900 Subject: [PATCH 06/23] Fixed comments for File constructors --- taglib/ape/apefile.h | 16 ++++++++------- taglib/asf/asffile.h | 17 ++++++---------- taglib/flac/flacfile.h | 25 ++++++++++++----------- taglib/it/itfile.h | 16 ++++++++------- taglib/mod/modfile.h | 14 +++++++------ taglib/mp4/mp4file.h | 24 +++++++++++----------- taglib/mpc/mpcfile.h | 14 +++++++------ taglib/mpeg/mpegfile.h | 30 ++++++++++++++++------------ taglib/ogg/flac/oggflacfile.h | 14 +++++++------ taglib/ogg/opus/opusfile.h | 14 +++++++------ taglib/ogg/speex/speexfile.h | 14 +++++++------ taglib/ogg/vorbis/vorbisfile.h | 14 +++++++------ taglib/riff/aiff/aifffile.h | 14 +++++++------ taglib/riff/wav/wavfile.h | 14 +++++++------ taglib/s3m/s3mfile.h | 14 +++++++------ taglib/trueaudio/trueaudiofile.h | 34 ++++++++++++++++++++------------ taglib/wavpack/wavpackfile.h | 7 ++++--- taglib/xm/xmfile.h | 14 +++++++------ 18 files changed, 171 insertions(+), 138 deletions(-) diff --git a/taglib/ape/apefile.h b/taglib/ape/apefile.h index 95c60742..5ccef72f 100644 --- a/taglib/ape/apefile.h +++ b/taglib/ape/apefile.h @@ -59,7 +59,7 @@ namespace TagLib { //! An implementation of TagLib::File with APE specific methods /*! - * This implements and provides an interface APE WavPack files to the + * This implements and provides an interface for APE files to the * TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing * the abstract TagLib::File API as well as providing some additional * information specific to APE files. @@ -84,20 +84,22 @@ namespace TagLib { }; /*! - * Contructs an WavPack file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an APE file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an WavPack file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an APE file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/asf/asffile.h b/taglib/asf/asffile.h index 7d0e3bc7..4e850d6d 100644 --- a/taglib/asf/asffile.h +++ b/taglib/asf/asffile.h @@ -48,22 +48,16 @@ namespace TagLib { public: /*! - * Contructs an ASF file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an ASF file from \a file. * * \note In the current implementation, both \a readProperties and * \a propertiesStyle are ignored. - * - * \note TagLib will *not* take ownership of the stream, the caller is - * responsible for deleting it after the File object. */ - File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); + File(FileName file, bool readProperties = true, + Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an ASF file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an ASF file from \a stream. * * \note In the current implementation, both \a readProperties and * \a propertiesStyle are ignored. @@ -71,7 +65,8 @@ namespace TagLib { * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. */ - File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); + File(IOStream *stream, bool readProperties = true, + Properties::ReadStyle propertiesStyle = Properties::Average); /*! * Destroys this instance of the File. diff --git a/taglib/flac/flacfile.h b/taglib/flac/flacfile.h index 7423d8f1..95b52142 100644 --- a/taglib/flac/flacfile.h +++ b/taglib/flac/flacfile.h @@ -67,9 +67,10 @@ namespace TagLib { { public: /*! - * Contructs a FLAC file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a FLAC file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. * * \deprecated This constructor will be dropped in favor of the one below * in a future version. @@ -78,12 +79,13 @@ namespace TagLib { Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs a FLAC file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an APE file from \a file. If \a readProperties is true the + * file's audio properties will also be read. * * If this file contains and ID3v2 tag the frames will be created using * \a frameFactory. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ // BIC: merge with the above constructor File(FileName file, ID3v2::FrameFactory *frameFactory, @@ -91,15 +93,16 @@ namespace TagLib { Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs a FLAC file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a FLAC file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note TagLib will *not* take ownership of the stream, the caller is + * responsible for deleting it after the File object. * * If this file contains and ID3v2 tag the frames will be created using * \a frameFactory. * - * \note TagLib will *not* take ownership of the stream, the caller is - * responsible for deleting it after the File object. + * \note In the current implementation, \a propertiesStyle is ignored. */ // BIC: merge with the above constructor File(IOStream *stream, ID3v2::FrameFactory *frameFactory, diff --git a/taglib/it/itfile.h b/taglib/it/itfile.h index 5584b7cd..abbdfd3b 100644 --- a/taglib/it/itfile.h +++ b/taglib/it/itfile.h @@ -36,23 +36,25 @@ namespace TagLib { class TAGLIB_EXPORT File : public Mod::FileBase { public: /*! - * Contructs a Impulse Tracker file from \a file. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs a Impulse Tracker file from \a file. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. */ File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average); /*! - * Contructs a Impulse Tracker file from \a stream. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs a Impulse Tracker file from \a stream. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. */ - File(IOStream *stram, bool readProperties = true, + File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average); diff --git a/taglib/mod/modfile.h b/taglib/mod/modfile.h index ad1e43b8..6113f9fe 100644 --- a/taglib/mod/modfile.h +++ b/taglib/mod/modfile.h @@ -37,18 +37,20 @@ namespace TagLib { { public: /*! - * Contructs a Protracker file from \a file. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs a Protracker file from \a file. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. */ File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average); /*! - * Contructs a Protracker file from \a stream. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs a Protracker file from \a stream. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. diff --git a/taglib/mp4/mp4file.h b/taglib/mp4/mp4file.h index 17fd5a95..39693d36 100644 --- a/taglib/mp4/mp4file.h +++ b/taglib/mp4/mp4file.h @@ -49,27 +49,25 @@ namespace TagLib { { public: /*! - * Contructs a MP4 file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an MP4 file from \a file. If \a readProperties is true the + * file's audio properties will also be read. * - * \note In the current implementation, both \a readProperties and - * \a propertiesStyle are ignored. + * \note In the current implementation, \a propertiesStyle is ignored. */ - File(FileName file, bool readProperties = true, Properties::ReadStyle audioPropertiesStyle = Properties::Average); + File(FileName file, bool readProperties = true, + Properties::ReadStyle audioPropertiesStyle = Properties::Average); /*! - * Contructs a MP4 file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. - * - * \note In the current implementation, both \a readProperties and - * \a propertiesStyle are ignored. + * Constructs an MP4 file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ - File(IOStream *stream, bool readProperties = true, Properties::ReadStyle audioPropertiesStyle = Properties::Average); + File(IOStream *stream, bool readProperties = true, + Properties::ReadStyle audioPropertiesStyle = Properties::Average); /*! * Destroys this instance of the File. diff --git a/taglib/mpc/mpcfile.h b/taglib/mpc/mpcfile.h index 59617074..ea66a5f9 100644 --- a/taglib/mpc/mpcfile.h +++ b/taglib/mpc/mpcfile.h @@ -84,20 +84,22 @@ namespace TagLib { }; /*! - * Contructs an MPC file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an MPC file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an MPC file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an MPC file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/mpeg/mpegfile.h b/taglib/mpeg/mpegfile.h index 0c817887..ef3a2b8f 100644 --- a/taglib/mpeg/mpegfile.h +++ b/taglib/mpeg/mpegfile.h @@ -71,9 +71,10 @@ namespace TagLib { }; /*! - * Contructs an MPEG file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an MPEG file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. * * \deprecated This constructor will be dropped in favor of the one below * in a future version. @@ -82,28 +83,31 @@ namespace TagLib { Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an MPEG file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. The frames will be created using + * Constructs an MPEG file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * If this file contains and ID3v2 tag the frames will be created using * \a frameFactory. * - * \deprecated This constructor will be dropped in favor of the one below - * in a future version. + * \note In the current implementation, \a propertiesStyle is ignored. */ + // BIC: merge with the above constructor File(FileName file, ID3v2::FrameFactory *frameFactory, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an MPEG file from \a stream. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. The frames will be created using - * \a frameFactory. + * Constructs an MPEG file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * If this file contains and ID3v2 tag the frames will be created using + * \a frameFactory. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ - // BIC: merge with the above constructor File(IOStream *stream, ID3v2::FrameFactory *frameFactory, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/ogg/flac/oggflacfile.h b/taglib/ogg/flac/oggflacfile.h index 770884a7..4b83df1f 100644 --- a/taglib/ogg/flac/oggflacfile.h +++ b/taglib/ogg/flac/oggflacfile.h @@ -64,20 +64,22 @@ namespace TagLib { { public: /*! - * Contructs an Ogg/FLAC file from \a file. If \a readProperties is true - * the file's audio properties will also be read using \a propertiesStyle. - * If false, \a propertiesStyle is ignored. + * Constructs an Ogg/FLAC file from \a file. If \a readProperties is true + * the file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an Ogg/FLAC file from \a file. If \a readProperties is true - * the file's audio properties will also be read using \a propertiesStyle. - * If false, \a propertiesStyle is ignored. + * Constructs an Ogg/FLAC file from \a stream. If \a readProperties is true + * the file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/ogg/opus/opusfile.h b/taglib/ogg/opus/opusfile.h index 736235c6..275167e4 100644 --- a/taglib/ogg/opus/opusfile.h +++ b/taglib/ogg/opus/opusfile.h @@ -56,20 +56,22 @@ namespace TagLib { { public: /*! - * Contructs a Opus file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an Opus file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs a Opus file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an Opus file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/ogg/speex/speexfile.h b/taglib/ogg/speex/speexfile.h index 2bbf8f40..880e6890 100644 --- a/taglib/ogg/speex/speexfile.h +++ b/taglib/ogg/speex/speexfile.h @@ -56,20 +56,22 @@ namespace TagLib { { public: /*! - * Contructs a Speex file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a Speex file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs a Speex file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a Speex file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/ogg/vorbis/vorbisfile.h b/taglib/ogg/vorbis/vorbisfile.h index 6e4d4fc4..7735a11b 100644 --- a/taglib/ogg/vorbis/vorbisfile.h +++ b/taglib/ogg/vorbis/vorbisfile.h @@ -63,20 +63,22 @@ namespace TagLib { { public: /*! - * Contructs a Vorbis file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a Vorbis file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs a Vorbis file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a Vorbis file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/riff/aiff/aifffile.h b/taglib/riff/aiff/aifffile.h index f2ce0ba2..4ddd43e8 100644 --- a/taglib/riff/aiff/aifffile.h +++ b/taglib/riff/aiff/aifffile.h @@ -58,20 +58,22 @@ namespace TagLib { { public: /*! - * Contructs an AIFF file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an AIFF file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an AIFF file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs an AIFF file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/riff/wav/wavfile.h b/taglib/riff/wav/wavfile.h index 980f6e4d..e8dfb8f8 100644 --- a/taglib/riff/wav/wavfile.h +++ b/taglib/riff/wav/wavfile.h @@ -70,20 +70,22 @@ namespace TagLib { }; /*! - * Contructs an WAV file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a WAV file from \a file. If \a readProperties is true the + * file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an WAV file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a WAV file from \a stream. If \a readProperties is true the + * file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); diff --git a/taglib/s3m/s3mfile.h b/taglib/s3m/s3mfile.h index c862108e..02732881 100644 --- a/taglib/s3m/s3mfile.h +++ b/taglib/s3m/s3mfile.h @@ -36,18 +36,20 @@ namespace TagLib { class TAGLIB_EXPORT File : public Mod::FileBase { public: /*! - * Contructs a ScreamTracker III file from \a file. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs a ScreamTracker III from \a file. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. */ File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average); /*! - * Contructs a ScreamTracker III file from \a stream. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs a ScreamTracker III file from \a stream. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. diff --git a/taglib/trueaudio/trueaudiofile.h b/taglib/trueaudio/trueaudiofile.h index be31089e..d805c8c5 100644 --- a/taglib/trueaudio/trueaudiofile.h +++ b/taglib/trueaudio/trueaudiofile.h @@ -79,42 +79,50 @@ namespace TagLib { }; /*! - * Contructs an TrueAudio file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a TrueAudio file from \a file. If \a readProperties is true + * the file's audio properties will also be read. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an TrueAudio file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. The frames will be created using + * Constructs a TrueAudio file from \a file. If \a readProperties is true + * the file's audio properties will also be read. + * + * If this file contains and ID3v2 tag the frames will be created using * \a frameFactory. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(FileName file, ID3v2::FrameFactory *frameFactory, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an TrueAudio file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * Constructs a TrueAudio file from \a stream. If \a readProperties is true + * the file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an TrueAudio file from \a file. If \a readProperties is true the - * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. The frames will be created using - * \a frameFactory. + * Constructs a TrueAudio file from \a stream. If \a readProperties is true + * the file's audio properties will also be read. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. + * + * If this file contains and ID3v2 tag the frames will be created using + * \a frameFactory. + * + * \note In the current implementation, \a propertiesStyle is ignored. */ File(IOStream *stream, ID3v2::FrameFactory *frameFactory, bool readProperties = true, diff --git a/taglib/wavpack/wavpackfile.h b/taglib/wavpack/wavpackfile.h index 7d4fafee..c507977e 100644 --- a/taglib/wavpack/wavpackfile.h +++ b/taglib/wavpack/wavpackfile.h @@ -80,15 +80,16 @@ namespace TagLib { }; /*! - * Contructs an WavPack file from \a file. If \a readProperties is true the + * Constructs a WavPack file from \a file. If \a readProperties is true the * file's audio properties will also be read using \a propertiesStyle. If - * false, \a propertiesStyle is ignored. + * false, \a propertiesStyle is ignored */ + File(FileName file, bool readProperties = true, Properties::ReadStyle propertiesStyle = Properties::Average); /*! - * Contructs an WavPack file from \a file. If \a readProperties is true the + * Constructs an WavPack file from \a file. If \a readProperties is true the * file's audio properties will also be read using \a propertiesStyle. If * false, \a propertiesStyle is ignored. * diff --git a/taglib/xm/xmfile.h b/taglib/xm/xmfile.h index 9d1bb71c..95871d3a 100644 --- a/taglib/xm/xmfile.h +++ b/taglib/xm/xmfile.h @@ -36,18 +36,20 @@ namespace TagLib { class TAGLIB_EXPORT File : public Mod::FileBase { public: /*! - * Contructs a Extended Module file from \a file. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs an Extended Module file from \a file. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. */ File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average); /*! - * Contructs a Extended Module file from \a stream. If \a readProperties - * is true the file's audio properties will also be read using - * \a propertiesStyle. If false, \a propertiesStyle is ignored. + * Constructs an Extended Module file from \a stream. + * + * \note In the current implementation, both \a readProperties and + * \a propertiesStyle are ignored. * * \note TagLib will *not* take ownership of the stream, the caller is * responsible for deleting it after the File object. From 6365f36c75cb6c96792a3a15099b62b20cc5baff Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 1 Jun 2013 23:55:52 +0900 Subject: [PATCH 07/23] Fixed compilation error with GCC4.2 --- taglib/toolkit/tbytevector.cpp | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 11cc67d5..ce47fbb8 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -296,6 +296,25 @@ ulonglong byteSwap(ulonglong x) #endif } +template +T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignificantByteFirst) +{ + if(offset >= v.size()) { + debug("toNumber() -- No data to convert. Returning 0."); + return 0; + } + + length = std::min(length, v.size() - offset); + + T sum = 0; + for(size_t i = 0; i < length; i++) { + const size_t shift = (mostSignificantByteFirst ? length - 1 - i : i) * 8; + sum |= static_cast(static_cast(v[offset + i])) << shift; + } + + return sum; +} + template T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst) { @@ -317,25 +336,6 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst) return tmp; } -template -T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignificantByteFirst) -{ - if(offset >= v.size()) { - debug("toNumber() -- No data to convert. Returning 0."); - return 0; - } - - length = std::min(length, v.size() - offset); - - T sum = 0; - for(size_t i = 0; i < length; i++) { - const size_t shift = (mostSignificantByteFirst ? length - 1 - i : i) * 8; - sum |= static_cast(static_cast(v[offset + i])) << shift; - } - - return sum; -} - template ByteVector fromNumber(T value, bool mostSignificantByteFirst) { From bc2d3ea72ebaccc66429c419be77a8a6f4d95b7c Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 2 Jun 2013 02:05:11 +0900 Subject: [PATCH 08/23] Fixed compilation error with GCC4.2 --- taglib/toolkit/tfile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index 279524b3..4a05b05f 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -69,9 +69,9 @@ using namespace TagLib; namespace { #ifdef _WIN32 - const uint BufferSize = 8192; + const TagLib::uint BufferSize = 8192; #else - const uint BufferSize = 1024; + const TagLib::uint BufferSize = 1024; #endif } From 90a4bae6ccf7496b85ff0e41901bda8f383fc4d2 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 2 Jun 2013 02:37:15 +0900 Subject: [PATCH 09/23] Fixed compilation error with GCC4.2 --- taglib/toolkit/tfilestream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 9cd1be42..3bf68e0e 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -45,7 +45,7 @@ namespace typedef FileName FileNameHandle; typedef HANDLE FileHandle; - const uint BufferSize = 8192; + const TagLib::uint BufferSize = 8192; const FileHandle InvalidFileHandle = INVALID_HANDLE_VALUE; inline FileHandle openFile(const FileName &path, bool readOnly) @@ -122,7 +122,7 @@ namespace typedef FILE* FileHandle; - const uint BufferSize = 8192; + const TagLib::uint BufferSize = 8192; const FileHandle InvalidFileHandle = 0; inline FileHandle openFile(const FileName &path, bool readOnly) From 860a605c8d830e9ef83b64ce157bb4a2e2e40d29 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 2 Jun 2013 03:45:13 +0900 Subject: [PATCH 10/23] Fixed behavior change of ByteVector::containsAt() --- taglib/toolkit/tbytevector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index ce47fbb8..631acc87 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -601,11 +601,11 @@ bool ByteVector::containsAt(const ByteVector &pattern, uint offset, uint pattern patternLength = pattern.size(); // do some sanity checking -- all of these things are needed for the search to be valid - - if(offset + patternLength > size() || patternOffset >= pattern.size() || patternLength == 0) + const uint compareLength = patternLength - patternOffset; + if(offset + compareLength > size() || patternOffset >= pattern.size() || patternLength == 0) return false; - return (::memcmp(data() + offset, pattern.data() + patternOffset, patternLength - patternOffset) == 0); + return (::memcmp(data() + offset, pattern.data() + patternOffset, compareLength) == 0); } bool ByteVector::startsWith(const ByteVector &pattern) const From 767a6ec4a2245d4f2cb9224eecd5c36f51f91fb4 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 2 Jun 2013 03:58:50 +0900 Subject: [PATCH 11/23] Added some tests for containsAt() --- tests/test_bytevector.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index dd433456..9efd23af 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -112,12 +112,17 @@ public: ByteVector s2("f"); CPPUNIT_ASSERT(ByteVectorList::split(s2, " ").size() == 1); - CPPUNIT_ASSERT(ByteVector().size() == 0); CPPUNIT_ASSERT(ByteVector("asdf").clear().size() == 0); CPPUNIT_ASSERT(ByteVector("asdf").clear() == ByteVector()); - } + ByteVector i("blah blah"); + ByteVector j("blah"); + CPPUNIT_ASSERT(i.containsAt(j, 5, 0)); + CPPUNIT_ASSERT(i.containsAt(j, 6, 1)); + CPPUNIT_ASSERT(i.containsAt(j, 6, 1, 3)); + } + void testFind1() { CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO")); From 36d7f9ba32db33e5847786b96af23a41a82a1a01 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 6 Jun 2013 13:45:23 +0900 Subject: [PATCH 12/23] Removed the dependency on shlwapi.dll in Win32 --- ConfigureChecks.cmake | 9 --------- cmake/modules/FindShlwapi.cmake | 14 -------------- taglib/CMakeLists.txt | 12 ------------ taglib/fileref.cpp | 30 +++++++++--------------------- taglib/toolkit/tfilestream.cpp | 31 +------------------------------ taglib/toolkit/tiostream.cpp | 21 +++++++++++++++++++++ taglib/toolkit/tiostream.h | 2 ++ 7 files changed, 33 insertions(+), 86 deletions(-) delete mode 100755 cmake/modules/FindShlwapi.cmake diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 192c1441..b0f164a9 100755 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -219,15 +219,6 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) -if(WIN32 AND NOT MSVC) - find_package(SHLWAPI) - if(SHLWAPI_FOUND) - set(HAVE_SHLWAPI 1) - else() - set(HAVE_SHLWAPI 0) - endif() -endif() - find_package(CppUnit) if(NOT CppUnit_FOUND AND BUILD_TESTS) message(STATUS "CppUnit not found, disabling tests.") diff --git a/cmake/modules/FindShlwapi.cmake b/cmake/modules/FindShlwapi.cmake deleted file mode 100755 index cba253f0..00000000 --- a/cmake/modules/FindShlwapi.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# * -# * It is what it is, you can do with it as you please. -# * -# * Just don't blame me if it teaches your computer to smoke! -# * -# * -Enjoy -# * fh :)_~ -# * -FIND_PATH(SHLWAPI_INCLUDE_DIR shlwapi.h) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SHLWAPI REQUIRED_VARS SHLWAPI_LIBRARY SHLWAPI_INCLUDE_DIR) -IF(SHLWAPI_FOUND) - SET(SHLWAPI_LIBRARIES ${SHLWAPI_LIBRARY} ) -ENDIF(SHLWAPI_FOUND) - diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 1753fa33..352f7e2e 100755 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -30,10 +30,6 @@ if(ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIR}) endif() -if(NOT MSVC AND SHLWAPI_FOUND) - include_directories(${SHLWAPI_INCLUDE_DIR}) -endif() - set(tag_HDRS tag.h fileref.h @@ -315,14 +311,6 @@ if(ZLIB_FOUND) target_link_libraries(tag ${ZLIB_LIBRARIES}) endif() -if(MSVC) - target_link_libraries(tag shlwapi.lib) -else() - if(SHLWAPI_FOUND) - target_link_libraries(tag ${SHLWAPI_LIBRARIES}) - endif() -endif() - set_target_properties(tag PROPERTIES VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH} SOVERSION ${TAGLIB_SOVERSION_MAJOR} diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 157ba2ee..d13a2837 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -29,10 +29,6 @@ #include "taglib_config.h" -#ifdef _WIN32 -# include -#endif - #include #include #include @@ -222,29 +218,21 @@ File *FileRef::create(FileName fileName, bool readAudioProperties, // Ok, this is really dumb for now, but it works for testing. String ext; - -#ifdef _WIN32 - // Avoids direct conversion from FileName to String - // because String can't decode strings in local encodings properly. - - if(!fileName.wstr().empty()) { - const wchar_t *pext = PathFindExtensionW(fileName.wstr().c_str()); - if(*pext == L'.') - ext = String(pext + 1).upper(); - } - else { - const char *pext = PathFindExtensionA(fileName.str().c_str()); - if(*pext == '.') - ext = String(pext + 1).upper(); - } -#else { +#ifdef _WIN32 + + String s = fileName.toString(); + +#else + String s = fileName; + + #endif + const int pos = s.rfind("."); if(pos != -1) ext = s.substr(pos + 1).upper(); } -#endif // If this list is updated, the method defaultFileExtensions() should also be // updated. However at some point that list should be created at the same time diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 3bf68e0e..eae52573 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -83,35 +83,6 @@ namespace return 0; } -# ifndef NDEBUG - - // Convert a string in a local encoding into a UTF-16 string. - - // Debugging use only. In actual use, file names in local encodings are passed to - // CreateFileA() without any conversions. - - String fileNameToString(const FileName &name) - { - if(!name.wstr().empty()) { - return String(name.wstr()); - } - else if(!name.str().empty()) { - const int len = MultiByteToWideChar(CP_ACP, 0, name.str().c_str(), -1, NULL, 0); - if(len == 0) - return String::null; - - wstring wstr(len, L'\0'); - MultiByteToWideChar(CP_ACP, 0, name.str().c_str(), -1, &wstr[0], len); - - return String(wstr); - } - else { - return String::null; - } - } - -# endif - #else // _WIN32 struct FileNameHandle : public std::string @@ -183,7 +154,7 @@ FileStream::FileStream(FileName fileName, bool openReadOnly) if(d->file == InvalidFileHandle) { # ifdef _WIN32 - debug("Could not open file " + fileNameToString(fileName)); + debug("Could not open file " + fileName.toString()); # else debug("Could not open file " + String(static_cast(d->name))); # endif diff --git a/taglib/toolkit/tiostream.cpp b/taglib/toolkit/tiostream.cpp index ee4e4a61..3069bb53 100644 --- a/taglib/toolkit/tiostream.cpp +++ b/taglib/toolkit/tiostream.cpp @@ -124,6 +124,27 @@ const std::string &FileName::str() const return d->name; } +String FileName::toString() const +{ + if(!d->wname.empty()) { + return String(d->wname); + } + else if(!d->name.empty()) { + const int len = MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, NULL, 0); + if(len == 0) + return String::null; + + std::vector buf(len); + MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, &buf[0], len); + + return String(&buf[0]); + } + else { + return String::null; + } +} + + #endif // _WIN32 //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index 498b3a45..22147f8a 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -48,6 +48,8 @@ namespace TagLib { const std::wstring &wstr() const; const std::string &str() const; + String toString() const; + private: class FileNamePrivate; FileNamePrivate *d; From fc9abc7a331f0c9410317e8f6df229a3f9fd6abe Mon Sep 17 00:00:00 2001 From: naiar Date: Fri, 7 Jun 2013 20:00:13 +0900 Subject: [PATCH 13/23] fixed build failure --- tests/test_flac.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index 7f40a382..caec7153 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -239,8 +239,8 @@ public: map["HÄÖ"] = String("bla"); FLAC::File f(copy.fileName().c_str()); PropertyMap invalid = f.setProperties(map); - CPPUNIT_ASSERT_EQUAL(uint(1), invalid.size()); - CPPUNIT_ASSERT_EQUAL(uint(0), f.properties().size()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), invalid.size()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.properties().size()); } }; From e18546560e875bce9d9290ce72ff0c2b6915b091 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 02:51:20 +0900 Subject: [PATCH 14/23] 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 15/23] 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 dce00b96b8a47ce83441ce90cc0e3ae8a223d0a1 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 13:14:06 +0900 Subject: [PATCH 16/23] Revert "Fixed some MSVC specific warnings" This reverts commit 93f304a91d83ca3f58dfcdc47aecd183ee128813. --- taglib/toolkit/tiostream.cpp | 47 ++++++++++++------------------------ taglib/toolkit/tiostream.h | 8 ++---- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/taglib/toolkit/tiostream.cpp b/taglib/toolkit/tiostream.cpp index 3069bb53..df540ca8 100644 --- a/taglib/toolkit/tiostream.cpp +++ b/taglib/toolkit/tiostream.cpp @@ -69,73 +69,58 @@ namespace } } -class FileName::FileNamePrivate -{ -public: - std::wstring wname; - std::string name; -}; +// If WinNT, stores a Unicode string into m_wname directly. +// If Win9x, converts and stores it into m_name to avoid calling Unicode version functions. FileName::FileName(const wchar_t *name) - : d(new FileNamePrivate()) + : m_wname(SystemSupportsUnicode ? name : L"") + , m_name (SystemSupportsUnicode ? "" : unicodeToAnsi(name)) { - // If Windows NT, stores a Unicode string directly. - // If Windows 9x, stores it converting into an ANSI string. - if(SystemSupportsUnicode) - d->wname = name; - else - d->name = unicodeToAnsi(name); } FileName::FileName(const char *name) - : d(new FileNamePrivate()) + : m_name(name) { - d->name = name; } FileName::FileName(const FileName &name) - : d(new FileNamePrivate(*name.d)) + : m_wname(name.m_wname) + , m_name (name.m_name) { } -FileName &FileName::operator==(const FileName &name) -{ - *d = *name.d; - return *this; -} - FileName::operator const wchar_t *() const { - return d->wname.c_str(); + return m_wname.c_str(); } FileName::operator const char *() const { - return d->name.c_str(); + return m_name.c_str(); } const std::wstring &FileName::wstr() const { - return d->wname; + return m_wname; } const std::string &FileName::str() const { - return d->name; + return m_name; } String FileName::toString() const { - if(!d->wname.empty()) { - return String(d->wname); + if(!m_wname.empty()) { + return String(m_wname); } - else if(!d->name.empty()) { - const int len = MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, NULL, 0); + else if(!m_name.empty()) { + const int len = MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, NULL, 0); if(len == 0) return String::null; std::vector buf(len); - MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, &buf[0], len); + MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, &buf[0], len); return String(&buf[0]); } diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index 22147f8a..86826964 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -40,7 +40,6 @@ namespace TagLib { FileName(const char *name); FileName(const FileName &name); - FileName &operator==(const FileName &name); operator const wchar_t *() const; operator const char *() const; @@ -51,14 +50,11 @@ namespace TagLib { String toString() const; private: - class FileNamePrivate; - FileNamePrivate *d; + const std::string m_name; + const std::wstring m_wname; }; - #else - typedef const char *FileName; - #endif //! An abstract class that provides operations on a sequence of bytes From 448648d61be288fb0c4193d2937f2c9bccf6763d Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 8 Jun 2013 21:40:30 +0900 Subject: [PATCH 17/23] 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 18/23] 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 19/23] 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 20/23] 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 21/23] 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 22/23] 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 23/23] 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); }