Chris@16
|
1 #ifndef BOOST_SERIALIZATION_SERIALIZATION_HPP
|
Chris@16
|
2 #define BOOST_SERIALIZATION_SERIALIZATION_HPP
|
Chris@16
|
3
|
Chris@16
|
4 // MS compatible compilers support #pragma once
|
Chris@101
|
5 #if defined(_MSC_VER)
|
Chris@16
|
6 # pragma once
|
Chris@16
|
7 #endif
|
Chris@16
|
8
|
Chris@101
|
9 #if defined(_MSC_VER)
|
Chris@16
|
10 # pragma warning (disable : 4675) // suppress ADL warning
|
Chris@16
|
11 #endif
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/config.hpp>
|
Chris@16
|
14 #include <boost/serialization/strong_typedef.hpp>
|
Chris@16
|
15 #include <boost/serialization/pfto.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
Chris@16
|
18 // serialization.hpp: interface for serialization system.
|
Chris@16
|
19
|
Chris@16
|
20 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
Chris@16
|
21 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
22 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
23 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
24
|
Chris@16
|
25 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
26
|
Chris@16
|
27 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
28 // public interface to serialization.
|
Chris@16
|
29
|
Chris@16
|
30 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
31 // layer 0 - intrusive verison
|
Chris@16
|
32 // declared and implemented for each user defined class to be serialized
|
Chris@16
|
33 //
|
Chris@16
|
34 // template<Archive>
|
Chris@16
|
35 // serialize(Archive &ar, const unsigned int file_version){
|
Chris@16
|
36 // ar & base_object<base>(*this) & member1 & member2 ... ;
|
Chris@16
|
37 // }
|
Chris@16
|
38
|
Chris@16
|
39 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
40 // layer 1 - layer that routes member access through the access class.
|
Chris@16
|
41 // this is what permits us to grant access to private class member functions
|
Chris@16
|
42 // by specifying friend class boost::serialization::access
|
Chris@16
|
43
|
Chris@16
|
44 #include <boost/serialization/access.hpp>
|
Chris@16
|
45
|
Chris@16
|
46 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
47 // layer 2 - default implementation of non-intrusive serialization.
|
Chris@16
|
48 //
|
Chris@16
|
49 // note the usage of function overloading to compensate that C++ does not
|
Chris@16
|
50 // currently support Partial Template Specialization for function templates
|
Chris@16
|
51 // We have declared the version number as "const unsigned long".
|
Chris@16
|
52 // Overriding templates for specific data types should declare the version
|
Chris@16
|
53 // number as "const unsigned int". Template matching will first be applied
|
Chris@16
|
54 // to functions with the same version types - that is the overloads.
|
Chris@16
|
55 // If there is no declared function prototype that matches, the second argument
|
Chris@16
|
56 // will be converted to "const unsigned long" and a match will be made with
|
Chris@16
|
57 // one of the default template functions below.
|
Chris@16
|
58
|
Chris@16
|
59 namespace boost {
|
Chris@16
|
60 namespace serialization {
|
Chris@16
|
61
|
Chris@16
|
62 BOOST_STRONG_TYPEDEF(unsigned int, version_type)
|
Chris@16
|
63
|
Chris@16
|
64 // default implementation - call the member function "serialize"
|
Chris@16
|
65 template<class Archive, class T>
|
Chris@16
|
66 inline void serialize(
|
Chris@16
|
67 Archive & ar, T & t, const BOOST_PFTO unsigned int file_version
|
Chris@16
|
68 ){
|
Chris@16
|
69 access::serialize(ar, t, static_cast<unsigned int>(file_version));
|
Chris@16
|
70 }
|
Chris@16
|
71
|
Chris@16
|
72 // save data required for construction
|
Chris@16
|
73 template<class Archive, class T>
|
Chris@16
|
74 inline void save_construct_data(
|
Chris@16
|
75 Archive & /*ar*/,
|
Chris@16
|
76 const T * /*t*/,
|
Chris@16
|
77 const BOOST_PFTO unsigned int /*file_version */
|
Chris@16
|
78 ){
|
Chris@16
|
79 // default is to save no data because default constructor
|
Chris@16
|
80 // requires no arguments.
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@16
|
83 // load data required for construction and invoke constructor in place
|
Chris@16
|
84 template<class Archive, class T>
|
Chris@16
|
85 inline void load_construct_data(
|
Chris@16
|
86 Archive & /*ar*/,
|
Chris@16
|
87 T * t,
|
Chris@16
|
88 const BOOST_PFTO unsigned int /*file_version*/
|
Chris@16
|
89 ){
|
Chris@16
|
90 // default just uses the default constructor. going
|
Chris@16
|
91 // through access permits usage of otherwise private default
|
Chris@16
|
92 // constructor
|
Chris@16
|
93 access::construct(t);
|
Chris@16
|
94 }
|
Chris@16
|
95
|
Chris@16
|
96 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
97 // layer 3 - move call into serialization namespace so that ADL will function
|
Chris@16
|
98 // in the manner we desire.
|
Chris@16
|
99 //
|
Chris@16
|
100 // on compilers which don't implement ADL. only the current namespace
|
Chris@16
|
101 // i.e. boost::serialization will be searched.
|
Chris@16
|
102 //
|
Chris@16
|
103 // on compilers which DO implement ADL
|
Chris@16
|
104 // serialize overrides can be in any of the following
|
Chris@16
|
105 //
|
Chris@16
|
106 // 1) same namepace as Archive
|
Chris@16
|
107 // 2) same namespace as T
|
Chris@16
|
108 // 3) boost::serialization
|
Chris@16
|
109 //
|
Chris@16
|
110 // Due to Martin Ecker
|
Chris@16
|
111
|
Chris@16
|
112 template<class Archive, class T>
|
Chris@16
|
113 inline void serialize_adl(
|
Chris@16
|
114 Archive & ar,
|
Chris@16
|
115 T & t,
|
Chris@16
|
116 const unsigned int file_version
|
Chris@16
|
117 ){
|
Chris@16
|
118 // note usage of function overloading to delay final resolution
|
Chris@16
|
119 // until the point of instantiation. This works around the two-phase
|
Chris@16
|
120 // lookup "feature" which inhibits redefintion of a default function
|
Chris@16
|
121 // template implementation. Due to Robert Ramey
|
Chris@16
|
122 //
|
Chris@16
|
123 // Note that this trick generates problems for compiles which don't support
|
Chris@16
|
124 // PFTO, suppress it here. As far as we know, there are no compilers
|
Chris@16
|
125 // which fail to support PFTO while supporting two-phase lookup.
|
Chris@16
|
126 #if ! defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
127 const version_type v(file_version);
|
Chris@16
|
128 serialize(ar, t, v);
|
Chris@16
|
129 #else
|
Chris@16
|
130 serialize(ar, t, file_version);
|
Chris@16
|
131 #endif
|
Chris@16
|
132 }
|
Chris@16
|
133
|
Chris@16
|
134 template<class Archive, class T>
|
Chris@16
|
135 inline void save_construct_data_adl(
|
Chris@16
|
136 Archive & ar,
|
Chris@16
|
137 const T * t,
|
Chris@16
|
138 const unsigned int file_version
|
Chris@16
|
139 ){
|
Chris@16
|
140 // see above
|
Chris@16
|
141 #if ! defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
142 const version_type v(file_version);
|
Chris@16
|
143 save_construct_data(ar, t, v);
|
Chris@16
|
144 #else
|
Chris@16
|
145 save_construct_data(ar, t, file_version);
|
Chris@16
|
146 #endif
|
Chris@16
|
147 }
|
Chris@16
|
148
|
Chris@16
|
149 template<class Archive, class T>
|
Chris@16
|
150 inline void load_construct_data_adl(
|
Chris@16
|
151 Archive & ar,
|
Chris@16
|
152 T * t,
|
Chris@16
|
153 const unsigned int file_version
|
Chris@16
|
154 ){
|
Chris@16
|
155 // see above comment
|
Chris@16
|
156 #if ! defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
157 const version_type v(file_version);
|
Chris@16
|
158 load_construct_data(ar, t, v);
|
Chris@16
|
159 #else
|
Chris@16
|
160 load_construct_data(ar, t, file_version);
|
Chris@16
|
161 #endif
|
Chris@16
|
162 }
|
Chris@16
|
163
|
Chris@16
|
164 } // namespace serialization
|
Chris@16
|
165 } // namespace boost
|
Chris@16
|
166
|
Chris@16
|
167 #endif //BOOST_SERIALIZATION_SERIALIZATION_HPP
|