diff --git a/CMakeLists.txt b/CMakeLists.txt index 91e1901d..f410e098 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ option(BUILD_EXAMPLES "Build the examples" OFF) option(NO_ITUNES_HACKS "Disable workarounds for iTunes bugs" OFF) +add_definitions(-DHAVE_CONFIG_H) set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/") ## the following are directories where stuff will be installed to diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index 007ab823..a4bf2b0b 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -19,7 +19,6 @@ * USA * ***************************************************************************/ -#include "config.h" #include #include #include diff --git a/taglib/asf/asfproperties.cpp b/taglib/asf/asfproperties.cpp index 1cd70ddf..18cd4c94 100644 --- a/taglib/asf/asfproperties.cpp +++ b/taglib/asf/asfproperties.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include #include "asfproperties.h" diff --git a/taglib/asf/asftag.cpp b/taglib/asf/asftag.cpp index 0132ba69..634df846 100644 --- a/taglib/asf/asftag.cpp +++ b/taglib/asf/asftag.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include "asftag.h" diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 5434ae44..ef6f745d 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -27,8 +27,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" - #include "tfile.h" #include "tstring.h" #include "tdebug.h" diff --git a/taglib/mp4/mp4properties.cpp b/taglib/mp4/mp4properties.cpp index 6823b36d..ac7da3f7 100644 --- a/taglib/mp4/mp4properties.cpp +++ b/taglib/mp4/mp4properties.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include #include "mp4file.h" diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 57bf9dc0..20fd5de0 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include #include diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp index 639d9673..60c6d18b 100644 --- a/taglib/mpeg/id3v2/id3v2frame.cpp +++ b/taglib/mpeg/id3v2/id3v2frame.cpp @@ -23,8 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" -#include "taglib_config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #if HAVE_ZLIB #include diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 534eeefc..9d5c5c19 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -23,8 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" -#include "taglib_config.h" +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include "id3v2framefactory.h" diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index a1dcacf1..a3bd3192 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -23,6 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include "id3v2tag.h" diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index d5f1bdaf..d04fb921 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -23,7 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include #include @@ -31,19 +33,11 @@ #include #include -#if defined(HAVE_MSC_BYTESWAP) -# include -#elif defined(HAVE_GLIBC_BYTESWAP) -# include -#elif defined(HAVE_MAC_BYTESWAP) -# include -#elif defined(HAVE_OPENBSD_BYTESWAP) -# include -#endif - #include "tstring.h" #include "tdebug.h" #include "tsmartptr.h" +#include "tutils.h" + #include "tbytevector.h" // This is a bit ugly to keep writing over and over again. @@ -189,113 +183,6 @@ size_t findVector( return ByteVector::npos; } -template -inline T byteSwap(T x) -{ - // There should be 16,32 and 64-bit versions. - debug("byteSwap() -- Non specialized version should not be called"); - return 0; -} - -template <> -inline ushort byteSwap(ushort x) -{ -#if defined(HAVE_GCC_BYTESWAP_16) - - return __builtin_bswap16(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_ushort(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_16(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt16(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap16(x); - -#else - - return ((x >> 8) & 0xff) | ((x & 0xff) << 8); - -#endif -} - -template <> -inline uint byteSwap(uint x) -{ -#if defined(HAVE_GCC_BYTESWAP_32) - - return __builtin_bswap32(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_ulong(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_32(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt32(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap32(x); - -#else - - return ((x & 0xff000000u) >> 24) - | ((x & 0x00ff0000u) >> 8) - | ((x & 0x0000ff00u) << 8) - | ((x & 0x000000ffu) << 24); - -#endif -} - -template <> -inline ulonglong byteSwap(ulonglong x) -{ -#if defined(HAVE_GCC_BYTESWAP_64) - - return __builtin_bswap64(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_uint64(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_64(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt64(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap64(x); - -#else - - return ((x & 0xff00000000000000ull) >> 56) - | ((x & 0x00ff000000000000ull) >> 40) - | ((x & 0x0000ff0000000000ull) >> 24) - | ((x & 0x000000ff00000000ull) >> 8) - | ((x & 0x00000000ff000000ull) << 8) - | ((x & 0x0000000000ff0000ull) << 24) - | ((x & 0x000000000000ff00ull) << 40) - | ((x & 0x00000000000000ffull) << 56); - -#endif -} namespace { enum Endianness { @@ -320,7 +207,7 @@ inline T toNumber(const ByteVector &v, size_t offset) ::memcpy(&tmp, v.data() + offset, sizeof(T)); if(swap) - return byteSwap(tmp); + return byteSwap(tmp); else return tmp; } @@ -352,7 +239,7 @@ inline ByteVector fromNumber(T value) #endif if(swap) - value = byteSwap(value); + value = byteSwap(value); return ByteVector(reinterpret_cast(&value), sizeof(T)); } @@ -839,7 +726,7 @@ float ByteVector::toFloat32BE(size_t offset) const ::memcpy(&tmp, data() + offset, 4); # if SYSTEM_BYTEORDER == 1 - tmp.i = byteSwap(tmp.i); + tmp.i = byteSwap(tmp.i); # endif return tmp.f; @@ -900,7 +787,7 @@ double ByteVector::toFloat64BE(size_t offset) const ::memcpy(&tmp, data() + offset, 8); # if SYSTEM_BYTEORDER == 1 - tmp.i = byteSwap(tmp.i); + tmp.i = byteSwap(tmp.i); # endif return tmp.f; diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 65c51efe..71350af7 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -23,7 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include "tdebug.h" #include "tstring.h" diff --git a/taglib/toolkit/trefcounter.cpp b/taglib/toolkit/trefcounter.cpp index 495c2529..f9a9f952 100644 --- a/taglib/toolkit/trefcounter.cpp +++ b/taglib/toolkit/trefcounter.cpp @@ -23,7 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif + #include "trefcounter.h" #if defined(HAVE_STD_ATOMIC) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 88cd3e6f..373d533f 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -25,27 +25,20 @@ // This class assumes that std::basic_string has a contiguous and null-terminated buffer. -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include "tstring.h" #include "tdebug.h" #include "tstringlist.h" #include "tsmartptr.h" +#include "tutils.h" #include #include #include -#if defined(HAVE_MSC_BYTESWAP) -# include -#elif defined(HAVE_GLIBC_BYTESWAP) -# include -#elif defined(HAVE_MAC_BYTESWAP) -# include -#elif defined(HAVE_OPENBSD_BYTESWAP) -# include -#endif - #ifdef HAVE_STD_CODECVT # include #else @@ -54,34 +47,6 @@ namespace { - inline TagLib::ushort byteSwap(TagLib::ushort x) - { -#if defined(HAVE_GCC_BYTESWAP_16) - - return __builtin_bswap16(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_ushort(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_16(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt16(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap16(x); - -#else - - return ((x >> 8) & 0xff) | ((x & 0xff) << 8); - -#endif - } inline unsigned short combine(unsigned char c1, unsigned char c2) { diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h new file mode 100644 index 00000000..73c35716 --- /dev/null +++ b/taglib/toolkit/tutils.h @@ -0,0 +1,151 @@ +/*************************************************************************** + 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_TUTILS_H +#define TAGLIB_TUTILS_H + +// THIS FILE IS NOT A PART OF THE TAGLIB API + +#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if defined(HAVE_MSC_BYTESWAP) +# include +#elif defined(HAVE_GLIBC_BYTESWAP) +# include +#elif defined(HAVE_MAC_BYTESWAP) +# include +#elif defined(HAVE_OPENBSD_BYTESWAP) +# include +#endif + +namespace TagLib +{ + + inline ushort byteSwap(ushort x) + { +#if defined(HAVE_GCC_BYTESWAP_16) + + return __builtin_bswap16(x); + +#elif defined(HAVE_MSC_BYTESWAP) + + return _byteswap_ushort(x); + +#elif defined(HAVE_GLIBC_BYTESWAP) + + return __bswap_16(x); + +#elif defined(HAVE_MAC_BYTESWAP) + + return OSSwapInt16(x); + +#elif defined(HAVE_OPENBSD_BYTESWAP) + + return swap16(x); + +#else + + return ((x >> 8) & 0xff) | ((x & 0xff) << 8); + +#endif + } + + inline uint byteSwap(uint x) + { +#if defined(HAVE_GCC_BYTESWAP_32) + + return __builtin_bswap32(x); + +#elif defined(HAVE_MSC_BYTESWAP) + + return _byteswap_ulong(x); + +#elif defined(HAVE_GLIBC_BYTESWAP) + + return __bswap_32(x); + +#elif defined(HAVE_MAC_BYTESWAP) + + return OSSwapInt32(x); + +#elif defined(HAVE_OPENBSD_BYTESWAP) + + return swap32(x); + +#else + + return ((x & 0xff000000u) >> 24) + | ((x & 0x00ff0000u) >> 8) + | ((x & 0x0000ff00u) << 8) + | ((x & 0x000000ffu) << 24); + +#endif + } + + inline ulonglong byteSwap(ulonglong x) + { +#if defined(HAVE_GCC_BYTESWAP_64) + + return __builtin_bswap64(x); + +#elif defined(HAVE_MSC_BYTESWAP) + + return _byteswap_uint64(x); + +#elif defined(HAVE_GLIBC_BYTESWAP) + + return __bswap_64(x); + +#elif defined(HAVE_MAC_BYTESWAP) + + return OSSwapInt64(x); + +#elif defined(HAVE_OPENBSD_BYTESWAP) + + return swap64(x); + +#else + + return ((x & 0xff00000000000000ull) >> 56) + | ((x & 0x00ff000000000000ull) >> 40) + | ((x & 0x0000ff0000000000ull) >> 24) + | ((x & 0x000000ff00000000ull) >> 8) + | ((x & 0x00000000ff000000ull) << 8) + | ((x & 0x0000000000ff0000ull) << 24) + | ((x & 0x000000000000ff00ull) << 40) + | ((x & 0x00000000000000ffull) << 56); + +#endif + } + +}; + +#endif + +#endif diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index a3a54972..8a7492e8 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -1,6 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include -#include // so evil :( #define protected public #include diff --git a/tests/utils.h b/tests/utils.h index a2d997eb..00cef628 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,4 +1,6 @@ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #ifdef _WIN32 #include