]> granicus.if.org Git - taglib/commitdiff
Refactor out some stuff to CMake tests
authorTsuda kageyu <tsuda.kageyu@gmail.com>
Sun, 21 Apr 2013 13:24:12 +0000 (22:24 +0900)
committerTsuda kageyu <tsuda.kageyu@gmail.com>
Sun, 21 Apr 2013 13:24:12 +0000 (22:24 +0900)
26 files changed:
CMakeLists.txt
ConfigureChecks.cmake
config-taglib.h.cmake
taglib/CMakeLists.txt
taglib/asf/asfattribute.cpp
taglib/asf/asffile.cpp
taglib/asf/asfpicture.cpp
taglib/asf/asfproperties.cpp
taglib/asf/asftag.cpp
taglib/fileref.cpp
taglib/flac/flacmetadatablock.cpp
taglib/flac/flacpicture.cpp
taglib/flac/flacunknownmetadatablock.cpp
taglib/mp4/mp4atom.cpp
taglib/mp4/mp4coverart.cpp
taglib/mp4/mp4file.cpp
taglib/mp4/mp4item.cpp
taglib/mp4/mp4properties.cpp
taglib/mp4/mp4tag.cpp
taglib/mpeg/id3v2/id3v2frame.cpp
taglib/mpeg/id3v2/id3v2framefactory.cpp
taglib/toolkit/taglib.h
taglib/toolkit/tbyteswap.cpp [deleted file]
taglib/toolkit/tbyteswap.h [deleted file]
taglib/toolkit/tbytevector.cpp
taglib/toolkit/tstring.cpp

index 1f29e4634a65452b532cbd1f6912e7dfe5ef2707..14f0095611714c27dcbebf1cd1350e406999a85e 100755 (executable)
@@ -21,7 +21,6 @@ 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
index 4b8f512ec07a766e81595877706edf29ea27682f..11db70d85dec44b81cb63445d6c204e5104459ac 100644 (file)
@@ -5,8 +5,170 @@ include(CheckFunctionExists)
 include(CheckLibraryExists)
 include(CheckTypeSize)
 include(CheckCXXSourceCompiles)
+include(TestBigEndian)
+
+# Determine the CPU byte order.
+
+test_big_endian(TAGLIB_BIG_ENDIAN)
+
+if(NOT ${TAGLIB_BIG_ENDIAN})
+set(TAGLIB_LITTLE_ENDIAN 1)
+endif()
+
+# Determine the size of integral types.
+
+check_type_size("short"     SIZEOF_SHORT)
+check_type_size("int"       SIZEOF_INT)
+check_type_size("long long" SIZEOF_LONGLONG)
+check_type_size("wchar_t"   SIZEOF_WCHAR_T)
+
+# Determine if your compiler supports std::wstring.
+
+check_cxx_source_compiles("
+       #include <string>
+       int main() { 
+               std::wstring x(L\"ABC\");
+               return 0; 
+       }
+" HAVE_STD_WSTRING)
+
+# Determine which kind of atomic operations your compiler supports.
+
+check_cxx_source_compiles("
+       #include <atomic>
+       int main() { 
+               std::atomic<unsigned int> x;
+               x.fetch_add(1);
+               x.fetch_sub(1);
+               return 0; 
+       }
+" HAVE_STD_ATOMIC)
+
+check_cxx_source_compiles("
+       #include <boost/atomic.hpp>
+       int main() { 
+               boost::atomic<unsigned int> x(1);
+               x.fetch_add(1);
+               x.fetch_sub(1);
+               return 0; 
+       }
+" HAVE_BOOST_ATOMIC)
+
+check_cxx_source_compiles("
+       int main() { 
+               volatile int x;
+               __sync_add_and_fetch(&x, 1);
+               int y = __sync_sub_and_fetch(&x, 1);
+               return 0; 
+       }
+" HAVE_GCC_ATOMIC)
+
+check_cxx_source_compiles("
+       #include <libkern/OSAtomic.h>
+       int main() { 
+               volatile int32_t x;
+               OSAtomicIncrement32Barrier(&x);
+               int32_t y = OSAtomicDecrement32Barrier(&x);
+               return 0; 
+       }
+" HAVE_MAC_ATOMIC)
+
+check_cxx_source_compiles("
+       #include <windows.h>
+       int main() { 
+               volatile LONG x;
+               InterlockedIncrement(&x);
+               LONG y = InterlockedDecrement(&x);
+               return 0; 
+       }
+" HAVE_WIN_ATOMIC)
+
+check_cxx_source_compiles("
+       #include <ia64intrin.h>
+       int main() { 
+               volatile int x;
+               __sync_add_and_fetch(&x, 1);
+               int y = __sync_sub_and_fetch(&x, 1);
+               return 0; 
+       }
+" HAVE_IA64_ATOMIC)
+
+# Determine which kind of byte swap functions your compiler supports.
+
+# Some of them can be missing depends on the GCC version.
+check_cxx_source_compiles("
+       int main() {
+               __builtin_bswap16(0);
+               return 0; 
+       }
+" HAVE_GCC_BYTESWAP_16)
+
+check_cxx_source_compiles("
+       int main() {
+               __builtin_bswap32(0);
+               return 0; 
+       }
+" HAVE_GCC_BYTESWAP_32)
+
+check_cxx_source_compiles("
+       int main() {
+               __builtin_bswap64(0);
+               return 0; 
+       }
+" HAVE_GCC_BYTESWAP_64)
+
+check_cxx_source_compiles("
+       #include <stdlib.h>
+       int main() {
+               _byteswap_ushort(0);
+               _byteswap_ulong(0);
+               _byteswap_uint64(0);
+               return 0; 
+       }
+" HAVE_MSC_BYTESWAP)
+
+check_cxx_source_compiles("
+       #include <byteswap.h>
+       int main() {
+               __bswap_16(0);
+               __bswap_32(0);
+               __bswap_64(0);
+               return 0; 
+       }
+" HAVE_GLIBC_BYTESWAP)
+
+check_cxx_source_compiles("
+       #include <libkern/OSByteOrder.h>
+       int main() {
+               OSSwapInt16(0);
+               OSSwapInt32(0);
+               OSSwapInt64(0);
+               return 0; 
+       }
+" HAVE_MAC_BYTESWAP)
+
+check_cxx_source_compiles("
+       #include <sys/endian.h>
+       int main() {
+               swap16(0);
+               swap32(0);
+               swap64(0);
+               return 0; 
+       }
+" HAVE_OPENBSD_BYTESWAP)
+
+# Determine whether your compiler supports codecvt.
+
+check_cxx_source_compiles("
+       #include <codecvt>
+       int main() { 
+               std::codecvt_utf8_utf16<wchar_t> x; 
+               return 0; 
+       }
+" HAVE_STD_CODECVT)
+
+# Check for libz using the cmake supplied FindZLIB.cmake
 
-# check for libz using the cmake supplied FindZLIB.cmake
 find_package(ZLIB)
 if(ZLIB_FOUND)
        set(HAVE_ZLIB 1)
@@ -14,12 +176,6 @@ else()
        set(HAVE_ZLIB 0)
 endif()
 
-# Determine whether your compiler supports codecvt header.
-
-check_cxx_source_compiles("
-       #include <codecvt>
-       int main() { std::codecvt_utf8_utf16<wchar_t> x; return 0; }
-" HAVE_CODECVT)
 
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
 find_package(CppUnit)
index 9fcc29a4564f7213f72b6d6104282c5fbdba9cf6..bb25bb868c010837b873f3a5ef6816ffc14af897 100644 (file)
@@ -1,10 +1,40 @@
 /* config-taglib.h. Generated by cmake from config-taglib.h.cmake */
 
-/* Define if you have libz */
-#cmakedefine   HAVE_ZLIB 1
+/* Indicates the endianness of your target system */
+#cmakedefine   TAGLIB_LITTLE_ENDIAN 1
+#cmakedefine   TAGLIB_BIG_ENDIAN 1
+
+/* Size of integral types */
+#cmakedefine   SIZEOF_SHORT    ${SIZEOF_SHORT}
+#cmakedefine   SIZEOF_INT      ${SIZEOF_INT}
+#cmakedefine   SIZEOF_LONGLONG ${SIZEOF_LONGLONG}
+#cmakedefine   SIZEOF_WCHAR_T  ${SIZEOF_WCHAR_T}
+
+/* Defined if your compiler supports std::wstring */
+#cmakedefine   HAVE_STD_WSTRING 1
+
+/* Defined if your compiler supports some atomic operations */
+#cmakedefine   HAVE_STD_ATOMIC 1
+#cmakedefine   HAVE_BOOST_ATOMIC 1
+#cmakedefine   HAVE_GCC_ATOMIC 1
+#cmakedefine   HAVE_MAC_ATOMIC 1
+#cmakedefine   HAVE_WIN_ATOMIC 1
+#cmakedefine   HAVE_IA64_ATOMIC 1
 
-/* Defined if your compiler has <codecvt> header */
-#cmakedefine   HAVE_CODECVT 1
+/* Defined if your compiler supports some byte swap functions */
+#cmakedefine   HAVE_GCC_BYTESWAP_16 1
+#cmakedefine   HAVE_GCC_BYTESWAP_32 1
+#cmakedefine   HAVE_GCC_BYTESWAP_64 1
+#cmakedefine   HAVE_MSC_BYTESWAP 1
+#cmakedefine   HAVE_GLIBC_BYTESWAP 1
+#cmakedefine   HAVE_MAC_BYTESWAP 1
+#cmakedefine   HAVE_OPENBSD_BYTESWAP 1
+
+/* Defined if your compiler supports codecvt */
+#cmakedefine   HAVE_STD_CODECVT 1
+
+/* Defined if you have libz */
+#cmakedefine   HAVE_ZLIB 1
 
 #cmakedefine   NO_ITUNES_HACKS 1
 #cmakedefine   WITH_ASF 1
index a940caf5def3d2d4a726bfb897b6e0fb68db22ec..72712ca2ad915bdf8d90534ea3c06102b01fa4a7 100644 (file)
@@ -50,7 +50,6 @@ set(tag_HDRS
   toolkit/tmap.h
   toolkit/tmap.tcc
   toolkit/tpropertymap.h
-  toolkit/tbyteswap.h
   mpeg/mpegfile.h
   mpeg/mpegproperties.h
   mpeg/mpegheader.h
@@ -290,7 +289,6 @@ set(toolkit_SRCS
   toolkit/tfilestream.cpp
   toolkit/tdebug.cpp
   toolkit/tpropertymap.cpp
-  toolkit/tbyteswap.cpp
   toolkit/unicode.cpp
 )
 
index 2cfada7b0fa3d516321640a63b38bf010a811699..937a8816d748de7666f3f4128340fa0a484fc129 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include "asfattribute.h"
index 56e93a76c7fd6eb5a3a5c2faca38cc66015ea53a..241998ca84c58d56b7be2310da9ebaf4f552af7f 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <tdebug.h>
 #include <tbytevectorlist.h>
 #include <tpropertymap.h>
index 35e52a7d5062a59da27cd74b4d0b02097eba5bed..3db695a4e9e38cfb05a16d21afccbc333dcb58d3 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include "asfattribute.h"
index 835cbdf9891b3769d520c9dbfc195a5cb3fda714..11d43b9d9e4328e8604b37149de3f0a1d0804421 100644 (file)
@@ -23,9 +23,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <tdebug.h>
 #include <tstring.h>
index 1cbd16eb553300af16014f5bf809335b9b490c77..70881209e7d1bd4d18bd01e538930cd7b19d8d26 100644 (file)
@@ -23,9 +23,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <tpropertymap.h>
 #include "asftag.h"
index 46e59ff16bc1311e177afd276ddfdeaf7efcb6db..6da560b704cdb1ffd2ed47646402f6f442789021 100644 (file)
@@ -27,9 +27,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 
 #ifdef _WIN32
 # include <Shlwapi.h>
index 7d161c27de32cf768b4bde479c90c4d4db99f63c..17ab05f376062ef2461086bc63e1981a1ca1a9ed 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include "flacmetadatablock.h"
index 95eeb6aba6dc49c91501aa45c4e1a3304c7430ae..a2a9000b63efc17a5dd538bddd819c9e0214a171 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include "flacpicture.h"
index 1265affbb3b9d29cb3df72857d55c2fe211ab0db..dcd5d6515857120d80483770ce8020884410417a 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include <tstring.h>
index fac593b12e2d3b3c174897030dee3af89637df29..7b87a4796daed319ddae51147c5a9d8ff1a06d55 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <tdebug.h>
 #include <tstring.h>
 #include "mp4atom.h"
index 928e3c4aa2f22f94f8ec0fdf4cfb2a066de5e8a9..5ccc76d678337ea21d4ee6c0548985767641d670 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include "mp4coverart.h"
index f41ee88860ebba36d5aa595f1bbf2e95a1a7ee06..aab1a2bea1637b02d384412e7b8008586e855511 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <tdebug.h>
 #include <tstring.h>
 #include <tpropertymap.h>
index af2cc65c80de9f06e3da1fcf27b50679c2004ba3..fdb9645174edaa05f149cb2b4421aeffec644d61 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <taglib.h>
 #include <tdebug.h>
 #include "mp4item.h"
index e4e950720252ce5daac806441b0eea57f27f2bab..f5d7ed21be4d618ae72eea845d45a5d29b4763cf 100644 (file)
@@ -23,9 +23,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <tdebug.h>
 #include <tstring.h>
index df83796d4fa71e075476b6efcd4c31e69029dfdf..e16a994b704df7e1f3bce53f11510cf8b95cbc9a 100644 (file)
@@ -23,9 +23,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <tdebug.h>
 #include <tstring.h>
index c5c5585d48a9c332602b67a11ff906b34628c60a..a444b9eb5a5221470e3d630e84c7572f77e9ca91 100644 (file)
@@ -23,9 +23,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #if HAVE_ZLIB
 #include <zlib.h>
index c7d7421453b1359376a4cf9f03679f05a4e440d7..54b37ce80d8b9ac8f4facf1b7689990be8d026df 100644 (file)
@@ -23,9 +23,7 @@
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <tdebug.h>
 
index dd4ee69da8b050b341f58bb681435369545cc9cc..81d23f04b461e8e9b137f6ecbb7724a540ac3e89 100755 (executable)
@@ -26,6 +26,8 @@
 #ifndef TAGLIB_H
 #define TAGLIB_H
 
+#include "config.h"
+
 #define TAGLIB_MAJOR_VERSION 1
 #define TAGLIB_MINOR_VERSION 8
 #define TAGLIB_PATCH_VERSION 0
 #include <string>
 #include <climits>
 
-#ifdef __APPLE__
-#  include <libkern/OSAtomic.h>
-#  define TAGLIB_ATOMIC_MAC
-#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-#  if !defined(NOMINMAX)
-#    define NOMINMAX
-#  endif
-#  include <windows.h>
-#  define TAGLIB_ATOMIC_WIN
-#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401)    \
-      && (defined(__i386__) || defined(__i486__) || defined(__i586__) || \
-          defined(__i686__) || defined(__x86_64) || defined(__ia64)) \
-      && !defined(__INTEL_COMPILER)
-#  define TAGLIB_ATOMIC_GCC
-#elif defined(__ia64) && defined(__INTEL_COMPILER)
-#  include <ia64intrin.h>
-#  define TAGLIB_ATOMIC_GCC
+// Check the widths of integral types.
+
+#if SIZEOF_SHORT != 2
+# error TagLib requires that short is 16-bit wide.
 #endif
 
-// Check the widths of integral types.
+#if SIZEOF_INT != 4
+# error TagLib requires that int is 32-bit wide.
+#endif
+
+#if SIZEOF_LONGLONG != 8
+# error TagLib requires that long long is 64-bit wide.
+#endif
+
+#if SIZEOF_WCHAR_T < 2
+# error TagLib requires that wchar_t is sufficient to store a UTF-16 char.
+#endif
+
+// Atomic increment/decrement operations
+
+#if defined(HAVE_STD_ATOMIC)
+# include <atomic>
+#elif defined(HAVE_BOOST_ATOMIC)
+# include <boost/atomic.hpp>
+#elif defined(HAVE_MAC_ATOMIC)
+# include <libkern/OSAtomic.h>
+#elif defined(HAVE_WIN_ATOMIC)
+# include <windows.h>
+#elif defined(HAVE_IA64_ATOMIC)
+# include <ia64intrin.h>
+#endif
+
+#if defined(HAVE_STD_ATOMIC)
+# define TAGLIB_ATOMIC_INT std::atomic<unsigned int>
+# define TAGLIB_ATOMIC_INC(x) x.fetch_add(1)
+# define TAGLIB_ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
+#elif defined(HAVE_BOOST_ATOMIC)
+# define TAGLIB_ATOMIC_INT boost::atomic<unsigned int>
+# define TAGLIB_ATOMIC_INC(x) x.fetch_add(1)
+# define TAGLIB_ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
+#elif defined(HAVE_GCC_ATOMIC)
+# define TAGLIB_ATOMIC_INT volatile int
+# define TAGLIB_ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
+# define TAGLIB_ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
+#elif defined(HAVE_MAC_ATOMIC)
+# define TAGLIB_ATOMIC_INT volatile int32_t
+# define TAGLIB_ATOMIC_INC(x) OSAtomicIncrement32Barrier(&x)
+# define TAGLIB_ATOMIC_DEC(x) OSAtomicDecrement32Barrier(&x)
+#elif defined(HAVE_IA64_ATOMIC)
+# define TAGLIB_ATOMIC_INT volatile int
+# define TAGLIB_ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
+# define TAGLIB_ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
+#else
+# define TAGLIB_ATOMIC_INT volatile int
+# define TAGLIB_ATOMIC_INC(x) (++x)
+# define TAGLIB_ATOMIC_DEC(x) (--x)
+#endif
 
-#if UCHAR_MAX != 255U
-# error TagLib assumes that char is 8-bit wide.
+// Optimized byte swap functions.
+
+#if defined(HAVE_MSC_BYTESWAP)
+# include <stdlib.h>
+#elif defined(HAVE_GLIBC_BYTESWAP)
+# include <byteswap.h>
+#elif defined(HAVE_MAC_BYTESWAP)
+# include <libkern/OSByteOrder.h>
+#elif defined(HAVE_OPENBSD_BYTESWAP)
+# include <sys/endian.h>
 #endif
 
-#if USHRT_MAX != 65535U
-# error TagLib assumes that short is 16-bit wide.
+#if defined(HAVE_GCC_BYTESWAP16)
+# define TAGLIB_BYTESWAP_16(x) __builtin_bswap16(x)
+#elif defined(HAVE_MSC_BYTESWAP)
+# define TAGLIB_BYTESWAP_16(x) _byteswap_ushort(x)
+#elif defined(HAVE_GLIBC_BYTESWAP)
+# define TAGLIB_BYTESWAP_16(x) __bswap_16(x)
+#elif defined(HAVE_MAC_BYTESWAP)
+# define TAGLIB_BYTESWAP_16(x) OSSwapInt16(x)
+#elif defined(HAVE_OPENBSD_BYTESWAP)
+# define TAGLIB_BYTESWAP_16(x) swap16(x)
 #endif
 
-#if UINT_MAX != 4294967295U
-# error TagLib assumes that int is 32-bit wide.
+#if defined(HAVE_GCC_BYTESWAP32)
+# define TAGLIB_BYTESWAP_32(x) __builtin_bswap32(x)
+#elif defined(HAVE_MSC_BYTESWAP)
+# define TAGLIB_BYTESWAP_32(x) _byteswap_ulong(x)
+#elif defined(HAVE_GLIBC_BYTESWAP)
+# define TAGLIB_BYTESWAP_32(x) __bswap_32(x)
+#elif defined(HAVE_MAC_BYTESWAP)
+# define TAGLIB_BYTESWAP_32(x) OSSwapInt32(x)
+#elif defined(HAVE_OPENBSD_BYTESWAP)
+# define TAGLIB_BYTESWAP_32(x) swap32(x)
 #endif
 
-#if !defined(ULLONG_MAX) && !defined(ULONGLONG_MAX) && !defined(ULONG_LONG_MAX)
-# error TagLib assumes that long long is 64-bit wide.
-#elif defined(ULLONG_MAX) && ULLONG_MAX != 18446744073709551615ULL
-# error TagLib assumes that long long is 64-bit wide.
-#elif defined(ULONGLONG_MAX) && ULONGLONG_MAX != 18446744073709551615ULL
-# error TagLib assumes that long long is 64-bit wide.
-#elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX != 18446744073709551615ULL
-# error TagLib assumes that long long is 64-bit wide.
+#if defined(HAVE_GCC_BYTESWAP64)
+# define TAGLIB_BYTESWAP_64(x) __builtin_bswap64(x)
+#elif defined(HAVE_MSC_BYTESWAP)
+# define TAGLIB_BYTESWAP_64(x) _byteswap_uint64(x)
+#elif defined(HAVE_GLIBC_BYTESWAP)
+# define TAGLIB_BYTESWAP_64(x) __bswap_64(x)
+#elif defined(HAVE_MAC_BYTESWAP)
+# define TAGLIB_BYTESWAP_64(x) OSSwapInt64(x)
+#elif defined(HAVE_OPENBSD_BYTESWAP)
+# define TAGLIB_BYTESWAP_64(x) swap64(x)
 #endif
 
 //! A namespace for all TagLib related classes and functions
@@ -115,7 +180,11 @@ namespace TagLib {
    * Unfortunately std::wstring isn't defined on some systems, (i.e. GCC < 3)
    * so I'm providing something here that should be constant.
    */
+#ifdef HAVE_STD_WSTRING
+  typedef std::wstring wstring;
+#else
   typedef std::basic_string<wchar> wstring;
+#endif
 
 #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
   /*!
@@ -130,32 +199,12 @@ namespace TagLib {
   public:
     RefCounter() : refCount(1) {}
 
-#ifdef TAGLIB_ATOMIC_MAC
-    void ref() { OSAtomicIncrement32Barrier(const_cast<int32_t*>(&refCount)); }
-    bool deref() { return ! OSAtomicDecrement32Barrier(const_cast<int32_t*>(&refCount)); }
-    int32_t count() { return refCount; }
-  private:
-    volatile int32_t refCount;
-#elif defined(TAGLIB_ATOMIC_WIN)
-    void ref() { InterlockedIncrement(&refCount); }
-    bool deref() { return ! InterlockedDecrement(&refCount); }
-    long count() { return refCount; }
-  private:
-    volatile long refCount;
-#elif defined(TAGLIB_ATOMIC_GCC)
-    void ref() { __sync_add_and_fetch(&refCount, 1); }
-    bool deref() { return ! __sync_sub_and_fetch(&refCount, 1); }
+    void ref() { TAGLIB_ATOMIC_INC(refCount); }
+    bool deref() { return (TAGLIB_ATOMIC_DEC(refCount) == 0); }
     int count() { return refCount; }
-  private:
-    volatile int refCount;
-#else
-    void ref() { refCount++; }
-    bool deref() { return ! --refCount; }
-    int count() { return refCount; }
-  private:
-    uint refCount;
-#endif
 
+  private:
+    TAGLIB_ATOMIC_INT refCount;
   };
 
 #endif // DO_NOT_DOCUMENT
diff --git a/taglib/toolkit/tbyteswap.cpp b/taglib/toolkit/tbyteswap.cpp
deleted file mode 100644 (file)
index cee2772..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/***************************************************************************
-    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 "taglib.h"
-#include "tbyteswap.h"
-
-// Determines if compiler intrinsic functions are available.
-
-// MSVC: Intrinsic _byteswap_* functions.
-#if defined(_MSC_VER) && _MSC_VER >= 1400
-# include <stdlib.h>
-# define TAGLIB_BYTESWAP_MSC
-
-// GCC 4.8 or above: __builtin_bswap16(), 32 and 64.
-#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
-# define TAGLIB_BYTESWAP_GCC 2
-
-// GCC 4.3 or above: __builtin_bswap16 is missing.
-#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
-# define TAGLIB_BYTESWAP_GCC 1
-
-#endif
-
-// Determines if platform or library specific functions are available.
-
-#if defined(__APPLE__)
-#   include <libkern/OSByteOrder.h>
-#   define TAGLIB_BYTESWAP_MAC
-
-#elif defined(__OpenBSD__)
-#   include <sys/endian.h>
-#   define TAGLIB_BYTESWAP_OPENBSD
-
-#elif defined(__GLIBC__)
-#   include <byteswap.h>
-#   define TAGLIB_BYTESWAP_GLIBC
-
-#endif
-
-// Determines CPU byte order at compile time rather than run time if possible.
-
-#if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) \
-  || (defined(__GNUC__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) \
-  || (defined(__clang__) && defined(__LITTLE_ENDIAN__))
-# define TAGLIB_LITTLE_ENDIAN
-
-#elif (defined(__GNUC__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) \
-  || (defined(__clang__) && defined(__BIG_ENDIAN__))
-# define TAGLIB_BIG_ENDIAN
-
-#else
-
-namespace {
-  bool isLittleEndian()
-  {
-    TagLib::ushort x = 1;
-    return (*reinterpret_cast<TagLib::uchar*>(&x) == 1);
-  }
-}
-
-#endif
-
-namespace TagLib 
-{
-  ushort byteSwap16(ushort x)
-  {
-#if defined(TAGLIB_BYTESWAP_MSC)
-
-    return _byteswap_ushort(x);
-
-#elif defined(TAGLIB_BYTESWAP_GCC) && TAGLIB_BYTESWAP_GCC == 2
-
-    return __builtin_bswap16(x);
-
-#elif defined(TAGLIB_BYTESWAP_MAC)
-
-    return OSSwapInt16(x);
-
-#elif defined(TAGLIB_BYTESWAP_OPENBSD)
-
-    return swap16(x);
-
-#elif defined(TAGLIB_BYTESWAP_GLIBC)
-
-    return __bswap_16(x);
-
-#else
-
-    return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
-
-#endif
-  }
-
-  uint byteSwap32(uint x)
-  {
-#if defined(TAGLIB_BYTESWAP_MSC)
-
-    return _byteswap_ulong(x);
-
-#elif defined(TAGLIB_BYTESWAP_GCC) 
-
-    return __builtin_bswap32(x);
-
-#elif defined(TAGLIB_BYTESWAP_MAC)
-
-    return OSSwapInt32(x);
-
-#elif defined(TAGLIB_BYTESWAP_OPENBSD)
-
-    return swap32(x);
-
-#elif defined(TAGLIB_BYTESWAP_GLIBC)
-
-    return __bswap_32(x);
-
-#else
-
-    return ((x & 0xff000000) >> 24) 
-      | ((x & 0x00ff0000) >>  8)
-      | ((x & 0x0000ff00) <<  8) 
-      | ((x & 0x000000ff) << 24);
-
-#endif
-  }
-
-  ulonglong byteSwap64(ulonglong x)
-  {
-#if defined(TAGLIB_BYTESWAP_MSC)
-
-    return _byteswap_uint64(x);
-
-#elif defined(TAGLIB_BYTESWAP_GCC) 
-
-    return __builtin_bswap64(x);
-
-#elif defined(TAGLIB_BYTESWAP_MAC)
-
-    return OSSwapInt64(x);
-
-#elif defined(TAGLIB_BYTESWAP_OPENBSD)
-
-    return swap64(x);
-
-#elif defined(TAGLIB_BYTESWAP_GLIBC)
-
-    return __bswap_64(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
-  }
-
-#if defined(TAGLIB_LITTLE_ENDIAN)
-
-  const bool isLittleEndianSystem = true;
-
-#elif defined(TAGLIB_BIG_ENDIAN)
-
-  const bool isLittleEndianSystem = false;
-
-#else
-
-  const bool isLittleEndianSystem = isLittleEndian();
-
-#endif
-}
diff --git a/taglib/toolkit/tbyteswap.h b/taglib/toolkit/tbyteswap.h
deleted file mode 100644 (file)
index 012a317..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/***************************************************************************
-    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_BYTESWAP_H
-#define TAGLIB_BYTESWAP_H
-
-namespace TagLib 
-{
-  // Cross-platform byte order conversion functions.
-
-  /*!
-   * Converts the byte order of \a x as a 16-bit unsigned integer.
-   */
-  ushort byteSwap16(ushort x);
-
-  /*!
-   * Converts the byte order of \a x as a 32-bit unsigned integer.
-   */
-  uint byteSwap32(uint x);
-
-  /*!
-   * Converts the byte order of \a x as a 64-bit unsigned integer.
-   */
-  ulonglong byteSwap64(ulonglong x);
-
-  /*!
-   * Indicates the system byte order.
-   * \a true if little endian, \a false if big endian.
-   */
-  extern const bool isLittleEndianSystem;
-}
-
-#endif
index fafaf68fcc1c49d9e266d99460c222055f15a8a8..a4b12672ae4ee36eaa48434f7d271e5852946b08 100644 (file)
@@ -30,7 +30,6 @@
 #include <tdebug.h>
 
 #include "tbytevector.h"
-#include "tbyteswap.h"
 
 // This is a bit ugly to keep writing over and over again.
 
@@ -186,19 +185,53 @@ T byteSwap(T x)
 template <>
 ushort byteSwap<ushort>(ushort x)
 {
-  return byteSwap16(x);
+#ifdef TAGLIB_BYTESWAP_16
+
+  return TAGLIB_BYTESWAP_16(x);
+
+#else
+
+  return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
+
+#endif
 }
 
 template <>
 uint byteSwap<uint>(uint x)
 {
-  return byteSwap32(x);
+#ifdef TAGLIB_BYTESWAP_32
+
+  return TAGLIB_BYTESWAP_32(x);
+
+#else
+
+  return ((x & 0xff000000u) >> 24) 
+    | ((x & 0x00ff0000u) >>  8) 
+    | ((x & 0x0000ff00u) <<  8)
+    | ((x & 0x000000ffu) << 24);
+
+#endif
 }
 
 template <>
 ulonglong byteSwap<ulonglong>(ulonglong x)
 {
-  return byteSwap64(x);
+#ifdef TAGLIB_BYTESWAP_64
+
+  return TAGLIB_BYTESWAP_64(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
 }
 
 template <class T>
@@ -213,7 +246,12 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
   T tmp;
   ::memcpy(&tmp, v.data() + offset, sizeof(T));
 
-  if(isLittleEndianSystem == mostSignificantByteFirst)
+#ifdef TAGLIB_LITTLE_ENDIAN
+  const bool swap = mostSignificantByteFirst;
+#else
+  const bool swap != mostSignificantByteFirst;
+#endif
+  if(swap)
     return byteSwap<T>(tmp);
   else
     return tmp;
@@ -241,7 +279,12 @@ ByteVector fromNumber(T value, bool mostSignificantByteFirst)
 {
   const size_t size = sizeof(T);
 
-  if(isLittleEndianSystem == mostSignificantByteFirst)
+#ifdef TAGLIB_LITTLE_ENDIAN
+  const bool swap = mostSignificantByteFirst;
+#else
+  const bool swap != mostSignificantByteFirst;
+#endif
+ if(swap)
     value = byteSwap<T>(value);
 
   return ByteVector(reinterpret_cast<const char *>(&value), size);
index 22590c898fc6d5bd092528fb5ce701fea2a59d2d..72f4a24a804659eaaabb9b886fc89e0982a5e8b0 100644 (file)
 
 // This class assumes that std::basic_string<T> has a contiguous and null-terminated buffer.
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
 #include "tstring.h"
 #include "tdebug.h"
 #include "tstringlist.h"
-#include "tbyteswap.h"
 
 #include <iostream>
 #include <string.h>
 
-#ifdef HAVE_CODECVT
+#ifdef HAVE_STD_CODECVT
 # include <codecvt>
-namespace {
-  typedef std::codecvt_utf8_utf16<wchar_t> utf8_utf16_t;
-}
 #else
 # include "unicode.h"
 #endif
 
-namespace {
+namespace 
+{
+  inline TagLib::ushort byteSwap(TagLib::ushort x)
+  {
+#ifdef TAGLIB_BYTESWAP_16
+
+    return TAGLIB_BYTESWAP_16(x);
+
+#else
+
+    return((x >> 8) & 0xff) | ((x & 0xff) << 8);
+
+#endif
+  }
 
   inline unsigned short combine(unsigned char c1, unsigned char c2)
   {
     return (c1 << 8) | c2;
   }
+
+  void UTF16toUTF8(const wchar_t *src, size_t srcLength, char *dst, size_t dstLength)
+  {
+#ifdef HAVE_STD_CODECVT
+
+    typedef std::codecvt_utf8_utf16<wchar_t> utf8_utf16_t;
+
+    using namespace TagLib;
+
+    const wchar_t *srcBegin = src;
+    const wchar_t *srcEnd   = srcBegin + srcLength;
+
+    char *dstBegin = dst;
+    char *dstEnd   = dstBegin + dstLength;
+
+    std::mbstate_t st = 0;
+    const wchar_t *source;
+    char *target;
+    std::codecvt_base::result result = utf8_utf16_t().out(
+      st, srcBegin, srcEnd, source, dstBegin, dstEnd, target);
+
+    if(result != utf8_utf16_t::ok) {
+      debug("String::copyFromUTF8() - Unicode conversion error.");
+    }
+
+#else
+
+    using namespace Unicode;
+    using namespace TagLib;
+
+    const Unicode::UTF16 *srcBegin = src;
+    const Unicode::UTF16 *srcEnd   = srcBegin + srcLength;
+
+    Unicode::UTF8 *dstBegin = reinterpret_cast<Unicode::UTF8*>(dst);
+    Unicode::UTF8 *dstEnd   = dstBegin + dstLength;
+
+    Unicode::ConversionResult result = Unicode::ConvertUTF16toUTF8(
+      &srcBegin, srcEnd, &dstBegin, dstEnd, Unicode::lenientConversion);
+
+    if(result != Unicode::conversionOK) {
+      debug("String::to8Bit() - Unicode conversion error.");
+    }
+
+#endif
+  }
+
+  void UTF8toUTF16(const char *src, size_t srcLength, wchar_t *dst, size_t dstLength)
+  {
+#ifdef HAVE_STD_CODECVT
+
+    typedef std::codecvt_utf8_utf16<wchar_t> utf8_utf16_t;
+
+    using namespace TagLib;
+
+    const char *srcBegin = src;
+    const char *srcEnd   = srcBegin + srcLength;
+
+    wchar_t *dstBegin = dst;
+    wchar_t *dstEnd   = dstBegin + dstLength;
+
+    std::mbstate_t st = 0;
+    const char *source;
+    wchar_t *target;
+    std::codecvt_base::result result = utf8_utf16_t().in(
+      st, srcBegin, srcEnd, source, dstBegin, dstEnd, target);
+
+    if(result != utf8_utf16_t::ok) {
+      debug("String::copyFromUTF8() - Unicode conversion error.");
+    }
+
+#else
+
+    using namespace Unicode;
+    using namespace TagLib;
+
+    const Unicode::UTF8 *srcBegin = reinterpret_cast<const Unicode::UTF8*>(src);
+    const Unicode::UTF8 *srcEnd   = srcBegin + srcLength;
+
+    Unicode::UTF16 *dstBegin = dst;
+    Unicode::UTF16 *dstEnd   = dstBegin + dstLength;
+
+    Unicode::ConversionResult result = Unicode::ConvertUTF8toUTF16(
+      &srcBegin, srcEnd, &dstBegin, dstEnd, Unicode::lenientConversion);
+
+    if(result != Unicode::conversionOK) {
+      debug("String::copyFromUTF8() - Unicode conversion error.");
+    }
+
+#endif 
+  }
 }
 
 namespace TagLib {
@@ -202,34 +297,7 @@ std::string String::to8Bit(bool unicode) const
   else {
     s.resize(d->data.size() * 4 + 1);
 
-#ifdef HAVE_CODECVT
-
-    std::mbstate_t st = 0;
-    const wchar_t *source;
-    char *target;
-    std::codecvt_base::result result = utf8_utf16_t().out(
-      st, &d->data[0], &d->data[d->data.size()], source, &s[0], &s[s.size()], target);
-
-    if(result != utf8_utf16_t::ok) {
-      debug("String::copyFromUTF8() - Unicode conversion error.");
-    }
-
-#else
-
-    const Unicode::UTF16 *source = &d->data[0];
-    Unicode::UTF8 *target = reinterpret_cast<Unicode::UTF8*>(&s[0]);
-
-    Unicode::ConversionResult result = Unicode::ConvertUTF16toUTF8(
-      &source, source + d->data.size(),
-      &target, target + s.size(),
-      Unicode::lenientConversion);
-
-    if(result != Unicode::conversionOK) {
-      debug("String::to8Bit() - Unicode conversion error.");
-    }
-
-#endif
-
+    UTF16toUTF8(&d->data[0], d->data.size(), &s[0], s.size());
     s.resize(::strlen(s.c_str()));
   }
 
@@ -371,34 +439,7 @@ ByteVector String::data(Type t) const
     {
       ByteVector v(size() * 4 + 1, 0);
 
-#ifdef HAVE_CODECVT
-
-      std::mbstate_t st = 0;
-      const wchar_t *source;
-      char *target;
-      std::codecvt_base::result result = utf8_utf16_t().out(
-        st, &d->data[0], &d->data[d->data.size()], source, v.data(), v.data() + v.size(), target);
-
-      if(result != utf8_utf16_t::ok) {
-        debug("String::data() - Unicode conversion error.");
-      }
-
-#else
-
-      const Unicode::UTF16 *source = &d->data[0];
-      Unicode::UTF8 *target = reinterpret_cast<Unicode::UTF8*>(v.data());
-
-      Unicode::ConversionResult result = Unicode::ConvertUTF16toUTF8(
-        &source, source + d->data.size(),
-        &target, target + v.size(),
-        Unicode::lenientConversion);
-
-      if(result != Unicode::conversionOK) {
-        debug("String::data() - Unicode conversion error.");
-      }
-
-#endif
-
+      UTF16toUTF8(&d->data[0], d->data.size(), v.data(), v.size());
       v.resize(::strlen(v.data()));
 
       return v;
@@ -730,34 +771,7 @@ void String::copyFromUTF8(const char *s, size_t length)
 {
   d->data.resize(length);
 
-#ifdef HAVE_CODECVT
-
-  std::mbstate_t st = 0;
-  const char *source;
-  wchar_t *target;
-  std::codecvt_base::result result = utf8_utf16_t().in(
-    st, s, s + length, source, &d->data[0], &d->data[d->data.size()], target);
-
-  if(result != utf8_utf16_t::ok) {
-    debug("String::copyFromUTF8() - Unicode conversion error.");
-  }
-
-#else
-
-  const Unicode::UTF8 *source = reinterpret_cast<const Unicode::UTF8 *>(s);
-  Unicode::UTF16 *target = &d->data[0];
-
-  Unicode::ConversionResult result = Unicode::ConvertUTF8toUTF16(
-    &source, source + length,
-    &target, target + length,
-    Unicode::lenientConversion);
-
-  if(result != Unicode::conversionOK) {
-    debug("String::copyFromUTF8() - Unicode conversion error.");
-  }
-
-#endif
-
+  UTF8toUTF16(s, length, &d->data[0], d->data.size());
   d->data.resize(::wcslen(d->data.c_str()));
 }
 
@@ -785,7 +799,7 @@ void String::copyFromUTF16(const wchar_t *s, size_t length, Type t)
 
   if(swap) {
     for(size_t i = 0; i < length; ++i)
-      d->data[i] = byteSwap16(static_cast<ushort>(s[i]));
+      d->data[i] = byteSwap(static_cast<ushort>(s[i]));
   }
 }
 
@@ -836,7 +850,16 @@ void String::copyFromUTF16(const char *s, size_t length, Type t)
 #endif
 }
 
-const String::Type String::WCharByteOrder = isLittleEndianSystem ? String::UTF16LE : String::UTF16BE;
+#ifdef TAGLIB_LITTLE_ENDIAN
+
+const String::Type String::WCharByteOrder = String::UTF16LE;
+
+#else
+
+const String::Type String::WCharByteOrder = String::UTF16BE;
+
+#endif
+
 }
 
 ////////////////////////////////////////////////////////////////////////////////