Ticket #9612: 0001-Changes-to-singleton-to-allow-extern-templates-on-si.patch
File 0001-Changes-to-singleton-to-allow-extern-templates-on-si.patch, 5.6 KB (added by , 9 years ago) |
---|
-
new file include/boost/serialization/extern.hpp
From ae8bf9fa9c0c0baf275d68538804be6ac6f7922a Mon Sep 17 00:00:00 2001 From: Brandon Kohn <blkohn@hotmail.com> Date: Sun, 2 Feb 2014 13:58:57 -0500 Subject: [PATCH] Changes to singleton to allow extern templates on singletons. --- include/boost/serialization/extern.hpp | 62 +++++++++++++++++++++++++++++++ include/boost/serialization/singleton.hpp | 16 ++++---- 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 include/boost/serialization/extern.hpp diff --git a/include/boost/serialization/extern.hpp b/include/boost/serialization/extern.hpp new file mode 100644 index 0000000..8b2cc35
- + 1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 2 // extern.hpp 3 4 // (C) Copyright 2014 Brandon Kohn 5 // Use, modification and distribution is subject to the Boost Software 6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 9 #ifndef BOOST_SERIALIZATION_EXTERN_HPP 10 #define BOOST_SERIALIZATION_EXTERN_HPP 11 12 // MS compatible compilers support #pragma once 13 #if defined(_MSC_VER) 14 # pragma once 15 #endif 16 17 #include <boost/config.hpp> 18 19 #ifndef BOOST_NO_CXX11_EXTERN_TEMPLATE 20 #define BOOST_SERIALIZATION_EXTERN_OSERIALIZER(Archive, T, Export) \ 21 namespace boost { namespace serialization { \ 22 extern template class Export singleton \ 23 < \ 24 ::boost::archive::detail::oserializer<Archive, T> \ 25 >; \ 26 }} \ 27 /***/ 28 29 #define BOOST_SERIALIZATION_INSTANTIATE_OSERIALIZER(Archive, T, Export) \ 30 namespace boost { namespace serialization { \ 31 template class Export singleton \ 32 < \ 33 ::boost::archive::detail::oserializer<Archive, T> \ 34 >; \ 35 }} \ 36 /***/ 37 38 #define BOOST_SERIALIZATION_EXTERN_ISERIALIZER(Archive, T, Export) \ 39 namespace boost { namespace serialization { \ 40 extern template class Export singleton \ 41 < \ 42 ::boost::archive::detail::iserializer<Archive, T> \ 43 >; \ 44 }} \ 45 /***/ 46 47 #define BOOST_SERIALIZATION_INSTANTIATE_ISERIALIZER(Archive, T, Export) \ 48 namespace boost { namespace serialization { \ 49 template class Export singleton \ 50 < \ 51 ::boost::archive::detail::iserializer<Archive, T> \ 52 >; \ 53 }} \ 54 /***/ 55 #else 56 #define BOOST_SERIALIZATION_EXTERN_OSERIALIZER(Archive, T, Export) 57 #define BOOST_SERIALIZATION_INSTANTIATE_OSERIALIZER(Archive, T, Export) 58 #define BOOST_SERIALIZATION_EXTERN_ISERIALIZER(Archive, T, Export) 59 #define BOOST_SERIALIZATION_INSTANTIATE_ISERIALIZER(Archive, T, Export) 60 #endif 61 62 #endif //! BOOST_SERIALIZATION_EXTERN_HPP -
include/boost/serialization/singleton.hpp
diff --git a/include/boost/serialization/singleton.hpp b/include/boost/serialization/singleton.hpp index 546118c..ab6e31c 100644
a b namespace serialization { 77 77 // attempt to retieve a mutable instances while locked will 78 78 // generate a assertion if compiled for debug. 79 79 80 class singleton_module :80 class BOOST_DLLEXPORT singleton_module : 81 81 public boost::noncopyable 82 82 { 83 83 private: … … bool detail::singleton_wrapper< T >::m_is_destroyed = false; 118 118 } // detail 119 119 120 120 template <class T> 121 class singleton : public singleton_module121 class BOOST_DLLEXPORT singleton : public singleton_module 122 122 { 123 123 private: 124 BOOST_DLLEXPORTstatic T & instance;124 static T & instance; 125 125 // include this to provoke instantiation at pre-execution time 126 126 static void use(T const &) {} 127 BOOST_DLLEXPORTstatic T & get_instance() {127 static T & get_instance() { 128 128 static detail::singleton_wrapper< T > t; 129 129 // refer to instance, causing it to be instantiated (and 130 130 // initialized at startup on working compilers) … … private: 133 133 return static_cast<T &>(t); 134 134 } 135 135 public: 136 BOOST_DLLEXPORTstatic T & get_mutable_instance(){136 static T & get_mutable_instance(){ 137 137 BOOST_ASSERT(! is_locked()); 138 138 return get_instance(); 139 139 } 140 BOOST_DLLEXPORTstatic const T & get_const_instance(){140 static const T & get_const_instance(){ 141 141 return get_instance(); 142 142 } 143 BOOST_DLLEXPORTstatic bool is_destroyed(){143 static bool is_destroyed(){ 144 144 return detail::singleton_wrapper< T >::m_is_destroyed; 145 145 } 146 146 }; 147 147 148 148 template<class T> 149 BOOST_DLLEXPORTT & singleton< T >::instance = singleton< T >::get_instance();149 T & singleton< T >::instance = singleton< T >::get_instance(); 150 150 151 151 } // namespace serialization 152 152 } // namespace boost