comparison DEPENDENCIES/generic/include/boost/serialization/shared_ptr.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 #ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP
2 #define BOOST_SERIALIZATION_SHARED_PTR_HPP
3
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
8
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // shared_ptr.hpp: serialization for boost shared pointer
11
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)
16
17 // See http://www.boost.org for updates, documentation, and revision history.
18
19 #include <cstddef> // NULL
20
21 #include <boost/config.hpp>
22 #include <boost/mpl/integral_c.hpp>
23 #include <boost/mpl/integral_c_tag.hpp>
24
25 #include <boost/detail/workaround.hpp>
26 #include <boost/shared_ptr.hpp>
27
28 #include <boost/serialization/split_free.hpp>
29 #include <boost/serialization/nvp.hpp>
30 #include <boost/serialization/version.hpp>
31 #include <boost/serialization/tracking.hpp>
32
33 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
34 // shared_ptr serialization traits
35 // version 1 to distinguish from boost 1.32 version. Note: we can only do this
36 // for a template when the compiler supports partial template specialization
37
38 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
39 namespace boost {
40 namespace serialization{
41 template<class T>
42 struct version< ::boost::shared_ptr< T > > {
43 typedef mpl::integral_c_tag tag;
44 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
45 typedef BOOST_DEDUCED_TYPENAME mpl::int_<1> type;
46 #else
47 typedef mpl::int_<1> type;
48 #endif
49 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
50 BOOST_STATIC_CONSTANT(int, value = 1);
51 #else
52 BOOST_STATIC_CONSTANT(int, value = type::value);
53 #endif
54 };
55 // don't track shared pointers
56 template<class T>
57 struct tracking_level< ::boost::shared_ptr< T > > {
58 typedef mpl::integral_c_tag tag;
59 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
60 typedef BOOST_DEDUCED_TYPENAME mpl::int_< ::boost::serialization::track_never> type;
61 #else
62 typedef mpl::int_< ::boost::serialization::track_never> type;
63 #endif
64 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
65 BOOST_STATIC_CONSTANT(int, value = ::boost::serialization::track_never);
66 #else
67 BOOST_STATIC_CONSTANT(int, value = type::value);
68 #endif
69 };
70 }}
71 #define BOOST_SERIALIZATION_SHARED_PTR(T)
72 #else
73 // define macro to let users of these compilers do this
74 #define BOOST_SERIALIZATION_SHARED_PTR(T) \
75 BOOST_CLASS_VERSION( \
76 ::boost::shared_ptr< T >, \
77 1 \
78 ) \
79 BOOST_CLASS_TRACKING( \
80 ::boost::shared_ptr< T >, \
81 ::boost::serialization::track_never \
82 ) \
83 /**/
84 #endif
85
86 namespace boost {
87 namespace serialization{
88
89 struct null_deleter {
90 void operator()(void const *) const {}
91 };
92
93 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
94 // serialization for shared_ptr
95
96 template<class Archive, class T>
97 inline void save(
98 Archive & ar,
99 const boost::shared_ptr< T > &t,
100 const unsigned int /* file_version */
101 ){
102 // The most common cause of trapping here would be serializing
103 // something like shared_ptr<int>. This occurs because int
104 // is never tracked by default. Wrap int in a trackable type
105 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
106 const T * t_ptr = t.get();
107 ar << boost::serialization::make_nvp("px", t_ptr);
108 }
109
110 #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
111 template<class Archive, class T>
112 inline void load(
113 Archive & ar,
114 boost::shared_ptr< T > &t,
115 const unsigned int file_version
116 ){
117 // The most common cause of trapping here would be serializing
118 // something like shared_ptr<int>. This occurs because int
119 // is never tracked by default. Wrap int in a trackable type
120 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
121 T* r;
122 if(file_version < 1){
123 //ar.register_type(static_cast<
124 // boost_132::detail::sp_counted_base_impl<T *, boost::checked_deleter< T > > *
125 //>(NULL));
126 ar.register_type(static_cast<
127 boost_132::detail::sp_counted_base_impl<T *, null_deleter > *
128 >(NULL));
129 boost_132::shared_ptr< T > sp;
130 ar >> boost::serialization::make_nvp("px", sp.px);
131 ar >> boost::serialization::make_nvp("pn", sp.pn);
132 // got to keep the sps around so the sp.pns don't disappear
133 ar.append(sp);
134 r = sp.get();
135 }
136 else{
137 ar >> boost::serialization::make_nvp("px", r);
138 }
139 ar.reset(t,r);
140 }
141
142 #else
143 template<class Archive, class T>
144 inline void load(
145 Archive & ar,
146 boost::shared_ptr< T > &t,
147 const unsigned int /*file_version*/
148 ){
149 // The most common cause of trapping here would be serializing
150 // something like shared_ptr<int>. This occurs because int
151 // is never tracked by default. Wrap int in a trackable type
152 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
153 T* r;
154 ar >> boost::serialization::make_nvp("px", r);
155 ar.reset(t,r);
156 }
157 #endif
158
159 template<class Archive, class T>
160 inline void serialize(
161 Archive & ar,
162 boost::shared_ptr< T > &t,
163 const unsigned int file_version
164 ){
165 // correct shared_ptr serialization depends upon object tracking
166 // being used.
167 BOOST_STATIC_ASSERT(
168 boost::serialization::tracking_level< T >::value
169 != boost::serialization::track_never
170 );
171 boost::serialization::split_free(ar, t, file_version);
172 }
173
174 } // namespace serialization
175 } // namespace boost
176
177 #endif // BOOST_SERIALIZATION_SHARED_PTR_HPP