source: NonGTP/Boost/boost/serialization/serialization.hpp @ 857

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