diff --git a/include/boost/archive/binary_iarchive.hpp b/include/boost/archive/binary_iarchive.hpp index d07bbbe4..ce67ccab 100644 --- a/include/boost/archive/binary_iarchive.hpp +++ b/include/boost/archive/binary_iarchive.hpp @@ -25,37 +25,6 @@ # pragma warning(disable : 4511 4512) #endif -namespace boost { -namespace archive { - -// do not derive from the classes below. If you want to extend this functionality -// via inhertance, derived from binary_iarchive_impl instead. This will -// preserve correct static polymorphism. - -// same as binary_iarchive below - without the shared_ptr_helper -class naked_binary_iarchive : - public binary_iarchive_impl< - boost::archive::naked_binary_iarchive, - std::istream::char_type, - std::istream::traits_type - > -{ -public: - naked_binary_iarchive(std::istream & is, unsigned int flags = 0) : - binary_iarchive_impl< - naked_binary_iarchive, std::istream::char_type, std::istream::traits_type - >(is, flags) - {} - naked_binary_iarchive(std::streambuf & bsb, unsigned int flags = 0) : - binary_iarchive_impl< - naked_binary_iarchive, std::istream::char_type, std::istream::traits_type - >(bsb, flags) - {} -}; - -} // namespace archive -} // namespace boost - namespace boost { namespace archive { diff --git a/include/boost/archive/binary_oarchive.hpp b/include/boost/archive/binary_oarchive.hpp index b1262730..89a86da4 100644 --- a/include/boost/archive/binary_oarchive.hpp +++ b/include/boost/archive/binary_oarchive.hpp @@ -50,8 +50,6 @@ public: {} }; -typedef binary_oarchive naked_binary_oarchive; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/binary_wiarchive.hpp b/include/boost/archive/binary_wiarchive.hpp index ce6576ee..775d8f82 100644 --- a/include/boost/archive/binary_wiarchive.hpp +++ b/include/boost/archive/binary_wiarchive.hpp @@ -28,37 +28,6 @@ namespace boost { namespace archive { -// same as binary_wiarchive below - without the shared_ptr_helper -class naked_binary_wiarchive : - public binary_iarchive_impl< - boost::archive::naked_binary_wiarchive, - std::wistream::char_type, - std::wistream::traits_type - > -{ -public: - naked_binary_wiarchive(std::wistream & is, unsigned int flags = 0) : - binary_iarchive_impl< - naked_binary_wiarchive, - std::wistream::char_type, - std::wistream::traits_type - >(is, flags) - {} - naked_binary_wiarchive(std::wstreambuf & bsb, unsigned int flags = 0) : - binary_iarchive_impl< - naked_binary_wiarchive, - std::wistream::char_type, - std::wistream::traits_type - >(bsb, flags) - {} -}; - -} // namespace archive -} // namespace boost - -namespace boost { -namespace archive { - class binary_wiarchive : public binary_iarchive_impl< binary_wiarchive, std::wistream::char_type, std::wistream::traits_type diff --git a/include/boost/archive/binary_woarchive.hpp b/include/boost/archive/binary_woarchive.hpp index 9d10c2dc..a8817d6f 100644 --- a/include/boost/archive/binary_woarchive.hpp +++ b/include/boost/archive/binary_woarchive.hpp @@ -49,8 +49,6 @@ public: {} }; -typedef binary_woarchive naked_binary_woarchive; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/polymorphic_binary_iarchive.hpp b/include/boost/archive/polymorphic_binary_iarchive.hpp index 9717f2fb..4a898a8a 100644 --- a/include/boost/archive/polymorphic_binary_iarchive.hpp +++ b/include/boost/archive/polymorphic_binary_iarchive.hpp @@ -29,11 +29,11 @@ namespace boost { namespace archive { class polymorphic_binary_iarchive : - public detail::polymorphic_iarchive_route + public detail::polymorphic_iarchive_route { public: polymorphic_binary_iarchive(std::istream & is, unsigned int flags = 0) : - detail::polymorphic_iarchive_route(is, flags) + detail::polymorphic_iarchive_route(is, flags) {} ~polymorphic_binary_iarchive(){} }; diff --git a/include/boost/archive/polymorphic_binary_oarchive.hpp b/include/boost/archive/polymorphic_binary_oarchive.hpp index c72c3f11..931b243f 100644 --- a/include/boost/archive/polymorphic_binary_oarchive.hpp +++ b/include/boost/archive/polymorphic_binary_oarchive.hpp @@ -25,7 +25,7 @@ namespace archive { typedef detail::polymorphic_oarchive_route< binary_oarchive_impl< - naked_binary_oarchive, + binary_oarchive, std::ostream::char_type, std::ostream::traits_type > diff --git a/include/boost/archive/polymorphic_text_iarchive.hpp b/include/boost/archive/polymorphic_text_iarchive.hpp index d6479b6a..7bef2927 100644 --- a/include/boost/archive/polymorphic_text_iarchive.hpp +++ b/include/boost/archive/polymorphic_text_iarchive.hpp @@ -29,11 +29,11 @@ namespace boost { namespace archive { class polymorphic_text_iarchive : - public detail::polymorphic_iarchive_route + public detail::polymorphic_iarchive_route { public: polymorphic_text_iarchive(std::istream & is, unsigned int flags = 0) : - detail::polymorphic_iarchive_route(is, flags) + detail::polymorphic_iarchive_route(is, flags) {} ~polymorphic_text_iarchive(){} }; diff --git a/include/boost/archive/polymorphic_text_wiarchive.hpp b/include/boost/archive/polymorphic_text_wiarchive.hpp index 86d6cbe0..8466f05d 100644 --- a/include/boost/archive/polymorphic_text_wiarchive.hpp +++ b/include/boost/archive/polymorphic_text_wiarchive.hpp @@ -33,11 +33,11 @@ namespace boost { namespace archive { class polymorphic_text_wiarchive : - public detail::polymorphic_iarchive_route + public detail::polymorphic_iarchive_route { public: polymorphic_text_wiarchive(std::wistream & is, unsigned int flags = 0) : - detail::polymorphic_iarchive_route(is, flags) + detail::polymorphic_iarchive_route(is, flags) {} ~polymorphic_text_wiarchive(){} }; diff --git a/include/boost/archive/polymorphic_text_woarchive.hpp b/include/boost/archive/polymorphic_text_woarchive.hpp index b3437398..1013b488 100644 --- a/include/boost/archive/polymorphic_text_woarchive.hpp +++ b/include/boost/archive/polymorphic_text_woarchive.hpp @@ -28,7 +28,7 @@ namespace boost { namespace archive { typedef detail::polymorphic_oarchive_route< - text_woarchive_impl + text_woarchive_impl > polymorphic_text_woarchive; } // namespace archive diff --git a/include/boost/archive/polymorphic_xml_iarchive.hpp b/include/boost/archive/polymorphic_xml_iarchive.hpp index e0e73b50..4dc3f894 100644 --- a/include/boost/archive/polymorphic_xml_iarchive.hpp +++ b/include/boost/archive/polymorphic_xml_iarchive.hpp @@ -29,11 +29,11 @@ namespace boost { namespace archive { class polymorphic_xml_iarchive : - public detail::polymorphic_iarchive_route + public detail::polymorphic_iarchive_route { public: polymorphic_xml_iarchive(std::istream & is, unsigned int flags = 0) : - detail::polymorphic_iarchive_route(is, flags) + detail::polymorphic_iarchive_route(is, flags) {} ~polymorphic_xml_iarchive(){} }; diff --git a/include/boost/archive/polymorphic_xml_oarchive.hpp b/include/boost/archive/polymorphic_xml_oarchive.hpp index eb5e858a..514f9e53 100644 --- a/include/boost/archive/polymorphic_xml_oarchive.hpp +++ b/include/boost/archive/polymorphic_xml_oarchive.hpp @@ -24,7 +24,7 @@ namespace boost { namespace archive { typedef detail::polymorphic_oarchive_route< - xml_oarchive_impl + xml_oarchive_impl > polymorphic_xml_oarchive; } // namespace archive diff --git a/include/boost/archive/polymorphic_xml_wiarchive.hpp b/include/boost/archive/polymorphic_xml_wiarchive.hpp index 19592571..d4ab7312 100644 --- a/include/boost/archive/polymorphic_xml_wiarchive.hpp +++ b/include/boost/archive/polymorphic_xml_wiarchive.hpp @@ -28,11 +28,11 @@ namespace boost { namespace archive { class polymorphic_xml_wiarchive : - public detail::polymorphic_iarchive_route + public detail::polymorphic_iarchive_route { public: polymorphic_xml_wiarchive(std::wistream & is, unsigned int flags = 0) : - detail::polymorphic_iarchive_route(is, flags) + detail::polymorphic_iarchive_route(is, flags) {} ~polymorphic_xml_wiarchive(){} }; diff --git a/include/boost/archive/polymorphic_xml_woarchive.hpp b/include/boost/archive/polymorphic_xml_woarchive.hpp index 141ac56c..dd8963fb 100644 --- a/include/boost/archive/polymorphic_xml_woarchive.hpp +++ b/include/boost/archive/polymorphic_xml_woarchive.hpp @@ -28,7 +28,7 @@ namespace boost { namespace archive { typedef detail::polymorphic_oarchive_route< - xml_woarchive_impl + xml_woarchive_impl > polymorphic_xml_woarchive; } // namespace archive diff --git a/include/boost/archive/text_iarchive.hpp b/include/boost/archive/text_iarchive.hpp index 13cb9930..03c611b3 100644 --- a/include/boost/archive/text_iarchive.hpp +++ b/include/boost/archive/text_iarchive.hpp @@ -96,22 +96,6 @@ protected: ~text_iarchive_impl(){}; }; -// do not derive from the classes below. If you want to extend this functionality -// via inhertance, derived from text_iarchive_impl instead. This will -// preserve correct static polymorphism. - -// same as text_iarchive below - without the shared_ptr_helper -class naked_text_iarchive : - public text_iarchive_impl -{ -public: - naked_text_iarchive(std::istream & is_, unsigned int flags = 0) : - // note: added _ to suppress useless gcc warning - text_iarchive_impl(is_, flags) - {} - ~naked_text_iarchive(){} -}; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/text_oarchive.hpp b/include/boost/archive/text_oarchive.hpp index eda10a19..f07448b7 100644 --- a/include/boost/archive/text_oarchive.hpp +++ b/include/boost/archive/text_oarchive.hpp @@ -106,8 +106,6 @@ public: ~text_oarchive(){} }; -typedef text_oarchive naked_text_oarchive; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/text_wiarchive.hpp b/include/boost/archive/text_wiarchive.hpp index b927a7e3..0435fba9 100644 --- a/include/boost/archive/text_wiarchive.hpp +++ b/include/boost/archive/text_wiarchive.hpp @@ -93,21 +93,6 @@ protected: ~text_wiarchive_impl(){}; }; -// do not derive from the classes below. If you want to extend this functionality -// via inhertance, derived from text_iarchive_impl instead. This will -// preserve correct static polymorphism. - -// same as text_wiarchive below - without the shared_ptr_helper -class naked_text_wiarchive : - public text_wiarchive_impl -{ -public: - naked_text_wiarchive(std::wistream & is, unsigned int flags = 0) : - text_wiarchive_impl(is, flags) - {} - ~naked_text_wiarchive(){} -}; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/text_woarchive.hpp b/include/boost/archive/text_woarchive.hpp index 70e558e0..3c8338a7 100644 --- a/include/boost/archive/text_woarchive.hpp +++ b/include/boost/archive/text_woarchive.hpp @@ -131,8 +131,6 @@ public: ~text_woarchive(){} }; -typedef text_woarchive naked_text_woarchive; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/xml_iarchive.hpp b/include/boost/archive/xml_iarchive.hpp index cdb8cdc3..0a63b530 100644 --- a/include/boost/archive/xml_iarchive.hpp +++ b/include/boost/archive/xml_iarchive.hpp @@ -106,21 +106,6 @@ protected: ~xml_iarchive_impl(); }; -// do not derive from the classes below. If you want to extend this functionality -// via inhertance, derived from text_iarchive_impl instead. This will -// preserve correct static polymorphism. - -// same as xml_iarchive below - without the shared_ptr_helper -class naked_xml_iarchive : - public xml_iarchive_impl -{ -public: - naked_xml_iarchive(std::istream & is, unsigned int flags = 0) : - xml_iarchive_impl(is, flags) - {} - ~naked_xml_iarchive(){} -}; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/xml_oarchive.hpp b/include/boost/archive/xml_oarchive.hpp index 8af4c1f1..02f5b656 100644 --- a/include/boost/archive/xml_oarchive.hpp +++ b/include/boost/archive/xml_oarchive.hpp @@ -120,8 +120,6 @@ public: ~xml_oarchive(){} }; -typedef xml_oarchive naked_xml_oarchive; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/xml_wiarchive.hpp b/include/boost/archive/xml_wiarchive.hpp index 4d4e1a33..51d54b31 100644 --- a/include/boost/archive/xml_wiarchive.hpp +++ b/include/boost/archive/xml_wiarchive.hpp @@ -111,21 +111,6 @@ protected: ~xml_wiarchive_impl(); }; -// do not derive from the classes below. If you want to extend this functionality -// via inhertance, derived from xml_wiarchive_impl instead. This will -// preserve correct static polymorphism. - -// same as xml_wiarchive below - without the shared_ptr_helper -class naked_xml_wiarchive : - public xml_wiarchive_impl -{ -public: - naked_xml_wiarchive(std::wistream & is, unsigned int flags = 0) : - xml_wiarchive_impl(is, flags) - {} - ~naked_xml_wiarchive(){} -}; - } // namespace archive } // namespace boost diff --git a/include/boost/archive/xml_woarchive.hpp b/include/boost/archive/xml_woarchive.hpp index 47d3fd99..c3f72f7d 100644 --- a/include/boost/archive/xml_woarchive.hpp +++ b/include/boost/archive/xml_woarchive.hpp @@ -122,8 +122,6 @@ public: ~xml_woarchive(){} }; -typedef xml_woarchive naked_xml_woarchive; - } // namespace archive } // namespace boost diff --git a/include/boost/serialization/shared_ptr.hpp b/include/boost/serialization/shared_ptr.hpp index 235193ed..13aae1db 100644 --- a/include/boost/serialization/shared_ptr.hpp +++ b/include/boost/serialization/shared_ptr.hpp @@ -121,9 +121,6 @@ inline void load( BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); T* r; if(file_version < 1){ - //ar.register_type(static_cast< - // boost_132::detail::sp_counted_base_impl > * - //>(NULL)); ar.register_type(static_cast< boost_132::detail::sp_counted_base_impl * >(NULL)); @@ -131,13 +128,21 @@ inline void load( ar >> boost::serialization::make_nvp("px", sp.px); ar >> boost::serialization::make_nvp("pn", sp.pn); // got to keep the sps around so the sp.pns don't disappear - ar.template get_helper().append(sp); + boost::serialization::shared_ptr_helper & h = + ar.template get_helper< + shared_ptr_helper + >(); + h.append(sp); r = sp.get(); } else{ ar >> boost::serialization::make_nvp("px", r); } - ar.template get_helper().reset(t,r); + shared_ptr_helper & h = + ar.template get_helper< + boost::serialization::shared_ptr_helper + >(); + h.reset(t,r); } #else template @@ -152,7 +157,11 @@ inline void load( BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); T* r; ar >> boost::serialization::make_nvp("px", r); - ar.template get_helper().reset(t,r); + boost::serialization::shared_ptr_helper & h = + ar.template get_helper< + shared_ptr_helper + >(); + h.reset(t,r); } #endif @@ -174,4 +183,121 @@ inline void serialize( } // namespace serialization } // namespace boost +#ifndef BOOST_NO_CXX11_SMART_PTR + +#include + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// shared_ptr serialization traits +// version 1 to distinguish from boost 1.32 version. Note: we can only do this +// for a template when the compiler supports partial template specialization + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + namespace boost { + namespace serialization{ + template + struct version< ::std::shared_ptr< T > > { + typedef mpl::integral_c_tag tag; + #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) + typedef BOOST_DEDUCED_TYPENAME mpl::int_<1> type; + #else + typedef mpl::int_<1> type; + #endif + #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) + BOOST_STATIC_CONSTANT(int, value = 1); + #else + BOOST_STATIC_CONSTANT(int, value = type::value); + #endif + }; + // don't track shared pointers + template + struct tracking_level< ::std::shared_ptr< T > > { + typedef mpl::integral_c_tag tag; + #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) + typedef BOOST_DEDUCED_TYPENAME mpl::int_< ::boost::serialization::track_never> type; + #else + typedef mpl::int_< ::boost::serialization::track_never> type; + #endif + #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) + BOOST_STATIC_CONSTANT(int, value = ::boost::serialization::track_never); + #else + BOOST_STATIC_CONSTANT(int, value = type::value); + #endif + }; + }} + #define BOOST_SERIALIZATION_SHARED_PTR(T) +#else + // define macro to let users of these compilers do this + #define BOOST_SERIALIZATION_SHARED_PTR(T) \ + BOOST_CLASS_VERSION( \ + ::boost::shared_ptr< T >, \ + 1 \ + ) \ + BOOST_CLASS_TRACKING( \ + ::boost::shared_ptr< T >, \ + ::boost::serialization::track_never \ + ) \ + /**/ +#endif + +namespace boost { +namespace serialization{ + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// serialization for shared_ptr + +template +inline void save( + Archive & ar, + const std::shared_ptr< T > &t, + const unsigned int /* file_version */ +){ + // The most common cause of trapping here would be serializing + // something like shared_ptr. This occurs because int + // is never tracked by default. Wrap int in a trackable type + BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); + const T * t_ptr = t.get(); + ar << boost::serialization::make_nvp("px", t_ptr); +} + +template +inline void load( + Archive & ar, + std::shared_ptr< T > &t, + const unsigned int /*file_version*/ +){ + // The most common cause of trapping here would be serializing + // something like shared_ptr. This occurs because int + // is never tracked by default. Wrap int in a trackable type + BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); + T* r; + ar >> boost::serialization::make_nvp("px", r); + boost::serialization::shared_ptr_helper & h = + ar.template get_helper< + shared_ptr_helper + //boost::archive::detail::shared_ptr_helper + >(); + h.reset(t,r); +} + +template +inline void serialize( + Archive & ar, + std::shared_ptr< T > &t, + const unsigned int file_version +){ + // correct shared_ptr serialization depends upon object tracking + // being used. + BOOST_STATIC_ASSERT( + boost::serialization::tracking_level< T >::value + != boost::serialization::track_never + ); + boost::serialization::split_free(ar, t, file_version); +} + +} // namespace serialization +} // namespace boost + +#endif // BOOST_NO_CXX11_SMART_PTR + #endif // BOOST_SERIALIZATION_SHARED_PTR_HPP diff --git a/include/boost/serialization/weak_ptr.hpp b/include/boost/serialization/weak_ptr.hpp index 6d4b8a20..b3af8bfe 100644 --- a/include/boost/serialization/weak_ptr.hpp +++ b/include/boost/serialization/weak_ptr.hpp @@ -55,4 +55,45 @@ inline void serialize( } // namespace serialization } // namespace boost +#ifndef BOOST_NO_CXX11_SMART_PTR +#include + +namespace boost { +namespace serialization{ + +template +inline void save( + Archive & ar, + const std::weak_ptr< T > &t, + const unsigned int /* file_version */ +){ + const std::shared_ptr< T > sp = t.lock(); + ar << boost::serialization::make_nvp("weak_ptr", sp); +} + +template +inline void load( + Archive & ar, + std::weak_ptr< T > &t, + const unsigned int /* file_version */ +){ + std::shared_ptr< T > sp; + ar >> boost::serialization::make_nvp("weak_ptr", sp); + t = sp; +} + +template +inline void serialize( + Archive & ar, + std::weak_ptr< T > &t, + const unsigned int file_version +){ + boost::serialization::split_free(ar, t, file_version); +} + +} // namespace serialization +} // namespace boost + +#endif // BOOST_NO_CXX11_SMART_PTR + #endif // BOOST_SERIALIZATION_WEAK_PTR_HPP diff --git a/src/binary_iarchive.cpp b/src/binary_iarchive.cpp index 7bb0435c..c1117e9e 100644 --- a/src/binary_iarchive.cpp +++ b/src/binary_iarchive.cpp @@ -21,20 +21,6 @@ namespace boost { namespace archive { -// explicitly instantiate for this type of stream -template class detail::archive_serializer_map; -template class basic_binary_iprimitive< - naked_binary_iarchive, - std::istream::char_type, - std::istream::traits_type ->; -template class basic_binary_iarchive ; -template class binary_iarchive_impl< - naked_binary_iarchive, - std::istream::char_type, - std::istream::traits_type ->; - // explicitly instantiate for this type of stream template class detail::archive_serializer_map; template class basic_binary_iprimitive< diff --git a/src/binary_wiarchive.cpp b/src/binary_wiarchive.cpp index a6135c8c..720d469d 100644 --- a/src/binary_wiarchive.cpp +++ b/src/binary_wiarchive.cpp @@ -26,19 +26,6 @@ namespace boost { namespace archive { -template class detail::archive_serializer_map; -template class basic_binary_iprimitive< - naked_binary_wiarchive, - wchar_t, - std::char_traits ->; -template class basic_binary_iarchive ; -template class binary_iarchive_impl< - naked_binary_wiarchive, - wchar_t, - std::char_traits ->; - // explicitly instantiate for this type of text stream template class detail::archive_serializer_map; template class basic_binary_iprimitive< diff --git a/src/shared_ptr_helper.cpp b/src/shared_ptr_helper.cpp index 54723a38..0f137343 100644 --- a/src/shared_ptr_helper.cpp +++ b/src/shared_ptr_helper.cpp @@ -30,10 +30,14 @@ namespace serialization { /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // a common class for holding various types of shared pointers +struct null_deleter { + void operator()(void const *) const {} +}; + // returns pointer to object and an indicator whether this is a // new entry (true) or a previous one (false) BOOST_ARCHIVE_DECL(shared_ptr) -shared_ptr_helper::get_od( +shared_ptr_helper_base::get_od( const void * t, const boost::serialization::extended_type_info * true_type, const boost::serialization::extended_type_info * this_type @@ -87,7 +91,7 @@ shared_ptr_helper::get_od( } BOOST_ARCHIVE_DECL(void) -shared_ptr_helper::append(const boost::shared_ptr &sp){ +shared_ptr_helper_base::append(const boost::shared_ptr &sp){ // make tracking array if necessary if(NULL == m_pointers) m_pointers = new collection_type; @@ -103,21 +107,23 @@ shared_ptr_helper::append(const boost::shared_ptr &sp){ // #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP BOOST_ARCHIVE_DECL(void) -shared_ptr_helper::append(const boost_132::shared_ptr & t){ +shared_ptr_helper_base::append(const boost_132::shared_ptr & t){ if(NULL == m_pointers_132) m_pointers_132 = new std::list >; m_pointers_132->push_back(t); } // #endif + BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) -shared_ptr_helper::shared_ptr_helper() : +shared_ptr_helper_base::shared_ptr_helper_base() : m_pointers(NULL) #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP , m_pointers_132(NULL) #endif {} + BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) -shared_ptr_helper::~shared_ptr_helper(){ +shared_ptr_helper_base::~shared_ptr_helper_base(){ if(NULL != m_pointers) delete m_pointers; #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP diff --git a/src/text_iarchive.cpp b/src/text_iarchive.cpp index cb9017fa..9520ca25 100644 --- a/src/text_iarchive.cpp +++ b/src/text_iarchive.cpp @@ -24,10 +24,6 @@ namespace boost { namespace archive { -template class detail::archive_serializer_map; -template class basic_text_iarchive ; -template class text_iarchive_impl ; - template class detail::archive_serializer_map; template class basic_text_iarchive ; template class text_iarchive_impl ; diff --git a/src/text_wiarchive.cpp b/src/text_wiarchive.cpp index a6630c03..a0c68a8e 100644 --- a/src/text_wiarchive.cpp +++ b/src/text_wiarchive.cpp @@ -26,10 +26,6 @@ namespace boost { namespace archive { -template class detail::archive_serializer_map; -template class basic_text_iarchive ; -template class text_wiarchive_impl ; - template class detail::archive_serializer_map; template class basic_text_iarchive ; template class text_wiarchive_impl ; diff --git a/src/xml_iarchive.cpp b/src/xml_iarchive.cpp index 6d0de772..43118935 100644 --- a/src/xml_iarchive.cpp +++ b/src/xml_iarchive.cpp @@ -34,10 +34,6 @@ namespace boost { namespace archive { -template class detail::archive_serializer_map; -template class basic_xml_iarchive ; -template class xml_iarchive_impl ; - template class detail::archive_serializer_map; template class basic_xml_iarchive ; template class xml_iarchive_impl ; diff --git a/src/xml_wiarchive.cpp b/src/xml_wiarchive.cpp index 2e10947b..02665488 100644 --- a/src/xml_wiarchive.cpp +++ b/src/xml_wiarchive.cpp @@ -39,10 +39,6 @@ namespace boost { namespace archive { -template class detail::archive_serializer_map; -template class basic_xml_iarchive ; -template class xml_wiarchive_impl ; - template class detail::archive_serializer_map; template class basic_xml_iarchive ; template class xml_wiarchive_impl ; diff --git a/test/test_shared_ptr.cpp b/test/test_shared_ptr.cpp index 1f5d09a7..f69935a2 100644 --- a/test/test_shared_ptr.cpp +++ b/test/test_shared_ptr.cpp @@ -19,11 +19,12 @@ namespace std{ } #endif -#include -#include #include #include +#include +#include + #include "test_tools.hpp" // This is a simple class. It contains a counter of the number @@ -95,14 +96,16 @@ public: int C::count = 0; -void save(const char * testfile, const boost::shared_ptr& spa) +template +void save(const char * testfile, const SP & spa) { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os, TEST_ARCHIVE_FLAGS); oa << BOOST_SERIALIZATION_NVP(spa); } -void load(const char * testfile, boost::shared_ptr& spa) +template +void load(const char * testfile, SP & spa) { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); @@ -110,12 +113,13 @@ void load(const char * testfile, boost::shared_ptr& spa) } // trivial test -void save_and_load(boost::shared_ptr& spa) +template +void save_and_load(SP & spa) { const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); save(testfile, spa); - boost::shared_ptr spa1; + SP spa1; load(testfile, spa1); BOOST_CHECK( @@ -125,10 +129,11 @@ void save_and_load(boost::shared_ptr& spa) std::remove(testfile); } +template void save2( const char * testfile, - const boost::shared_ptr& first, - const boost::shared_ptr& second + const SP & first, + const SP & second ){ test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os, TEST_ARCHIVE_FLAGS); @@ -136,10 +141,11 @@ void save2( oa << BOOST_SERIALIZATION_NVP(second); } +template void load2( const char * testfile, - boost::shared_ptr& first, - boost::shared_ptr& second) + SP & first, + SP & second) { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); @@ -150,7 +156,8 @@ void load2( // Run tests by serializing two shared_ptrs into an archive, // clearing them (deleting the objects) and then reloading the // objects back from an archive. -void save_and_load2(boost::shared_ptr& first, boost::shared_ptr& second) +template +void save_and_load2(SP & first, SP & second) { const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); @@ -167,11 +174,12 @@ void save_and_load2(boost::shared_ptr& first, boost::shared_ptr& second) std::remove(testfile); } +template void save3( const char * testfile, - boost::shared_ptr& first, - boost::shared_ptr& second, - boost::weak_ptr& third + SP & first, + SP & second, + WP & third ){ test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os, TEST_ARCHIVE_FLAGS); @@ -180,11 +188,12 @@ void save3( oa << BOOST_SERIALIZATION_NVP(second); } +template void load3( const char * testfile, - boost::shared_ptr& first, - boost::shared_ptr& second, - boost::weak_ptr& third + SP & first, + SP & second, + WP & third ){ test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); @@ -196,10 +205,11 @@ void load3( ia >> BOOST_SERIALIZATION_NVP(second); } +template void save_and_load3( - boost::shared_ptr& first, - boost::shared_ptr& second, - boost::weak_ptr& third + SP & first, + SP & second, + WP & third ){ const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); @@ -218,14 +228,16 @@ void save_and_load3( std::remove(testfile); } -void save4(const char * testfile, const boost::shared_ptr& spc) +template +void save4(const char * testfile, const SP & spc) { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os, TEST_ARCHIVE_FLAGS); oa << BOOST_SERIALIZATION_NVP(spc); } -void load4(const char * testfile, boost::shared_ptr& spc) +template +void load4(const char * testfile, SP & spc) { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); @@ -233,12 +245,13 @@ void load4(const char * testfile, boost::shared_ptr& spc) } // trivial test -void save_and_load4(boost::shared_ptr& spc) +template +void save_and_load4(SP & spc) { const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); save4(testfile, spc); - boost::shared_ptr spc1; + SP spc1; load4(testfile, spc1); BOOST_CHECK( @@ -249,40 +262,40 @@ void save_and_load4(boost::shared_ptr& spc) } // This does the tests -int test_main(int /* argc */, char * /* argv */[]) -{ +template class SPT , template class WPT > +bool test(){ { - boost::shared_ptr spa; + SPT spa; // These are our shared_ptrs - spa = boost::shared_ptr(new A); - boost::shared_ptr spa1 = spa; + spa = SPT(new A); + SPT spa1 = spa; spa1 = spa; } { // These are our shared_ptrs - boost::shared_ptr spa; + SPT spa; // trivial test 1 save_and_load(spa); //trivival test 2 - spa = boost::shared_ptr(new A); + spa = SPT(new A); save_and_load(spa); // Try to save and load pointers to As - spa = boost::shared_ptr(new A); - boost::shared_ptr spa1 = spa; + spa = SPT(new A); + SPT spa1 = spa; save_and_load2(spa, spa1); // Try to save and load pointers to Bs - spa = boost::shared_ptr(new B); + spa = SPT(new B); spa1 = spa; save_and_load2(spa, spa1); // test a weak pointer - spa = boost::shared_ptr(new A); + spa = SPT(new A); spa1 = spa; - boost::weak_ptr wp = spa; + WPT wp = spa; save_and_load3(spa, spa1, wp); // obj of type B gets destroyed @@ -291,10 +304,19 @@ int test_main(int /* argc */, char * /* argv */[]) BOOST_CHECK(A::count == 0); { // Try to save and load pointers to Cs - boost::shared_ptr spc; - spc = boost::shared_ptr(new C); + SPT spc; + spc = SPT(new C); save_and_load4(spc); } BOOST_CHECK(C::count == 0); - return EXIT_SUCCESS; + return true; } +// This does the tests +int test_main(int /* argc */, char * /* argv */[]) +{ + bool result = true; + result &= test(); + //result &= test(); + return result ? EXIT_SUCCESS : EXIT_FAILURE; +} +