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