From 66f5f396ffabc65ab0e01b3078fcfa8463bfe2e6 Mon Sep 17 00:00:00 2001 From: Tsuda kageyu Date: Wed, 17 Apr 2013 21:41:23 +0900 Subject: [PATCH] Use shared_ptr if possible regardless of C++11 support --- CMakeLists.txt | 5 ---- ConfigureChecks.cmake | 25 ++++++++++++++++--- config-taglib.h.cmake | 4 +++ taglib/toolkit/trefcountptr.h | 46 ++++++++++++++++++----------------- 4 files changed, 49 insertions(+), 31 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..ec0da6d1 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -9,15 +9,32 @@ 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 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) + 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..8ce6798b 100644 --- a/config-taglib.h.cmake +++ b/config-taglib.h.cmake @@ -3,6 +3,10 @@ /* Define if you have libz */ #cmakedefine HAVE_ZLIB 1 +#cmakedefine HAVE_STD_SHARED_PTR 1 +#cmakedefine HAVE_TR1_SHARED_PTR 1 +#cmakedefine HAVE_BOOST_SHARED_PTR 1 + #cmakedefine NO_ITUNES_HACKS 1 #cmakedefine WITH_ASF 1 #cmakedefine WITH_MP4 1 diff --git a/taglib/toolkit/trefcountptr.h b/taglib/toolkit/trefcountptr.h index fb01de37..492afcd5 100644 --- a/taglib/toolkit/trefcountptr.h +++ b/taglib/toolkit/trefcountptr.h @@ -26,10 +26,31 @@ #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 -#ifdef TAGLIB_USE_CXX11 +#ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class. +/*! + * \internal + * This is just used as a smart pointer for shared classes in TagLib. + * + * \warning This is not part of the TagLib public API! + */ + +// RefCountPtr is just an alias of shared_ptr if it is available. + +#if defined(HAVE_STD_SHARED_PTR) # include +# define RefCountPtr std::tr1::shared_ptr + +#elif defined(HAVE_TR1_SHARED_PTR) +# include +# define RefCountPtr std::tr1::shared_ptr + +#elif defined(HAVE_BOOST_SHARED_PTR) +# include +# define RefCountPtr boost::shared_ptr #else # ifdef __APPLE__ @@ -46,29 +67,10 @@ # include # define TAGLIB_ATOMIC_GCC # endif -#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. - * - * \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. + // RefCountPtr mimics std::shared_ptr if it is not available. template class RefCountPtr