File indexing completed on 2024-11-15 09:31:01
0001 #ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP
0002 #define BOOST_SERIALIZATION_SHARED_PTR_HPP
0003
0004
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <cstddef> // NULL
0020 #include <memory>
0021
0022 #include <boost/config.hpp>
0023 #include <boost/mpl/integral_c.hpp>
0024 #include <boost/mpl/integral_c_tag.hpp>
0025
0026 #include <boost/detail/workaround.hpp>
0027 #include <boost/shared_ptr.hpp>
0028
0029 #include <boost/serialization/shared_ptr_helper.hpp>
0030 #include <boost/serialization/split_free.hpp>
0031 #include <boost/serialization/nvp.hpp>
0032 #include <boost/serialization/version.hpp>
0033 #include <boost/serialization/tracking.hpp>
0034
0035
0036
0037
0038
0039
0040 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
0041 namespace boost {
0042 namespace serialization{
0043 template<class T>
0044 struct version< ::boost::shared_ptr< T > > {
0045 typedef mpl::integral_c_tag tag;
0046 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
0047 typedef typename mpl::int_<1> type;
0048 #else
0049 typedef mpl::int_<1> type;
0050 #endif
0051 BOOST_STATIC_CONSTANT(int, value = type::value);
0052 };
0053
0054 template<class T>
0055 struct tracking_level< ::boost::shared_ptr< T > > {
0056 typedef mpl::integral_c_tag tag;
0057 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
0058 typedef typename mpl::int_< ::boost::serialization::track_never> type;
0059 #else
0060 typedef mpl::int_< ::boost::serialization::track_never> type;
0061 #endif
0062 BOOST_STATIC_CONSTANT(int, value = type::value);
0063 };
0064 }}
0065 #define BOOST_SERIALIZATION_SHARED_PTR(T)
0066 #else
0067
0068 #define BOOST_SERIALIZATION_SHARED_PTR(T) \
0069 BOOST_CLASS_VERSION( \
0070 ::boost::shared_ptr< T >, \
0071 1 \
0072 ) \
0073 BOOST_CLASS_TRACKING( \
0074 ::boost::shared_ptr< T >, \
0075 ::boost::serialization::track_never \
0076 ) \
0077
0078 #endif
0079
0080 namespace boost {
0081 namespace serialization{
0082
0083 struct null_deleter {
0084 void operator()(void const *) const {}
0085 };
0086
0087
0088
0089
0090
0091
0092
0093 void * const shared_ptr_helper_id = 0;
0094
0095 template<class Archive, class T>
0096 inline void save(
0097 Archive & ar,
0098 const boost::shared_ptr< T > &t,
0099 const unsigned int
0100 ){
0101
0102
0103
0104 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
0105 const T * t_ptr = t.get();
0106 ar << boost::serialization::make_nvp("px", t_ptr);
0107 }
0108
0109 #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
0110 template<class Archive, class T>
0111 inline void load(
0112 Archive & ar,
0113 boost::shared_ptr< T > &t,
0114 const unsigned int file_version
0115 ){
0116
0117
0118 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
0119 T* r;
0120 if(file_version < 1){
0121 ar.register_type(static_cast<
0122 boost_132::detail::sp_counted_base_impl<T *, null_deleter > *
0123 >(NULL));
0124 boost_132::shared_ptr< T > sp;
0125 ar >> boost::serialization::make_nvp("px", sp.px);
0126 ar >> boost::serialization::make_nvp("pn", sp.pn);
0127
0128 boost::serialization::shared_ptr_helper<boost::shared_ptr> & h =
0129 ar.template get_helper< shared_ptr_helper<boost::shared_ptr> >(
0130 shared_ptr_helper_id
0131 );
0132 h.append(sp);
0133 r = sp.get();
0134 }
0135 else{
0136 ar >> boost::serialization::make_nvp("px", r);
0137 }
0138 shared_ptr_helper<boost::shared_ptr> & h =
0139 ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >(
0140 shared_ptr_helper_id
0141 );
0142 h.reset(t,r);
0143 }
0144 #else
0145
0146 template<class Archive, class T>
0147 inline void load(
0148 Archive & ar,
0149 boost::shared_ptr< T > &t,
0150 const unsigned int
0151 ){
0152
0153
0154
0155 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
0156 T* r;
0157 ar >> boost::serialization::make_nvp("px", r);
0158
0159 boost::serialization::shared_ptr_helper<boost::shared_ptr> & h =
0160 ar.template get_helper<shared_ptr_helper<boost::shared_ptr> >(
0161 shared_ptr_helper_id
0162 );
0163 h.reset(t,r);
0164 }
0165 #endif
0166
0167 template<class Archive, class T>
0168 inline void serialize(
0169 Archive & ar,
0170 boost::shared_ptr< T > &t,
0171 const unsigned int file_version
0172 ){
0173
0174
0175 BOOST_STATIC_ASSERT(
0176 boost::serialization::tracking_level< T >::value
0177 != boost::serialization::track_never
0178 );
0179 boost::serialization::split_free(ar, t, file_version);
0180 }
0181
0182 }
0183 }
0184
0185
0186
0187
0188
0189
0190 #ifndef BOOST_NO_CXX11_SMART_PTR
0191 #include <boost/static_assert.hpp>
0192
0193
0194
0195
0196 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
0197 BOOST_STATIC_ASSERT(false);
0198 #endif
0199
0200 namespace boost {
0201 namespace serialization{
0202 template<class T>
0203 struct version< ::std::shared_ptr< T > > {
0204 typedef mpl::integral_c_tag tag;
0205 typedef mpl::int_<1> type;
0206 BOOST_STATIC_CONSTANT(int, value = type::value);
0207 };
0208
0209 template<class T>
0210 struct tracking_level< ::std::shared_ptr< T > > {
0211 typedef mpl::integral_c_tag tag;
0212 typedef mpl::int_< ::boost::serialization::track_never> type;
0213 BOOST_STATIC_CONSTANT(int, value = type::value);
0214 };
0215 }}
0216
0217 #define BOOST_SERIALIZATION_SHARED_PTR(T)
0218
0219 namespace boost {
0220 namespace serialization{
0221
0222
0223
0224
0225 template<class Archive, class T>
0226 inline void save(
0227 Archive & ar,
0228 const std::shared_ptr< T > &t,
0229 const unsigned int
0230 ){
0231
0232
0233
0234 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
0235 const T * t_ptr = t.get();
0236 ar << boost::serialization::make_nvp("px", t_ptr);
0237 }
0238
0239 template<class Archive, class T>
0240 inline void load(
0241 Archive & ar,
0242 std::shared_ptr< T > &t,
0243 const unsigned int
0244 ){
0245
0246
0247
0248 BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
0249 T* r;
0250 ar >> boost::serialization::make_nvp("px", r);
0251
0252 boost::serialization::shared_ptr_helper<std::shared_ptr> & h =
0253 ar.template get_helper<
0254 shared_ptr_helper<std::shared_ptr>
0255 >(
0256 shared_ptr_helper_id
0257 );
0258 h.reset(t,r);
0259 }
0260
0261 template<class Archive, class T>
0262 inline void serialize(
0263 Archive & ar,
0264 std::shared_ptr< T > &t,
0265 const unsigned int file_version
0266 ){
0267
0268
0269 BOOST_STATIC_ASSERT(
0270 boost::serialization::tracking_level< T >::value
0271 != boost::serialization::track_never
0272 );
0273 boost::serialization::split_free(ar, t, file_version);
0274 }
0275
0276 }
0277 }
0278
0279 #endif
0280
0281 #endif