]> granicus.if.org Git - taglib/commitdiff
Use std::shared_ptr<T> if C++11 is available
authorTsuda kageyu <tsuda.kageyu@gmail.com>
Wed, 17 Apr 2013 02:12:42 +0000 (11:12 +0900)
committerTsuda kageyu <tsuda.kageyu@gmail.com>
Wed, 17 Apr 2013 02:12:42 +0000 (11:12 +0900)
CMakeLists.txt
taglib/toolkit/trefcountptr.h

index 1f29e4634a65452b532cbd1f6912e7dfe5ef2707..e56978f52718fd996039e7eb1a26ad6cd1c30382 100755 (executable)
@@ -11,6 +11,11 @@ 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)
index 49e0ee9efd886128b9b01845cb588e1584863fef..eb84e1782205f764f1481c17d4d7d7de37f5119b 100644 (file)
 #ifndef TAGLIB_REFCOUNTPTR_H
 #define TAGLIB_REFCOUNTPTR_H
 
-#include "tdebug.h"
-
-#ifdef __APPLE__
-#  include <libkern/OSAtomic.h>
-#  define TAGLIB_ATOMIC_MAC
-#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-#  define TAGLIB_ATOMIC_WIN
-#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401)    \
+// TAGLIB_USE_CXX11 determines whether or not to enable C++11 features.
+
+#ifdef TAGLIB_USE_CXX11
+# include <memory>
+
+#else
+# ifdef __APPLE__
+#   include <libkern/OSAtomic.h>
+#   define TAGLIB_ATOMIC_MAC
+# elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#   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
+#   define TAGLIB_ATOMIC_GCC
+# elif defined(__ia64) && defined(__INTEL_COMPILER)
+#   include <ia64intrin.h>
+#   define TAGLIB_ATOMIC_GCC
+# endif
 #endif
 
 #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
  * \warning This <b>is not</b> part of the TagLib public API!
  */
 
+#ifdef TAGLIB_USE_CXX11
+
+  // RefCountPtr<T> is just an alias of std::shared_ptr<T> 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<T> mimics std::shared_ptr<T>.
+  // RefCountPtr<T> mimics std::shared_ptr<T> if C++11 is not available.
 
   template<typename T>
   class RefCountPtr
@@ -234,7 +248,8 @@ namespace TagLib {
     counter_base *counter;
   };
 }
+#endif // TAGLIB_USE_CXX11
 
 #endif // DO_NOT_DOCUMENT
 
-#endif
+#endif
\ No newline at end of file