diff DEPENDENCIES/generic/include/boost/serialization/shared_ptr.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
line wrap: on
line diff
--- a/DEPENDENCIES/generic/include/boost/serialization/shared_ptr.hpp	Fri Sep 04 12:01:02 2015 +0100
+++ b/DEPENDENCIES/generic/include/boost/serialization/shared_ptr.hpp	Mon Sep 07 11:12:49 2015 +0100
@@ -2,7 +2,7 @@
 #define BOOST_SERIALIZATION_SHARED_PTR_HPP
 
 // MS compatible compilers support #pragma once
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+#if defined(_MSC_VER)
 # pragma once
 #endif
 
@@ -17,6 +17,7 @@
 //  See http://www.boost.org for updates, documentation, and revision history.
 
 #include <cstddef> // NULL
+#include <memory>
 
 #include <boost/config.hpp>
 #include <boost/mpl/integral_c.hpp>
@@ -25,13 +26,14 @@
 #include <boost/detail/workaround.hpp>
 #include <boost/shared_ptr.hpp>
 
+#include <boost/serialization/shared_ptr_helper.hpp>
 #include <boost/serialization/split_free.hpp>
 #include <boost/serialization/nvp.hpp>
 #include <boost/serialization/version.hpp>
 #include <boost/serialization/tracking.hpp>
 
 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// shared_ptr serialization traits
+// boost:: 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
 
@@ -42,7 +44,7 @@
         struct version< ::boost::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;
+            typedef typename mpl::int_<1> type;
             #else
             typedef mpl::int_<1> type;
             #endif
@@ -57,7 +59,7 @@
         struct tracking_level< ::boost::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;
+            typedef typename mpl::int_< ::boost::serialization::track_never> type;
             #else
             typedef mpl::int_< ::boost::serialization::track_never> type;
             #endif
@@ -91,7 +93,12 @@
 };
 
 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// serialization for shared_ptr
+// serialization for boost::shared_ptr
+
+// Using a constant means that all shared pointers are held in the same set.
+// Thus we detect handle multiple pointers to the same value instances
+// in the archive.
+void * const shared_ptr_helper_id = 0;
 
 template<class Archive, class T>
 inline void save(
@@ -114,15 +121,11 @@
     boost::shared_ptr< T > &t,
     const unsigned int file_version
 ){
-    // The most common cause of trapping here would be serializing
     // something like shared_ptr<int>.  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;
     if(file_version < 1){
-        //ar.register_type(static_cast<
-        //    boost_132::detail::sp_counted_base_impl<T *, boost::checked_deleter< T > > *
-        //>(NULL));
         ar.register_type(static_cast<
             boost_132::detail::sp_counted_base_impl<T *, null_deleter > *
         >(NULL));
@@ -130,16 +133,24 @@
         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.append(sp);
+        boost::serialization::shared_ptr_helper<boost::shared_ptr> & h =
+            ar.template get_helper< shared_ptr_helper<boost::shared_ptr> >(
+                shared_ptr_helper_id
+            );
+        h.append(sp);
         r = sp.get();
     }
     else{
         ar >> boost::serialization::make_nvp("px", r);
     }
-    ar.reset(t,r);
+    shared_ptr_helper<boost::shared_ptr> & h =
+        ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >(
+            shared_ptr_helper_id
+        );
+    h.reset(t,r);
 }
+#else
 
-#else
 template<class Archive, class T>
 inline void load(
     Archive & ar,
@@ -152,7 +163,12 @@
     BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
     T* r;
     ar >> boost::serialization::make_nvp("px", r);
-    ar.reset(t,r);
+
+    boost::serialization::shared_ptr_helper<boost::shared_ptr> & h =
+        ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >(
+            shared_ptr_helper_id
+        );
+    h.reset(t,r);    
 }
 #endif
 
@@ -174,4 +190,100 @@
 } // namespace serialization
 } // namespace boost
 
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// std::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_CXX11_SMART_PTR
+#include <boost/static_assert.hpp>
+
+// note: we presume that any compiler/library which supports C++11
+// std::pointers also supports template partial specialization
+// trap here if such presumption were to turn out to wrong!!!
+#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+    BOOST_STATIC_ASSERT(false);
+#endif
+
+namespace boost {
+namespace serialization{
+    template<class T>
+    struct version< ::std::shared_ptr< T > > {
+        typedef mpl::integral_c_tag tag;
+        typedef mpl::int_<1> type;
+        BOOST_STATIC_CONSTANT(int, value = type::value);
+    };
+    // don't track shared pointers
+    template<class T>
+    struct tracking_level< ::std::shared_ptr< T > > { 
+        typedef mpl::integral_c_tag tag;
+        typedef mpl::int_< ::boost::serialization::track_never> type;
+        BOOST_STATIC_CONSTANT(int, value = type::value);
+    };
+}}
+// the following just keeps older programs from breaking
+#define BOOST_SERIALIZATION_SHARED_PTR(T)
+
+namespace boost {
+namespace serialization{
+
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// serialization for std::shared_ptr
+
+template<class Archive, class T>
+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<int>.  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<class Archive, class T>
+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<int>.  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);
+    //void (* const id)(Archive &, std::shared_ptr< T > &, const unsigned int) = & load;
+    boost::serialization::shared_ptr_helper<std::shared_ptr> & h =
+        ar.template get_helper<
+            shared_ptr_helper<std::shared_ptr>
+        >(
+            shared_ptr_helper_id
+        );
+    h.reset(t,r);
+}
+
+template<class Archive, class T>
+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