From ae8bf9fa9c0c0baf275d68538804be6ac6f7922a Mon Sep 17 00:00:00 2001 From: Brandon Kohn 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 --- /dev/null +++ b/include/boost/serialization/extern.hpp @@ -0,0 +1,62 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// extern.hpp + +// (C) Copyright 2014 Brandon Kohn +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_SERIALIZATION_EXTERN_HPP +#define BOOST_SERIALIZATION_EXTERN_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +#include + +#ifndef BOOST_NO_CXX11_EXTERN_TEMPLATE + #define BOOST_SERIALIZATION_EXTERN_OSERIALIZER(Archive, T, Export) \ + namespace boost { namespace serialization { \ + extern template class Export singleton \ + < \ + ::boost::archive::detail::oserializer \ + >; \ + }} \ + /***/ + + #define BOOST_SERIALIZATION_INSTANTIATE_OSERIALIZER(Archive, T, Export) \ + namespace boost { namespace serialization { \ + template class Export singleton \ + < \ + ::boost::archive::detail::oserializer \ + >; \ + }} \ + /***/ + + #define BOOST_SERIALIZATION_EXTERN_ISERIALIZER(Archive, T, Export) \ + namespace boost { namespace serialization { \ + extern template class Export singleton \ + < \ + ::boost::archive::detail::iserializer \ + >; \ + }} \ + /***/ + + #define BOOST_SERIALIZATION_INSTANTIATE_ISERIALIZER(Archive, T, Export) \ + namespace boost { namespace serialization { \ + template class Export singleton \ + < \ + ::boost::archive::detail::iserializer \ + >; \ + }} \ + /***/ +#else + #define BOOST_SERIALIZATION_EXTERN_OSERIALIZER(Archive, T, Export) + #define BOOST_SERIALIZATION_INSTANTIATE_OSERIALIZER(Archive, T, Export) + #define BOOST_SERIALIZATION_EXTERN_ISERIALIZER(Archive, T, Export) + #define BOOST_SERIALIZATION_INSTANTIATE_ISERIALIZER(Archive, T, Export) +#endif + +#endif //! BOOST_SERIALIZATION_EXTERN_HPP diff --git a/include/boost/serialization/singleton.hpp b/include/boost/serialization/singleton.hpp index 546118c..ab6e31c 100644 --- a/include/boost/serialization/singleton.hpp +++ b/include/boost/serialization/singleton.hpp @@ -77,7 +77,7 @@ namespace serialization { // attempt to retieve a mutable instances while locked will // generate a assertion if compiled for debug. -class singleton_module : +class BOOST_DLLEXPORT singleton_module : public boost::noncopyable { private: @@ -118,13 +118,13 @@ bool detail::singleton_wrapper< T >::m_is_destroyed = false; } // detail template -class singleton : public singleton_module +class BOOST_DLLEXPORT singleton : public singleton_module { private: - BOOST_DLLEXPORT static T & instance; + static T & instance; // include this to provoke instantiation at pre-execution time static void use(T const &) {} - BOOST_DLLEXPORT static T & get_instance() { + static T & get_instance() { static detail::singleton_wrapper< T > t; // refer to instance, causing it to be instantiated (and // initialized at startup on working compilers) @@ -133,20 +133,20 @@ private: return static_cast(t); } public: - BOOST_DLLEXPORT static T & get_mutable_instance(){ + static T & get_mutable_instance(){ BOOST_ASSERT(! is_locked()); return get_instance(); } - BOOST_DLLEXPORT static const T & get_const_instance(){ + static const T & get_const_instance(){ return get_instance(); } - BOOST_DLLEXPORT static bool is_destroyed(){ + static bool is_destroyed(){ return detail::singleton_wrapper< T >::m_is_destroyed; } }; template -BOOST_DLLEXPORT T & singleton< T >::instance = singleton< T >::get_instance(); + T & singleton< T >::instance = singleton< T >::get_instance(); } // namespace serialization } // namespace boost -- 1.8.5.2.msysgit.0