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