Mercurial > hg > vamp-build-and-test
comparison 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 |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
1 #ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP | 1 #ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP |
2 #define BOOST_SERIALIZATION_SHARED_PTR_HPP | 2 #define BOOST_SERIALIZATION_SHARED_PTR_HPP |
3 | 3 |
4 // MS compatible compilers support #pragma once | 4 // MS compatible compilers support #pragma once |
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020) | 5 #if defined(_MSC_VER) |
6 # pragma once | 6 # pragma once |
7 #endif | 7 #endif |
8 | 8 |
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
10 // shared_ptr.hpp: serialization for boost shared pointer | 10 // shared_ptr.hpp: serialization for boost shared pointer |
15 // http://www.boost.org/LICENSE_1_0.txt) | 15 // http://www.boost.org/LICENSE_1_0.txt) |
16 | 16 |
17 // See http://www.boost.org for updates, documentation, and revision history. | 17 // See http://www.boost.org for updates, documentation, and revision history. |
18 | 18 |
19 #include <cstddef> // NULL | 19 #include <cstddef> // NULL |
20 #include <memory> | |
20 | 21 |
21 #include <boost/config.hpp> | 22 #include <boost/config.hpp> |
22 #include <boost/mpl/integral_c.hpp> | 23 #include <boost/mpl/integral_c.hpp> |
23 #include <boost/mpl/integral_c_tag.hpp> | 24 #include <boost/mpl/integral_c_tag.hpp> |
24 | 25 |
25 #include <boost/detail/workaround.hpp> | 26 #include <boost/detail/workaround.hpp> |
26 #include <boost/shared_ptr.hpp> | 27 #include <boost/shared_ptr.hpp> |
27 | 28 |
29 #include <boost/serialization/shared_ptr_helper.hpp> | |
28 #include <boost/serialization/split_free.hpp> | 30 #include <boost/serialization/split_free.hpp> |
29 #include <boost/serialization/nvp.hpp> | 31 #include <boost/serialization/nvp.hpp> |
30 #include <boost/serialization/version.hpp> | 32 #include <boost/serialization/version.hpp> |
31 #include <boost/serialization/tracking.hpp> | 33 #include <boost/serialization/tracking.hpp> |
32 | 34 |
33 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | 35 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
34 // shared_ptr serialization traits | 36 // boost:: shared_ptr serialization traits |
35 // version 1 to distinguish from boost 1.32 version. Note: we can only do this | 37 // 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 | 38 // for a template when the compiler supports partial template specialization |
37 | 39 |
38 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION | 40 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
39 namespace boost { | 41 namespace boost { |
40 namespace serialization{ | 42 namespace serialization{ |
41 template<class T> | 43 template<class T> |
42 struct version< ::boost::shared_ptr< T > > { | 44 struct version< ::boost::shared_ptr< T > > { |
43 typedef mpl::integral_c_tag tag; | 45 typedef mpl::integral_c_tag tag; |
44 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) | 46 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) |
45 typedef BOOST_DEDUCED_TYPENAME mpl::int_<1> type; | 47 typedef typename mpl::int_<1> type; |
46 #else | 48 #else |
47 typedef mpl::int_<1> type; | 49 typedef mpl::int_<1> type; |
48 #endif | 50 #endif |
49 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) | 51 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) |
50 BOOST_STATIC_CONSTANT(int, value = 1); | 52 BOOST_STATIC_CONSTANT(int, value = 1); |
55 // don't track shared pointers | 57 // don't track shared pointers |
56 template<class T> | 58 template<class T> |
57 struct tracking_level< ::boost::shared_ptr< T > > { | 59 struct tracking_level< ::boost::shared_ptr< T > > { |
58 typedef mpl::integral_c_tag tag; | 60 typedef mpl::integral_c_tag tag; |
59 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) | 61 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) |
60 typedef BOOST_DEDUCED_TYPENAME mpl::int_< ::boost::serialization::track_never> type; | 62 typedef typename mpl::int_< ::boost::serialization::track_never> type; |
61 #else | 63 #else |
62 typedef mpl::int_< ::boost::serialization::track_never> type; | 64 typedef mpl::int_< ::boost::serialization::track_never> type; |
63 #endif | 65 #endif |
64 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) | 66 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) |
65 BOOST_STATIC_CONSTANT(int, value = ::boost::serialization::track_never); | 67 BOOST_STATIC_CONSTANT(int, value = ::boost::serialization::track_never); |
89 struct null_deleter { | 91 struct null_deleter { |
90 void operator()(void const *) const {} | 92 void operator()(void const *) const {} |
91 }; | 93 }; |
92 | 94 |
93 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | 95 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
94 // serialization for shared_ptr | 96 // serialization for boost::shared_ptr |
97 | |
98 // Using a constant means that all shared pointers are held in the same set. | |
99 // Thus we detect handle multiple pointers to the same value instances | |
100 // in the archive. | |
101 void * const shared_ptr_helper_id = 0; | |
95 | 102 |
96 template<class Archive, class T> | 103 template<class Archive, class T> |
97 inline void save( | 104 inline void save( |
98 Archive & ar, | 105 Archive & ar, |
99 const boost::shared_ptr< T > &t, | 106 const boost::shared_ptr< T > &t, |
112 inline void load( | 119 inline void load( |
113 Archive & ar, | 120 Archive & ar, |
114 boost::shared_ptr< T > &t, | 121 boost::shared_ptr< T > &t, |
115 const unsigned int file_version | 122 const unsigned int file_version |
116 ){ | 123 ){ |
117 // The most common cause of trapping here would be serializing | |
118 // something like shared_ptr<int>. This occurs because int | 124 // something like shared_ptr<int>. This occurs because int |
119 // is never tracked by default. Wrap int in a trackable type | 125 // is never tracked by default. Wrap int in a trackable type |
120 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); | 126 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); |
121 T* r; | 127 T* r; |
122 if(file_version < 1){ | 128 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< | 129 ar.register_type(static_cast< |
127 boost_132::detail::sp_counted_base_impl<T *, null_deleter > * | 130 boost_132::detail::sp_counted_base_impl<T *, null_deleter > * |
128 >(NULL)); | 131 >(NULL)); |
129 boost_132::shared_ptr< T > sp; | 132 boost_132::shared_ptr< T > sp; |
130 ar >> boost::serialization::make_nvp("px", sp.px); | 133 ar >> boost::serialization::make_nvp("px", sp.px); |
131 ar >> boost::serialization::make_nvp("pn", sp.pn); | 134 ar >> boost::serialization::make_nvp("pn", sp.pn); |
132 // got to keep the sps around so the sp.pns don't disappear | 135 // got to keep the sps around so the sp.pns don't disappear |
133 ar.append(sp); | 136 boost::serialization::shared_ptr_helper<boost::shared_ptr> & h = |
137 ar.template get_helper< shared_ptr_helper<boost::shared_ptr> >( | |
138 shared_ptr_helper_id | |
139 ); | |
140 h.append(sp); | |
134 r = sp.get(); | 141 r = sp.get(); |
135 } | 142 } |
136 else{ | 143 else{ |
137 ar >> boost::serialization::make_nvp("px", r); | 144 ar >> boost::serialization::make_nvp("px", r); |
138 } | 145 } |
139 ar.reset(t,r); | 146 shared_ptr_helper<boost::shared_ptr> & h = |
140 } | 147 ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >( |
141 | 148 shared_ptr_helper_id |
149 ); | |
150 h.reset(t,r); | |
151 } | |
142 #else | 152 #else |
153 | |
143 template<class Archive, class T> | 154 template<class Archive, class T> |
144 inline void load( | 155 inline void load( |
145 Archive & ar, | 156 Archive & ar, |
146 boost::shared_ptr< T > &t, | 157 boost::shared_ptr< T > &t, |
147 const unsigned int /*file_version*/ | 158 const unsigned int /*file_version*/ |
150 // something like shared_ptr<int>. This occurs because int | 161 // something like shared_ptr<int>. This occurs because int |
151 // is never tracked by default. Wrap int in a trackable type | 162 // is never tracked by default. Wrap int in a trackable type |
152 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); | 163 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); |
153 T* r; | 164 T* r; |
154 ar >> boost::serialization::make_nvp("px", r); | 165 ar >> boost::serialization::make_nvp("px", r); |
155 ar.reset(t,r); | 166 |
167 boost::serialization::shared_ptr_helper<boost::shared_ptr> & h = | |
168 ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >( | |
169 shared_ptr_helper_id | |
170 ); | |
171 h.reset(t,r); | |
156 } | 172 } |
157 #endif | 173 #endif |
158 | 174 |
159 template<class Archive, class T> | 175 template<class Archive, class T> |
160 inline void serialize( | 176 inline void serialize( |
172 } | 188 } |
173 | 189 |
174 } // namespace serialization | 190 } // namespace serialization |
175 } // namespace boost | 191 } // namespace boost |
176 | 192 |
193 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
194 // std::shared_ptr serialization traits | |
195 // version 1 to distinguish from boost 1.32 version. Note: we can only do this | |
196 // for a template when the compiler supports partial template specialization | |
197 | |
198 #ifndef BOOST_NO_CXX11_SMART_PTR | |
199 #include <boost/static_assert.hpp> | |
200 | |
201 // note: we presume that any compiler/library which supports C++11 | |
202 // std::pointers also supports template partial specialization | |
203 // trap here if such presumption were to turn out to wrong!!! | |
204 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION | |
205 BOOST_STATIC_ASSERT(false); | |
206 #endif | |
207 | |
208 namespace boost { | |
209 namespace serialization{ | |
210 template<class T> | |
211 struct version< ::std::shared_ptr< T > > { | |
212 typedef mpl::integral_c_tag tag; | |
213 typedef mpl::int_<1> type; | |
214 BOOST_STATIC_CONSTANT(int, value = type::value); | |
215 }; | |
216 // don't track shared pointers | |
217 template<class T> | |
218 struct tracking_level< ::std::shared_ptr< T > > { | |
219 typedef mpl::integral_c_tag tag; | |
220 typedef mpl::int_< ::boost::serialization::track_never> type; | |
221 BOOST_STATIC_CONSTANT(int, value = type::value); | |
222 }; | |
223 }} | |
224 // the following just keeps older programs from breaking | |
225 #define BOOST_SERIALIZATION_SHARED_PTR(T) | |
226 | |
227 namespace boost { | |
228 namespace serialization{ | |
229 | |
230 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
231 // serialization for std::shared_ptr | |
232 | |
233 template<class Archive, class T> | |
234 inline void save( | |
235 Archive & ar, | |
236 const std::shared_ptr< T > &t, | |
237 const unsigned int /* file_version */ | |
238 ){ | |
239 // The most common cause of trapping here would be serializing | |
240 // something like shared_ptr<int>. This occurs because int | |
241 // is never tracked by default. Wrap int in a trackable type | |
242 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); | |
243 const T * t_ptr = t.get(); | |
244 ar << boost::serialization::make_nvp("px", t_ptr); | |
245 } | |
246 | |
247 template<class Archive, class T> | |
248 inline void load( | |
249 Archive & ar, | |
250 std::shared_ptr< T > &t, | |
251 const unsigned int /*file_version*/ | |
252 ){ | |
253 // The most common cause of trapping here would be serializing | |
254 // something like shared_ptr<int>. This occurs because int | |
255 // is never tracked by default. Wrap int in a trackable type | |
256 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never)); | |
257 T* r; | |
258 ar >> boost::serialization::make_nvp("px", r); | |
259 //void (* const id)(Archive &, std::shared_ptr< T > &, const unsigned int) = & load; | |
260 boost::serialization::shared_ptr_helper<std::shared_ptr> & h = | |
261 ar.template get_helper< | |
262 shared_ptr_helper<std::shared_ptr> | |
263 >( | |
264 shared_ptr_helper_id | |
265 ); | |
266 h.reset(t,r); | |
267 } | |
268 | |
269 template<class Archive, class T> | |
270 inline void serialize( | |
271 Archive & ar, | |
272 std::shared_ptr< T > &t, | |
273 const unsigned int file_version | |
274 ){ | |
275 // correct shared_ptr serialization depends upon object tracking | |
276 // being used. | |
277 BOOST_STATIC_ASSERT( | |
278 boost::serialization::tracking_level< T >::value | |
279 != boost::serialization::track_never | |
280 ); | |
281 boost::serialization::split_free(ar, t, file_version); | |
282 } | |
283 | |
284 } // namespace serialization | |
285 } // namespace boost | |
286 | |
287 #endif // BOOST_NO_CXX11_SMART_PTR | |
288 | |
177 #endif // BOOST_SERIALIZATION_SHARED_PTR_HPP | 289 #endif // BOOST_SERIALIZATION_SHARED_PTR_HPP |