From a16c95b33fd215f4616fa2e7a80c81bcc629d945 Mon Sep 17 00:00:00 2001 From: Michael Helmling Date: Sat, 23 Jul 2016 13:08:23 +0200 Subject: [PATCH 1/3] Adds a function for dynamic version information retrieval The current way of exposing TagLib's version only through #define's makes it impossible for clients (e.g. language bindings) to reliably determine the TagLib version that is currently in use: using the define's in client code will statically copy the compile-time values into the client's library, but if TagLib is dynamically bound the version (at least minor and patch version) can change after building client code. --- taglib/toolkit/taglib.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index 2f4c5655..18f6b270 100644 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -46,6 +46,8 @@ * \endcode */ +#include + namespace TagLib { enum ByteOrder @@ -53,6 +55,13 @@ namespace TagLib LittleEndian, BigEndian }; + /*! + * Returns the library's version information as 3-tuple of ints (for major, minor, patch version). + */ + std::tuple version() + { + return std::make_tuple(TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION, TAGLIB_PATCH_VERSION); + } } /*! From 0f096af50404989b24b97bf8280db3c577672364 Mon Sep 17 00:00:00 2001 From: Michael Helmling Date: Thu, 28 Jul 2016 22:32:44 +0200 Subject: [PATCH 2/3] Extend dynamic version retrieval; remove C++11 dependency --- taglib/CMakeLists.txt | 1 + taglib/toolkit/taglib.cpp | 34 ++++++++++++++++++++++++++++++++++ taglib/toolkit/taglib.h | 34 +++++++++++++++++++++++++++------- 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 taglib/toolkit/taglib.cpp diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 6d8e483f..361b8a79 100644 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -321,6 +321,7 @@ set(matroska_SRCS ) set(toolkit_SRCS + toolkit/taglib.cpp toolkit/tstring.cpp toolkit/tstringlist.cpp toolkit/tstringhandler.cpp diff --git a/taglib/toolkit/taglib.cpp b/taglib/toolkit/taglib.cpp new file mode 100644 index 00000000..ffae16eb --- /dev/null +++ b/taglib/toolkit/taglib.cpp @@ -0,0 +1,34 @@ +#include "taglib.h" +#include "tstring.h" +#include + +using namespace TagLib; + +String TagLib::GetVersionString() +{ + return String::number(TAGLIB_MAJOR_VERSION) + + "." + String::number(TAGLIB_MINOR_VERSION) + + "." + String::number(TAGLIB_PATCH_VERSION); +} + +unsigned int TagLib::GetMajorVersion() +{ + return TAGLIB_MAJOR_VERSION; +} + +unsigned int TagLib::GetMinorVersion() +{ + return TAGLIB_MINOR_VERSION; +} + +unsigned int TagLib::GetPatchVersion() +{ + return TAGLIB_PATCH_VERSION; +} + +unsigned int TagLib::GetVersion() +{ + return (TAGLIB_MAJOR_VERSION << 16) + || (TAGLIB_MINOR_VERSION << 8) + || (TAGLIB_PATCH_VERSION << 4); +} diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index 18f6b270..3a5ca016 100644 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -46,8 +46,6 @@ * \endcode */ -#include - namespace TagLib { enum ByteOrder @@ -55,13 +53,35 @@ namespace TagLib LittleEndian, BigEndian }; + class String; /*! - * Returns the library's version information as 3-tuple of ints (for major, minor, patch version). + * Returns the version as a string in the form + * (Major Version).(Minor Version).(Patch Version), e.g. "4.2.0". */ - std::tuple version() - { - return std::make_tuple(TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION, TAGLIB_PATCH_VERSION); - } + String GetVersionString(); + + /*! + * Returns the version as an unsigned integer in the form + * (Major Version << 16) | (Minor Version << 8) | (Patch Version), e.g. 0x040200 + * Use this for simple and consistent version comparison, e.g. + * if (TagLib::GetVersion() <= ((1 << 16) | (11 << 8))) return false; + */ + unsigned int GetVersion(); + + /*! + * Returns the major version, e.g. 4 + */ + unsigned int GetMajorVersion(); + + /*! + * Returns the minor version, e.g. 2 + */ + unsigned int GetMinorVersion(); + + /*! + * Returns the patch version, e.g. 0 + */ + unsigned int GetPatchVersion(); } /*! From c352425ee708412f514d383ba5744fbc429228e6 Mon Sep 17 00:00:00 2001 From: Michael Helmling Date: Sat, 30 Jul 2016 13:47:46 +0200 Subject: [PATCH 3/3] Adjust version macros to TagLib naming conventions; use dedicated namespace --- taglib/toolkit/taglib.cpp | 37 +++++++++++++++------------- taglib/toolkit/taglib.h | 51 +++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/taglib/toolkit/taglib.cpp b/taglib/toolkit/taglib.cpp index ffae16eb..e65a6e77 100644 --- a/taglib/toolkit/taglib.cpp +++ b/taglib/toolkit/taglib.cpp @@ -4,31 +4,34 @@ using namespace TagLib; -String TagLib::GetVersionString() + +String TagLib::Version::string() { return String::number(TAGLIB_MAJOR_VERSION) + "." + String::number(TAGLIB_MINOR_VERSION) + "." + String::number(TAGLIB_PATCH_VERSION); } -unsigned int TagLib::GetMajorVersion() -{ - return TAGLIB_MAJOR_VERSION; -} - -unsigned int TagLib::GetMinorVersion() -{ - return TAGLIB_MINOR_VERSION; -} - -unsigned int TagLib::GetPatchVersion() -{ - return TAGLIB_PATCH_VERSION; -} - -unsigned int TagLib::GetVersion() +unsigned int TagLib::Version::combined() { return (TAGLIB_MAJOR_VERSION << 16) || (TAGLIB_MINOR_VERSION << 8) || (TAGLIB_PATCH_VERSION << 4); } + + +unsigned int (TagLib::Version::major)() +{ + return TAGLIB_MAJOR_VERSION; +} + +unsigned int (TagLib::Version::minor)() +{ + return TAGLIB_MINOR_VERSION; +} + +unsigned int TagLib::Version::patch() +{ + return TAGLIB_PATCH_VERSION; +} + diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index 3a5ca016..7cc3718c 100644 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -54,34 +54,37 @@ namespace TagLib BigEndian }; class String; - /*! - * Returns the version as a string in the form - * (Major Version).(Minor Version).(Patch Version), e.g. "4.2.0". - */ - String GetVersionString(); + namespace Version + { + /*! + * Returns the version as a string in the form + * (Major Version).(Minor Version).(Patch Version), e.g. "4.2.0". + */ + String string(); - /*! - * Returns the version as an unsigned integer in the form - * (Major Version << 16) | (Minor Version << 8) | (Patch Version), e.g. 0x040200 - * Use this for simple and consistent version comparison, e.g. - * if (TagLib::GetVersion() <= ((1 << 16) | (11 << 8))) return false; - */ - unsigned int GetVersion(); + /*! + * Returns the version as an unsigned integer in the form + * (Major Version << 16) | (Minor Version << 8) | (Patch Version), e.g. 0x040200 + * Use this for simple and consistent version comparison, e.g. + * if (TagLib::GetVersion() <= ((1 << 16) | (11 << 8))) return false; + */ + unsigned int combined(); - /*! - * Returns the major version, e.g. 4 - */ - unsigned int GetMajorVersion(); + /*! + * Returns the major version, e.g. 4 + */ + unsigned int (major)(); - /*! - * Returns the minor version, e.g. 2 - */ - unsigned int GetMinorVersion(); + /*! + * Returns the minor version, e.g. 2 + */ + unsigned int (minor)(); - /*! - * Returns the patch version, e.g. 0 - */ - unsigned int GetPatchVersion(); + /*! + * Returns the patch version, e.g. 0 + */ + unsigned int patch(); + } } /*!