Back to home page

EIC code displayed by LXR

 
 

    


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 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // shared_ptr.hpp: serialization for boost shared pointer
0011 
0012 // (C) Copyright 2004 Robert Ramey and Martin Ecker
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
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 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0036 // boost:: shared_ptr serialization traits
0037 // version 1 to distinguish from boost 1.32 version. Note: we can only do this
0038 // for a template when the compiler supports partial template specialization
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         // don't track shared pointers
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     // define macro to let users of these compilers do this
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 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0088 // serialization for boost::shared_ptr
0089 
0090 // Using a constant means that all shared pointers are held in the same set.
0091 // Thus we detect handle multiple pointers to the same value instances
0092 // in the archive.
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 /* file_version */
0100 ){
0101     // The most common cause of trapping here would be serializing
0102     // something like shared_ptr<int>.  This occurs because int
0103     // is never tracked by default.  Wrap int in a trackable type
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     // something like shared_ptr<int>.  This occurs because int
0117     // is never tracked by default.  Wrap int in a trackable type
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         // got to keep the sps around so the sp.pns don't disappear
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 /*file_version*/
0151 ){
0152     // The most common cause of trapping here would be serializing
0153     // something like shared_ptr<int>.  This occurs because int
0154     // is never tracked by default.  Wrap int in a trackable type
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     // correct shared_ptr serialization depends upon object tracking
0174     // being used.
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 } // namespace serialization
0183 } // namespace boost
0184 
0185 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0186 // std::shared_ptr serialization traits
0187 // version 1 to distinguish from boost 1.32 version. Note: we can only do this
0188 // for a template when the compiler supports partial template specialization
0189 
0190 #ifndef BOOST_NO_CXX11_SMART_PTR
0191 #include <boost/static_assert.hpp>
0192 
0193 // note: we presume that any compiler/library which supports C++11
0194 // std::pointers also supports template partial specialization
0195 // trap here if such presumption were to turn out to wrong!!!
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     // don't track shared pointers
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 // the following just keeps older programs from breaking
0217 #define BOOST_SERIALIZATION_SHARED_PTR(T)
0218 
0219 namespace boost {
0220 namespace serialization{
0221 
0222 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0223 // serialization for std::shared_ptr
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 /* file_version */
0230 ){
0231     // The most common cause of trapping here would be serializing
0232     // something like shared_ptr<int>.  This occurs because int
0233     // is never tracked by default.  Wrap int in a trackable type
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 /*file_version*/
0244 ){
0245     // The most common cause of trapping here would be serializing
0246     // something like shared_ptr<int>.  This occurs because int
0247     // is never tracked by default.  Wrap int in a trackable type
0248     BOOST_STATIC_ASSERT((tracking_level< T >::value != track_never));
0249     T* r;
0250     ar >> boost::serialization::make_nvp("px", r);
0251     //void (* const id)(Archive &, std::shared_ptr< T > &, const unsigned int) = & load;
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     // correct shared_ptr serialization depends upon object tracking
0268     // being used.
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 } // namespace serialization
0277 } // namespace boost
0278 
0279 #endif // BOOST_NO_CXX11_SMART_PTR
0280 
0281 #endif // BOOST_SERIALIZATION_SHARED_PTR_HPP