1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/serialization/shared_ptr.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,241 @@
1.4 +#ifndef BOOST_SERIALIZATION_SHARED_PTR_HPP
1.5 +#define BOOST_SERIALIZATION_SHARED_PTR_HPP
1.6 +
1.7 +// MS compatible compilers support #pragma once
1.8 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1.9 +# pragma once
1.10 +#endif
1.11 +
1.12 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
1.13 +// shared_ptr.hpp: serialization for boost shared pointer
1.14 +
1.15 +// (C) Copyright 2004 Robert Ramey and Martin Ecker
1.16 +// Use, modification and distribution is subject to the Boost Software
1.17 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.18 +// http://www.boost.org/LICENSE_1_0.txt)
1.19 +
1.20 +// See http://www.boost.org for updates, documentation, and revision history.
1.21 +
1.22 +#include <map>
1.23 +
1.24 +#include <boost/config.hpp>
1.25 +#include <boost/mpl/integral_c.hpp>
1.26 +#include <boost/mpl/integral_c_tag.hpp>
1.27 +
1.28 +#include <boost/detail/workaround.hpp>
1.29 +#include <boost/shared_ptr.hpp>
1.30 +#include <boost/throw_exception.hpp>
1.31 +
1.32 +#include <boost/archive/archive_exception.hpp>
1.33 +
1.34 +#include <boost/serialization/type_info_implementation.hpp>
1.35 +#include <boost/serialization/split_free.hpp>
1.36 +#include <boost/serialization/nvp.hpp>
1.37 +#include <boost/serialization/version.hpp>
1.38 +#include <boost/serialization/tracking.hpp>
1.39 +#include <boost/static_assert.hpp>
1.40 +
1.41 +#include <boost/serialization/void_cast_fwd.hpp>
1.42 +
1.43 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
1.44 +// shared_ptr serialization traits
1.45 +// version 1 to distinguish from boost 1.32 version. Note: we can only do this
1.46 +// for a template when the compiler supports partial template specialization
1.47 +
1.48 +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.49 + namespace boost {
1.50 + namespace serialization{
1.51 + template<class T>
1.52 + struct version< ::boost::shared_ptr<T> > {
1.53 + typedef mpl::integral_c_tag tag;
1.54 +#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
1.55 + typedef BOOST_DEDUCED_TYPENAME mpl::int_<1> type;
1.56 +#else
1.57 + typedef mpl::int_<1> type;
1.58 +#endif
1.59 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
1.60 + BOOST_STATIC_CONSTANT(unsigned int, value = 1);
1.61 +#else
1.62 + BOOST_STATIC_CONSTANT(unsigned int, value = type::value);
1.63 +#endif
1.64 + };
1.65 + // don't track shared pointers
1.66 + template<class T>
1.67 + struct tracking_level< ::boost::shared_ptr<T> > {
1.68 + typedef mpl::integral_c_tag tag;
1.69 +#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
1.70 + typedef BOOST_DEDUCED_TYPENAME mpl::int_< ::boost::serialization::track_never> type;
1.71 +#else
1.72 + typedef mpl::int_< ::boost::serialization::track_never> type;
1.73 +#endif
1.74 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
1.75 + BOOST_STATIC_CONSTANT(int, value = ::boost::serialization::track_never);
1.76 +#else
1.77 + BOOST_STATIC_CONSTANT(int, value = type::value);
1.78 +#endif
1.79 + };
1.80 + }}
1.81 + #define BOOST_SERIALIZATION_SHARED_PTR(T)
1.82 +#else
1.83 + // define macro to let users of these compilers do this
1.84 + #define BOOST_SERIALIZATION_SHARED_PTR(T) \
1.85 + BOOST_CLASS_VERSION( \
1.86 + ::boost::shared_ptr< T >, \
1.87 + 1 \
1.88 + ) \
1.89 + BOOST_CLASS_TRACKING( \
1.90 + ::boost::shared_ptr< T >, \
1.91 + ::boost::serialization::track_never \
1.92 + ) \
1.93 + /**/
1.94 +#endif
1.95 +
1.96 +namespace boost {
1.97 +namespace serialization{
1.98 +
1.99 +class extended_type_info;
1.100 +
1.101 +namespace detail {
1.102 +
1.103 +struct null_deleter {
1.104 + void operator()(void const *) const {}
1.105 +};
1.106 +
1.107 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
1.108 +// a common class for holding various types of shared pointers
1.109 +
1.110 +class shared_ptr_helper {
1.111 + typedef std::map<void*, shared_ptr<void> > collection_type;
1.112 + typedef collection_type::const_iterator iterator_type;
1.113 + // list of shared_pointers create accessable by raw pointer. This
1.114 + // is used to "match up" shared pointers loaded at diferent
1.115 + // points in the archive
1.116 + collection_type m_pointers;
1.117 + // return a void pointer to the most derived type
1.118 + template<class T>
1.119 + void * object_identifier(T * t) const {
1.120 + const extended_type_info * true_type
1.121 + = type_info_implementation<T>::type::get_derived_extended_type_info(*t);
1.122 + // note:if this exception is thrown, be sure that derived pointer
1.123 + // is either regsitered or exported.
1.124 + if(NULL == true_type)
1.125 + boost::throw_exception(
1.126 + boost::archive::archive_exception(
1.127 + boost::archive::archive_exception::unregistered_class
1.128 + )
1.129 + );
1.130 + const boost::serialization::extended_type_info * this_type
1.131 + = boost::serialization::type_info_implementation<T>::type::get_instance();
1.132 + void * vp = void_downcast(*true_type, *this_type, t);
1.133 + return vp;
1.134 + }
1.135 +public:
1.136 + template<class T>
1.137 + void reset(shared_ptr<T> & s, T * r){
1.138 + if(NULL == r){
1.139 + s.reset();
1.140 + return;
1.141 + }
1.142 + // get pointer to the most derived object. This is effectively
1.143 + // the object identifer
1.144 + void * od = object_identifier(r);
1.145 +
1.146 + iterator_type it = m_pointers.find(od);
1.147 +
1.148 + if(it == m_pointers.end()){
1.149 + s.reset(r);
1.150 + m_pointers.insert(collection_type::value_type(od,s));
1.151 + }
1.152 + else{
1.153 + s = static_pointer_cast<T>((*it).second);
1.154 + }
1.155 + }
1.156 + virtual ~shared_ptr_helper(){}
1.157 +};
1.158 +
1.159 +} // namespace detail
1.160 +
1.161 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
1.162 +// utility function for creating/getting a helper - could be useful in general
1.163 +// but shared_ptr is the only class (so far that needs it) and I don't have a
1.164 +// convenient header to place it into.
1.165 +template<class Archive, class H>
1.166 +H &
1.167 +get_helper(Archive & ar){
1.168 + extended_type_info * eti = type_info_implementation<H>::type::get_instance();
1.169 + shared_ptr<void> sph;
1.170 + ar.lookup_helper(eti, sph);
1.171 + if(NULL == sph.get()){
1.172 + sph = shared_ptr<H>(new H);
1.173 + ar.insert_helper(eti, sph);
1.174 + }
1.175 + return * static_cast<H *>(sph.get());
1.176 +}
1.177 +
1.178 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
1.179 +// serialization for shared_ptr
1.180 +
1.181 +template<class Archive, class T>
1.182 +inline void save(
1.183 + Archive & ar,
1.184 + const boost::shared_ptr<T> &t,
1.185 + const unsigned int /* file_version */
1.186 +){
1.187 + // The most common cause of trapping here would be serializing
1.188 + // something like shared_ptr<int>. This occurs because int
1.189 + // is never tracked by default. Wrap int in a trackable type
1.190 + BOOST_STATIC_ASSERT((tracking_level<T>::value != track_never));
1.191 + const T * t_ptr = t.get();
1.192 + ar << boost::serialization::make_nvp("px", t_ptr);
1.193 +}
1.194 +
1.195 +template<class Archive, class T>
1.196 +inline void load(
1.197 + Archive & ar,
1.198 + boost::shared_ptr<T> &t,
1.199 + const unsigned int file_version
1.200 +){
1.201 + // The most common cause of trapping here would be serializing
1.202 + // something like shared_ptr<int>. This occurs because int
1.203 + // is never tracked by default. Wrap int in a trackable type
1.204 + BOOST_STATIC_ASSERT((tracking_level<T>::value != track_never));
1.205 + T* r;
1.206 + #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
1.207 + if(file_version < 1){
1.208 + ar.register_type(static_cast<
1.209 + boost_132::detail::sp_counted_base_impl<T *, boost::checked_deleter<T> > *
1.210 + >(NULL));
1.211 + boost_132::shared_ptr<T> sp;
1.212 + ar >> boost::serialization::make_nvp("px", sp.px);
1.213 + ar >> boost::serialization::make_nvp("pn", sp.pn);
1.214 + // got to keep the sps around so the sp.pns don't disappear
1.215 + get_helper<Archive, boost_132::serialization::detail::shared_ptr_helper>(ar).append(sp);
1.216 + r = sp.get();
1.217 + }
1.218 + else
1.219 + #endif
1.220 + {
1.221 + ar >> boost::serialization::make_nvp("px", r);
1.222 + }
1.223 + get_helper<Archive, detail::shared_ptr_helper >(ar).reset(t,r);
1.224 +}
1.225 +
1.226 +template<class Archive, class T>
1.227 +inline void serialize(
1.228 + Archive & ar,
1.229 + boost::shared_ptr<T> &t,
1.230 + const unsigned int file_version
1.231 +){
1.232 + // correct shared_ptr serialization depends upon object tracking
1.233 + // being used.
1.234 + BOOST_STATIC_ASSERT(
1.235 + boost::serialization::tracking_level<T>::value
1.236 + != boost::serialization::track_never
1.237 + );
1.238 + boost::serialization::split_free(ar, t, file_version);
1.239 +}
1.240 +
1.241 +} // namespace serialization
1.242 +} // namespace boost
1.243 +
1.244 +#endif // BOOST_SERIALIZATION_SHARED_PTR_HPP