1
<!doctype HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
10 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
11 <link rel=
"stylesheet" type=
"text/css" href=
"../../../boost.css">
12 <link rel=
"stylesheet" type=
"text/css" href=
"style.css">
13 <title>Template serialization - shared_ptr
</title>
15 <body link=
"#0000ff" vlink=
"#800080">
16 <table border=
"0" cellpadding=
"7" cellspacing=
"0" width=
"100%" summary=
"header">
18 <td valign=
"top" width=
"300">
19 <h3><a href=
"../../../index.htm"><img height=
"86" width=
"277" alt=
"C++ Boost" src=
"../../../boost.png" border=
"0"></a></h3>
22 <h1 align=
"center">Serialization
</h1>
23 <h2 align=
"center"><code style=
"white-space: normal">shared_ptr
<class T
></code> Revisited
</h2>
28 The previously described serialization of
<code style=
"white-space: normal">shared_ptr
</code>
29 illustrates the straightforward way of serializing a moderately complicated class structure.
30 Unfortunately, this way of doing it suffered from some undesirable features
32 <li>It was dependent on the Boost implementation of
<code style=
"white-space: normal">shared_ptr
</code>.
33 The
<code style=
"white-space: normal">shared_ptr
</code> interface has been included
34 in
<code style=
"white-space: normal">std::tr1
</code> and may someday be included in the standard
35 C++ library. An implementation which depends only on the public interface can be guaranteed to
36 function with any other future implementation of
<code style=
"white-space: normal">shared_ptr
</code>.
37 <li>It required extra macros for export.
41 template
<class Archive, class T
>
44 const boost::shared_ptr<T
> &t,
45 const unsigned int /* file_version */
47 const T * t_ptr = t.get();
48 // just serialize the underlying raw pointer
49 ar
<<: boost::serialization::make_nvp(
"px", t_ptr);
52 template
<class Archive, class T>
55 boost::shared_ptr
<T
> &t,
56 const unsigned int file_version
59 // recover the underlying raw pointer
60 ar
>> boost::serialization::make_nvp(
"px", r);
62 // To Do - match up with other shared pointers which
63 // use this same raw pointer.
68 In principle, this is very much simpler than the original implementation. Completion of
72 <li>Filling in the
"To Do". This required making an extra map for
73 <code style=
"white-space: normal">shared_ptr
</code> instances.
74 <li>A method for identifying pointers to the same objects from pointers to their base classes.
75 <li>Backward compatibility with pointers serialized by the previous method. This exploits
76 the serialization class versioning.
77 <li>Proper handling of
<code style=
"white-space: normal">weak_ptr
</code>.
80 The result of this effort can be found in
81 <a target = serialization_shared_ptr
href=
"../../../boost/serialization/shared_ptr.hpp">
82 <code style=
"white-space: normal">boost::serialization::shared_ptr.hpp
</code>
85 Note that if your code needs to read archives created under boost version
1.32, you will
86 have to include the following
89 #include
<boost/serialization/shared_ptr_132.hpp
>
90 #include
<boost/serialization/shared_ptr.hpp
>
94 #include
<boost/serialization/shared_ptr.hpp
>
98 <p><i>© Copyright
<a href=
"http://www.rrsd.com">Robert Ramey
</a> 2002-
2004.
99 Distributed under the Boost Software License, Version
1.0. (See
100 accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)