From 4fc2a3bdd80c36e74b320097b9347ebbc74fed0c Mon Sep 17 00:00:00 2001 From: Tsuda kageyu Date: Thu, 18 Apr 2013 03:23:12 +0900 Subject: [PATCH] Detect C++11 features automatically --- CMakeLists.txt | 5 -- ConfigureChecks.cmake | 50 ++++++++++++++++++-- config-taglib.h.cmake | 14 ++++++ taglib/asf/asfattribute.cpp | 2 +- taglib/asf/asfattribute.h | 4 +- taglib/asf/asfpicture.cpp | 4 +- taglib/asf/asfpicture.h | 8 ++-- taglib/fileref.cpp | 4 +- taglib/fileref.h | 8 ++-- taglib/mp4/mp4coverart.cpp | 2 +- taglib/mp4/mp4coverart.h | 2 +- taglib/mp4/mp4item.cpp | 4 +- taglib/mp4/mp4item.h | 4 +- taglib/mpeg/mpegheader.cpp | 4 +- taglib/mpeg/mpegheader.h | 8 ++-- taglib/toolkit/tbytevector.cpp | 4 +- taglib/toolkit/tbytevector.h | 8 ++-- taglib/toolkit/tbytevectorlist.cpp | 4 +- taglib/toolkit/tbytevectorlist.h | 8 ++-- taglib/toolkit/tlist.h | 20 ++++---- taglib/toolkit/tlist.tcc | 12 ++--- taglib/toolkit/tmap.h | 12 ++--- taglib/toolkit/tmap.tcc | 10 ++-- taglib/toolkit/trefcountptr.h | 75 +++++++++++++++++++++++------- taglib/toolkit/tstring.cpp | 31 ++++++------ taglib/toolkit/tstring.h | 12 ++--- taglib/toolkit/tstringlist.cpp | 6 +-- taglib/toolkit/tstringlist.h | 14 +++--- 28 files changed, 214 insertions(+), 125 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e56978f5..1f29e463 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,11 +11,6 @@ else() endif() OPTION(ENABLE_STATIC_RUNTIME "Visual Studio, link with runtime statically" OFF) -option(ENABLE_CXX11 "Enable C++11 features" OFF) -if(ENABLE_CXX11) - add_definitions(-DTAGLIB_USE_CXX11) -endif() - option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF) if(VISIBILITY_HIDDEN) add_definitions (-fvisibility=hidden) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index e4a6d1fa..b7bda179 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -9,15 +9,57 @@ include(CheckCXXSourceCompiles) # check for libz using the cmake supplied FindZLIB.cmake find_package(ZLIB) if(ZLIB_FOUND) - set(HAVE_ZLIB 1) + set(HAVE_ZLIB 1) else() - set(HAVE_ZLIB 0) + set(HAVE_ZLIB 0) endif() +# Determine whether or not your compiler supports move semantics. +check_cxx_source_compiles(" + #ifdef __clang__ + # pragma clang diagnostic error \"-Wc++11-extensions\" + #endif + #include + int func(int &&x) { return x - 1; } + int main() { return func(std::move(1)); } +" SUPPORT_MOVE_SEMANTICS) + +# Determine whether or not your compiler supports template alias. +check_cxx_source_compiles(" + #ifdef __clang__ + # pragma clang diagnostic error \"-Wc++11-extensions\" + #endif + #include + template using myVector = std::vector; + int main() { return 0; } +" SUPPORT_TEMPLATE_ALIAS) + +# Determine where shared_ptr is defined regardless of C++11 support. +check_cxx_source_compiles(" + #include + int main() { std::tr1::shared_ptr x; return 0; } +" HAVE_STD_SHARED_PTR) + +check_cxx_source_compiles(" + #include + int main() { std::tr1::shared_ptr x; return 0; } +" HAVE_TR1_SHARED_PTR) + +check_cxx_source_compiles(" + #include + int main() { boost::shared_ptr x; return 0; } +" HAVE_BOOST_SHARED_PTR) + +# Determine whether your compiler supports codecvt header. +check_cxx_source_compiles(" + #include + int main() { std::codecvt_utf8_utf16 x; return 0; } +" HAVE_CODECVT) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) find_package(CppUnit) if(NOT CppUnit_FOUND AND BUILD_TESTS) - message(STATUS "CppUnit not found, disabling tests.") - set(BUILD_TESTS OFF) + message(STATUS "CppUnit not found, disabling tests.") + set(BUILD_TESTS OFF) endif() diff --git a/config-taglib.h.cmake b/config-taglib.h.cmake index 9c2f487d..e57ff050 100644 --- a/config-taglib.h.cmake +++ b/config-taglib.h.cmake @@ -3,6 +3,20 @@ /* Define if you have libz */ #cmakedefine HAVE_ZLIB 1 +/* Defined if your compiler supports the move semantics */ +#cmakedefine SUPPORT_MOVE_SEMANTICS 1 + +/* Defined if your compiler supports the template alias */ +#cmakedefine SUPPORT_TEMPLATE_ALIAS 1 + +/* Defined if your compiler supports shared_ptr */ +#cmakedefine HAVE_STD_SHARED_PTR 1 +#cmakedefine HAVE_TR1_SHARED_PTR 1 +#cmakedefine HAVE_BOOST_SHARED_PTR 1 + +/* Defined if your compiler has header */ +#cmakedefine HAVE_CODECVT 1 + #cmakedefine NO_ITUNES_HACKS 1 #cmakedefine WITH_ASF 1 #cmakedefine WITH_MP4 1 diff --git a/taglib/asf/asfattribute.cpp b/taglib/asf/asfattribute.cpp index b4195133..7a512a18 100644 --- a/taglib/asf/asfattribute.cpp +++ b/taglib/asf/asfattribute.cpp @@ -129,7 +129,7 @@ ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ASF::Attribute &ASF::Attribute::operator=(ASF::Attribute &&other) { diff --git a/taglib/asf/asfattribute.h b/taglib/asf/asfattribute.h index d9ea231a..93e8c2e1 100644 --- a/taglib/asf/asfattribute.h +++ b/taglib/asf/asfattribute.h @@ -115,12 +115,12 @@ namespace TagLib */ ASF::Attribute &operator=(const Attribute &other); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves the contents of \a other into this item. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ ASF::Attribute &operator=(Attribute &&other); diff --git a/taglib/asf/asfpicture.cpp b/taglib/asf/asfpicture.cpp index 6f94e29d..a2b3d0ac 100644 --- a/taglib/asf/asfpicture.cpp +++ b/taglib/asf/asfpicture.cpp @@ -60,7 +60,7 @@ ASF::Picture::Picture(const Picture& other) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ASF::Picture::Picture(Picture &&other) : d(std::move(other.d)) @@ -131,7 +131,7 @@ ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ASF::Picture& ASF::Picture::operator=(ASF::Picture &&other) { diff --git a/taglib/asf/asfpicture.h b/taglib/asf/asfpicture.h index 84fe1a37..e2279462 100644 --- a/taglib/asf/asfpicture.h +++ b/taglib/asf/asfpicture.h @@ -107,12 +107,12 @@ namespace TagLib */ Picture(const Picture& other); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Constructs an picture equivalent to \a other. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Picture(Picture &&other); @@ -128,12 +128,12 @@ namespace TagLib */ Picture& operator=(const Picture& other); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves the contents of \a other into this picture. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Picture& operator=(Picture &&other); diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index c188145b..85081c46 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -98,7 +98,7 @@ FileRef::FileRef(const FileRef &ref) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS FileRef::FileRef(FileRef &&ref) : d(std::move(ref.d)) @@ -195,7 +195,7 @@ FileRef &FileRef::operator=(const FileRef &ref) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS FileRef &FileRef::operator=(FileRef &&ref) { diff --git a/taglib/fileref.h b/taglib/fileref.h index a2bd491f..c359ef22 100644 --- a/taglib/fileref.h +++ b/taglib/fileref.h @@ -139,12 +139,12 @@ namespace TagLib { */ FileRef(const FileRef &ref); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Move \a ref into the FileRef. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ FileRef(FileRef &&ref); @@ -238,12 +238,12 @@ namespace TagLib { */ FileRef &operator=(const FileRef &ref); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a ref into this FileRef. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ FileRef &operator=(FileRef &&ref); diff --git a/taglib/mp4/mp4coverart.cpp b/taglib/mp4/mp4coverart.cpp index 7ec52ed2..6d7383f0 100644 --- a/taglib/mp4/mp4coverart.cpp +++ b/taglib/mp4/mp4coverart.cpp @@ -60,7 +60,7 @@ MP4::CoverArt & return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS MP4::CoverArt & MP4::CoverArt::operator=(CoverArt &&item) diff --git a/taglib/mp4/mp4coverart.h b/taglib/mp4/mp4coverart.h index b5424a0c..a34e715e 100644 --- a/taglib/mp4/mp4coverart.h +++ b/taglib/mp4/mp4coverart.h @@ -54,7 +54,7 @@ namespace TagLib { CoverArt(const CoverArt &item); CoverArt &operator=(const CoverArt &item); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS CoverArt &operator=(CoverArt &&item); #endif diff --git a/taglib/mp4/mp4item.cpp b/taglib/mp4/mp4item.cpp index 9e7b0554..1e03ae4e 100644 --- a/taglib/mp4/mp4item.cpp +++ b/taglib/mp4/mp4item.cpp @@ -72,7 +72,7 @@ MP4::Item::Item(const Item &item) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS MP4::Item::Item(Item &&item) : d(std::move(item.d)) @@ -88,7 +88,7 @@ MP4::Item & return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS MP4::Item & MP4::Item::operator=(Item &&item) diff --git a/taglib/mp4/mp4item.h b/taglib/mp4/mp4item.h index 73ee2f01..44fae301 100644 --- a/taglib/mp4/mp4item.h +++ b/taglib/mp4/mp4item.h @@ -56,12 +56,12 @@ namespace TagLib { Item(); Item(const Item &item); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS Item(Item &&item); #endif Item &operator=(const Item &item); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS Item &operator=(Item &&item); #endif ~Item(); diff --git a/taglib/mpeg/mpegheader.cpp b/taglib/mpeg/mpegheader.cpp index 875de909..ce58cfd1 100644 --- a/taglib/mpeg/mpegheader.cpp +++ b/taglib/mpeg/mpegheader.cpp @@ -78,7 +78,7 @@ MPEG::Header::Header(const Header &h) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS MPEG::Header::Header(Header &&h) : d(std::move(h.d)) @@ -157,7 +157,7 @@ MPEG::Header &MPEG::Header::operator=(const Header &h) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS MPEG::Header &MPEG::Header::operator=(Header &&h) { diff --git a/taglib/mpeg/mpegheader.h b/taglib/mpeg/mpegheader.h index 0f4d8855..cdc8669d 100644 --- a/taglib/mpeg/mpegheader.h +++ b/taglib/mpeg/mpegheader.h @@ -57,12 +57,12 @@ namespace TagLib { */ Header(const Header &h); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a h into this Header. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Header(Header &&h); @@ -166,12 +166,12 @@ namespace TagLib { */ Header &operator=(const Header &h); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a h into this Header. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Header &operator=(Header &&h); diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 15876943..38cb97ef 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -380,7 +380,7 @@ ByteVector::ByteVector(const ByteVector &v, size_t offset, size_t length) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ByteVector::ByteVector(ByteVector &&v) : d(std::move(v.d)) @@ -762,7 +762,7 @@ ByteVector &ByteVector::operator=(const ByteVector &v) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ByteVector &ByteVector::operator=(ByteVector &&v) { diff --git a/taglib/toolkit/tbytevector.h b/taglib/toolkit/tbytevector.h index 21f63f33..ec8e7c3f 100644 --- a/taglib/toolkit/tbytevector.h +++ b/taglib/toolkit/tbytevector.h @@ -68,12 +68,12 @@ namespace TagLib { */ ByteVector(const ByteVector &v); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Constructs a byte vector equivalent to \a v. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ ByteVector(ByteVector &&v); @@ -429,12 +429,12 @@ namespace TagLib { */ ByteVector &operator=(const ByteVector &v); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a v into this ByteVector. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ ByteVector &operator=(ByteVector &&v); diff --git a/taglib/toolkit/tbytevectorlist.cpp b/taglib/toolkit/tbytevectorlist.cpp index e5282b84..505c3bf8 100644 --- a/taglib/toolkit/tbytevectorlist.cpp +++ b/taglib/toolkit/tbytevectorlist.cpp @@ -73,7 +73,7 @@ ByteVectorList::ByteVectorList(const ByteVectorList &l) : List(l) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ByteVectorList::ByteVectorList(ByteVectorList &&l) : List(l) { @@ -87,7 +87,7 @@ ByteVectorList &ByteVectorList::operator=(const ByteVectorList &l) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ByteVectorList &ByteVectorList::operator=(ByteVectorList &&l) { diff --git a/taglib/toolkit/tbytevectorlist.h b/taglib/toolkit/tbytevectorlist.h index dc26f269..ce7cc800 100644 --- a/taglib/toolkit/tbytevectorlist.h +++ b/taglib/toolkit/tbytevectorlist.h @@ -54,12 +54,12 @@ namespace TagLib { */ ByteVectorList(const ByteVectorList &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a l into this ByteVectorList. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ ByteVectorList(ByteVectorList &&l); @@ -72,12 +72,12 @@ namespace TagLib { */ ByteVectorList &operator=(const ByteVectorList &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a l into this ByteVectorList. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ ByteVectorList &operator=(ByteVectorList &&l); diff --git a/taglib/toolkit/tlist.h b/taglib/toolkit/tlist.h index a2749215..0948ee70 100644 --- a/taglib/toolkit/tlist.h +++ b/taglib/toolkit/tlist.h @@ -70,12 +70,12 @@ namespace TagLib { */ List(const List &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a l into this List. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ List(List &&l); @@ -135,13 +135,13 @@ namespace TagLib { */ List &append(const List &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Appends \a item to the end of the list and returns a reference to the * list. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ List &append(T &&item); @@ -149,7 +149,7 @@ namespace TagLib { * Appends all of the values in \a l to the end of the list and returns a * reference to the list. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ List &append(List &&l); @@ -167,13 +167,13 @@ namespace TagLib { */ List &prepend(const List &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Prepends \a item to the beginning list and returns a reference to the * list. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ List &prepend(T &&item); @@ -181,7 +181,7 @@ namespace TagLib { * Prepends all of the items in \a l to the beginning list and returns a * reference to the list. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ List &prepend(List &&l); @@ -272,12 +272,12 @@ namespace TagLib { */ List &operator=(const List &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a l into this List. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ List &operator=(List &&l); diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index 83051bec..736351db 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -54,7 +54,7 @@ public: ListPrivate() : ListPrivateBase() {} ListPrivate(const std::list &l) : ListPrivateBase(), list(l) {} -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ListPrivate(std::list &&l) : ListPrivateBase(), list(l) {} @@ -76,7 +76,7 @@ public: ListPrivate() : ListPrivateBase() {} ListPrivate(const std::list &l) : ListPrivateBase(), list(l) {} -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS ListPrivate(std::list &&l) : ListPrivateBase(), list(l) {} @@ -120,7 +120,7 @@ List::List(const List &l) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template List::List(List &&l) @@ -197,7 +197,7 @@ List &List::append(const List &l) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template List &List::append(T &&item) @@ -236,7 +236,7 @@ List &List::prepend(const List &l) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template List &List::prepend(T &&item) @@ -364,7 +364,7 @@ List &List::operator=(const List &l) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template List &List::operator=(List &&l) diff --git a/taglib/toolkit/tmap.h b/taglib/toolkit/tmap.h index 0928cf57..38a23896 100644 --- a/taglib/toolkit/tmap.h +++ b/taglib/toolkit/tmap.h @@ -73,12 +73,12 @@ namespace TagLib { */ Map(const Map &m); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a m into this Map. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Map(Map &&m); @@ -119,13 +119,13 @@ namespace TagLib { */ Map &insert(const Key &key, const T &value); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Inserts \a value under \a key in the map. If a value for \a key already * exists it will be overwritten. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Map &insert(const Key &key, T &&value); @@ -197,12 +197,12 @@ namespace TagLib { */ Map &operator=(const Map &m); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a m into this Map. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ Map &operator=(Map &&m); diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index 480be764..607c1bee 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -40,7 +40,7 @@ public: MapPrivate(const std::map &m) : RefCounter(), map(m) {} -# ifdef TAGLIB_USE_CXX11 +# ifdef SUPPORT_MOVE_SEMANTICS MapPrivate(std::map &&m) : RefCounter(), map(m) {} @@ -56,7 +56,7 @@ public: MapPrivate(const std::map& m) : map(m) {} -# ifdef TAGLIB_USE_CXX11 +# ifdef SUPPORT_MOVE_SEMANTICS MapPrivate(std::map &&m) : map(m) {} @@ -83,7 +83,7 @@ Map::Map(const Map &m) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template TagLib::Map::Map(Map &&m) @@ -132,7 +132,7 @@ Map &Map::insert(const Key &key, const T &value) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template Map &Map::insert(const Key &key, T &&value) @@ -221,7 +221,7 @@ Map &Map::operator=(const Map &m) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS template Map &Map::operator=(Map &&m) diff --git a/taglib/toolkit/trefcountptr.h b/taglib/toolkit/trefcountptr.h index 8abc6720..f74168d8 100644 --- a/taglib/toolkit/trefcountptr.h +++ b/taglib/toolkit/trefcountptr.h @@ -26,13 +26,16 @@ #ifndef TAGLIB_REFCOUNTPTR_H #define TAGLIB_REFCOUNTPTR_H -// TAGLIB_USE_CXX11 determines whether or not to enable C++11 features. +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include "tdebug.h" - -#ifdef TAGLIB_USE_CXX11 +#if defined(HAVE_STD_SHARED_PTR) # include - +#elif defined(HAVE_TR1_SHARED_PTR) +# include +#elif defined(HAVE_BOOST_SHARED_PTR) +# include #else # ifdef __APPLE__ # include @@ -51,7 +54,6 @@ #endif #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class. - /*! * \internal * This is just used as a smart pointer for shared classes in TagLib. @@ -59,18 +61,55 @@ * \warning This is not part of the TagLib public API! */ -#ifdef TAGLIB_USE_CXX11 - - // RefCountPtr is just an alias of std::shared_ptr if C++11 is available. -# define RefCountPtr std::shared_ptr - - // Workaround for the fact that some compilers don't support the template aliases. - -#else - namespace TagLib { - // RefCountPtr mimics std::shared_ptr if C++11 is not available. +#if defined(HAVE_STD_SHARED_PTR) || defined(HAVE_TR1_SHARED_PTR) || defined(HAVE_BOOST_SHARED_PTR) + +# if defined(SUPPORT_TEMPLATE_ALIAS) + + // Defines RefCountPtr as an alias of shared_ptr. + +# if defined(HAVE_STD_SHARED_PTR) || defined(HAVE_TR1_SHARED_PTR) + + template + using RefCountPtr = std::tr1::shared_ptr; + +# else + + template + using RefCountPtr = boost::shared_ptr; + +# endif + +# else + + // Defines RefCountPtr as an derived class of shared_ptr. + +# if defined(HAVE_STD_SHARED_PTR) || defined(HAVE_TR1_SHARED_PTR) + + template + class RefCountPtr : public std::tr1::shared_ptr + { + public: + explicit RefCountPtr(T *p) : std::tr1::shared_ptr(p) {} + }; + +# else + + template + class RefCountPtr : public boost::shared_ptr + { + public: + explicit RefCountPtr(T *p) : boost::shared_ptr(p) {} + }; + +# endif + +# endif + +#else // HAVE_*_SHARED_PTR + + // Implements RefCountPtr if shared_ptr is not available. template class RefCountPtr @@ -249,9 +288,9 @@ namespace TagLib { private: CounterBase *counter; }; -} -#endif // TAGLIB_USE_CXX11 +#endif // HAVE_*_SHARED_PTR +} #endif // DO_NOT_DOCUMENT #endif diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 3130e382..d4e9a233 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -24,7 +24,10 @@ ***************************************************************************/ // This class assumes that std::basic_string has a contiguous and null-terminated buffer. -// + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include "tstring.h" #include "tdebug.h" @@ -33,15 +36,11 @@ #include -// Determine if the compiler supports codecvt. - -#if (defined(_MSC_VER) && _MSC_VER >= 1600) -# define TAGLIB_USE_CODECVT -#endif - -#ifdef TAGLIB_USE_CODECVT +#ifdef HAVE_CODECVT # include - typedef std::codecvt_utf8_utf16 utf8_utf16_t; + namespace { + typedef std::codecvt_utf8_utf16 utf8_utf16_t; + } #else # include "unicode.h" #endif @@ -68,7 +67,7 @@ public: { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS StringPrivate(wstring &&s) : data(s) @@ -105,7 +104,7 @@ String::String(const String &s) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS String::String(String &&s) : d(std::move(s.d)) @@ -216,7 +215,7 @@ std::string String::to8Bit(bool unicode) const else { s.resize(d->data.size() * 4 + 1); -#ifdef TAGLIB_USE_CODECVT +#ifdef HAVE_CODECVT std::mbstate_t st = 0; const wchar_t *source; @@ -387,7 +386,7 @@ ByteVector String::data(Type t) const { ByteVector v(size() * 4 + 1, 0); -#ifdef TAGLIB_USE_CODECVT +#ifdef HAVE_CODECVT std::mbstate_t st = 0; const wchar_t *source; @@ -648,7 +647,7 @@ String &String::operator=(const String &s) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS String &String::operator=(String &&s) { @@ -672,7 +671,7 @@ String &String::operator=(const wstring &s) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS String &String::operator=(wstring &&s) { @@ -758,7 +757,7 @@ void String::copyFromUTF8(const char *s, size_t length) { d->data.resize(length); -#ifdef TAGLIB_USE_CODECVT +#ifdef HAVE_CODECVT std::mbstate_t st = 0; const char *source; diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index 4bd014db..dfde414d 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -119,12 +119,12 @@ namespace TagLib { */ String(const String &s); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Constructs a String equivalent to \a s. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ String(String &&s); @@ -403,12 +403,12 @@ namespace TagLib { */ String &operator=(const String &s); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a s into this String. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ String &operator=(String &&s); @@ -424,12 +424,12 @@ namespace TagLib { */ String &operator=(const wstring &s); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a s into this String. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ String &operator=(wstring &&s); diff --git a/taglib/toolkit/tstringlist.cpp b/taglib/toolkit/tstringlist.cpp index 0220a012..49650f49 100644 --- a/taglib/toolkit/tstringlist.cpp +++ b/taglib/toolkit/tstringlist.cpp @@ -61,7 +61,7 @@ StringList::StringList(const StringList &l) : List(l) { } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS StringList::StringList(StringList &&l) : List(l) { @@ -111,7 +111,7 @@ StringList &StringList::append(const StringList &l) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS StringList &StringList::append(String &&s) { @@ -133,7 +133,7 @@ StringList &StringList::operator=(const StringList &l) return *this; } -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS StringList &StringList::operator=(StringList &&l) { diff --git a/taglib/toolkit/tstringlist.h b/taglib/toolkit/tstringlist.h index 3659efec..75466063 100644 --- a/taglib/toolkit/tstringlist.h +++ b/taglib/toolkit/tstringlist.h @@ -58,12 +58,12 @@ namespace TagLib { */ StringList(const StringList &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Constructs a StringList equivalent to \a l. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ StringList(StringList &&l); @@ -99,13 +99,13 @@ namespace TagLib { */ StringList &append(const StringList &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Appends \a s to the end of the list and returns a reference to the * list. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ StringList &append(String &&s); @@ -113,7 +113,7 @@ namespace TagLib { * Appends all of the values in \a l to the end of the list and returns a * reference to the list. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ StringList &append(StringList &&l); @@ -126,12 +126,12 @@ namespace TagLib { */ StringList &operator=(const StringList &l); -#ifdef TAGLIB_USE_CXX11 +#ifdef SUPPORT_MOVE_SEMANTICS /*! * Moves \a l into this StringList. * - * \note Not available unless TAGLIB_USE_CXX11 macro is defined. + * \note Not available unless SUPPORT_MOVE_SEMANTICS macro is defined. */ StringList &operator=(StringList &&l);