1 #ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP
2 #define BOOST_SERIALIZATION_SHARED_PTR_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // shared_ptr.hpp: serialization for boost shared pointer
12 // (C) Copyright 2004 Robert Ramey and Martin Ecker
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // See http://www.boost.org for updates, documentation, and revision history.
20 #include <cstddef> // NULL
22 #include <boost/config.hpp>
23 #include <boost/mpl/integral_c.hpp>
24 #include <boost/mpl/integral_c_tag.hpp>
26 #include <boost/detail/workaround.hpp>
27 #include <boost/shared_ptr.hpp>
29 #include <boost/serialization/split_free.hpp>
30 #include <boost/serialization/nvp.hpp>
31 #include <boost/serialization/version.hpp>
32 #include <boost/serialization/tracking.hpp>
34 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
35 // shared_ptr serialization traits
36 // version 1 to distinguish from boost 1.32 version. Note: we can only do this
37 // for a template when the compiler supports partial template specialization
39 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
41 namespace serialization
{
43 struct version
< ::boost::shared_ptr
<T
> > {
44 typedef mpl::integral_c_tag tag
;
45 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
46 typedef BOOST_DEDUCED_TYPENAME
mpl::int_
<1> type
;
48 typedef mpl::int_
<1> type
;
50 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
51 BOOST_STATIC_CONSTANT(unsigned int, value
= 1);
53 BOOST_STATIC_CONSTANT(unsigned int, value
= type::value
);
56 // don't track shared pointers
58 struct tracking_level
< ::boost::shared_ptr
<T
> > {
59 typedef mpl::integral_c_tag tag
;
60 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
61 typedef BOOST_DEDUCED_TYPENAME
mpl::int_
< ::boost::serialization::track_never
> type
;
63 typedef mpl::int_
< ::boost::serialization::track_never
> type
;
65 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
66 BOOST_STATIC_CONSTANT(int, value
= ::boost::serialization::track_never
);
68 BOOST_STATIC_CONSTANT(int, value
= type::value
);
72 #define BOOST_SERIALIZATION_SHARED_PTR(T)
74 // define macro to let users of these compilers do this
75 #define BOOST_SERIALIZATION_SHARED_PTR(T) \
76 BOOST_CLASS_VERSION( \
77 ::boost::shared_ptr< T >, \
80 BOOST_CLASS_TRACKING( \
81 ::boost::shared_ptr< T >, \
82 ::boost::serialization::track_never \
88 namespace serialization
{
90 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
91 // serialization for shared_ptr
93 template<class Archive
, class T
>
96 const boost::shared_ptr
<T
> &t
,
97 const unsigned int /* file_version */
99 // The most common cause of trapping here would be serializing
100 // something like shared_ptr<int>. This occurs because int
101 // is never tracked by default. Wrap int in a trackable type
102 BOOST_STATIC_ASSERT((tracking_level
<T
>::value
!= track_never
));
103 const T
* t_ptr
= t
.get();
104 ar
<< boost::serialization::make_nvp("px", t_ptr
);
107 template<class Archive
, class T
>
110 boost::shared_ptr
<T
> &t
,
111 const unsigned int file_version
113 // The most common cause of trapping here would be serializing
114 // something like shared_ptr<int>. This occurs because int
115 // is never tracked by default. Wrap int in a trackable type
116 BOOST_STATIC_ASSERT((tracking_level
<T
>::value
!= track_never
));
118 #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
119 if(file_version
< 1){
120 //ar.register_type(static_cast<
121 // boost_132::detail::sp_counted_base_impl<T *, boost::checked_deleter<T> > *
123 ar
.register_type(static_cast<
124 boost_132::detail::sp_counted_base_impl
<T
*, boost::archive::detail::null_deleter
> *
126 boost_132::shared_ptr
<T
> sp
;
127 ar
>> boost::serialization::make_nvp("px", sp
.px
);
128 ar
>> boost::serialization::make_nvp("pn", sp
.pn
);
129 // got to keep the sps around so the sp.pns don't disappear
136 ar
>> boost::serialization::make_nvp("px", r
);
141 template<class Archive
, class T
>
142 inline void serialize(
144 boost::shared_ptr
<T
> &t
,
145 const unsigned int file_version
147 // correct shared_ptr serialization depends upon object tracking
150 boost::serialization::tracking_level
<T
>::value
151 != boost::serialization::track_never
153 boost::serialization::split_free(ar
, t
, file_version
);
156 } // namespace serialization
159 #endif // BOOST_SERIALIZATION_SHARED_PTR_HPP