Chris@16
|
1 #ifndef BOOST_SERIALIZATION_ACCESS_HPP
|
Chris@16
|
2 #define BOOST_SERIALIZATION_ACCESS_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@16
|
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
Chris@16
|
10 // access.hpp: interface for serialization system.
|
Chris@16
|
11
|
Chris@16
|
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
Chris@16
|
13 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
15 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
16
|
Chris@16
|
17 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/serialization/pfto.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost {
|
Chris@16
|
24
|
Chris@16
|
25 namespace archive {
|
Chris@16
|
26 namespace detail {
|
Chris@16
|
27 template<class Archive, class T>
|
Chris@16
|
28 class iserializer;
|
Chris@16
|
29 template<class Archive, class T>
|
Chris@16
|
30 class oserializer;
|
Chris@16
|
31 } // namespace detail
|
Chris@16
|
32 } // namespace archive
|
Chris@16
|
33
|
Chris@16
|
34 namespace serialization {
|
Chris@16
|
35
|
Chris@16
|
36 // forward declarations
|
Chris@16
|
37 template<class Archive, class T>
|
Chris@16
|
38 inline void serialize_adl(Archive &, T &, const unsigned int);
|
Chris@16
|
39 namespace detail {
|
Chris@16
|
40 template<class Archive, class T>
|
Chris@16
|
41 struct member_saver;
|
Chris@16
|
42 template<class Archive, class T>
|
Chris@16
|
43 struct member_loader;
|
Chris@16
|
44 } // namespace detail
|
Chris@16
|
45
|
Chris@16
|
46 // use an "accessor class so that we can use:
|
Chris@16
|
47 // "friend class boost::serialization::access;"
|
Chris@16
|
48 // in any serialized class to permit clean, safe access to private class members
|
Chris@16
|
49 // by the serialization system
|
Chris@16
|
50
|
Chris@16
|
51 class access {
|
Chris@16
|
52 public:
|
Chris@16
|
53 // grant access to "real" serialization defaults
|
Chris@16
|
54 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
Chris@16
|
55 public:
|
Chris@16
|
56 #else
|
Chris@16
|
57 template<class Archive, class T>
|
Chris@16
|
58 friend struct detail::member_saver;
|
Chris@16
|
59 template<class Archive, class T>
|
Chris@16
|
60 friend struct detail::member_loader;
|
Chris@16
|
61 template<class Archive, class T>
|
Chris@16
|
62 friend class archive::detail::iserializer;
|
Chris@16
|
63 template<class Archive, class T>
|
Chris@16
|
64 friend class archive::detail::oserializer;
|
Chris@16
|
65 template<class Archive, class T>
|
Chris@16
|
66 friend inline void serialize(
|
Chris@16
|
67 Archive & ar,
|
Chris@16
|
68 T & t,
|
Chris@16
|
69 const BOOST_PFTO unsigned int file_version
|
Chris@16
|
70 );
|
Chris@16
|
71 template<class Archive, class T>
|
Chris@16
|
72 friend inline void save_construct_data(
|
Chris@16
|
73 Archive & ar,
|
Chris@16
|
74 const T * t,
|
Chris@16
|
75 const BOOST_PFTO unsigned int file_version
|
Chris@16
|
76 );
|
Chris@16
|
77 template<class Archive, class T>
|
Chris@16
|
78 friend inline void load_construct_data(
|
Chris@16
|
79 Archive & ar,
|
Chris@16
|
80 T * t,
|
Chris@16
|
81 const BOOST_PFTO unsigned int file_version
|
Chris@16
|
82 );
|
Chris@16
|
83 #endif
|
Chris@16
|
84
|
Chris@16
|
85 // pass calls to users's class implementation
|
Chris@16
|
86 template<class Archive, class T>
|
Chris@16
|
87 static void member_save(
|
Chris@16
|
88 Archive & ar,
|
Chris@16
|
89 //const T & t,
|
Chris@16
|
90 T & t,
|
Chris@16
|
91 const unsigned int file_version
|
Chris@16
|
92 ){
|
Chris@16
|
93 t.save(ar, file_version);
|
Chris@16
|
94 }
|
Chris@16
|
95 template<class Archive, class T>
|
Chris@16
|
96 static void member_load(
|
Chris@16
|
97 Archive & ar,
|
Chris@16
|
98 T & t,
|
Chris@16
|
99 const unsigned int file_version
|
Chris@16
|
100 ){
|
Chris@16
|
101 t.load(ar, file_version);
|
Chris@16
|
102 }
|
Chris@16
|
103 template<class Archive, class T>
|
Chris@16
|
104 static void serialize(
|
Chris@16
|
105 Archive & ar,
|
Chris@16
|
106 T & t,
|
Chris@16
|
107 const unsigned int file_version
|
Chris@16
|
108 ){
|
Chris@16
|
109 // note: if you get a compile time error here with a
|
Chris@16
|
110 // message something like:
|
Chris@16
|
111 // cannot convert parameter 1 from <file type 1> to <file type 2 &>
|
Chris@16
|
112 // a likely possible cause is that the class T contains a
|
Chris@16
|
113 // serialize function - but that serialize function isn't
|
Chris@16
|
114 // a template and corresponds to a file type different than
|
Chris@16
|
115 // the class Archive. To resolve this, don't include an
|
Chris@16
|
116 // archive type other than that for which the serialization
|
Chris@16
|
117 // function is defined!!!
|
Chris@16
|
118 t.serialize(ar, file_version);
|
Chris@16
|
119 }
|
Chris@16
|
120 template<class T>
|
Chris@16
|
121 static void destroy( const T * t) // const appropriate here?
|
Chris@16
|
122 {
|
Chris@16
|
123 // the const business is an MSVC 6.0 hack that should be
|
Chris@16
|
124 // benign on everything else
|
Chris@16
|
125 delete const_cast<T *>(t);
|
Chris@16
|
126 }
|
Chris@16
|
127 template<class T>
|
Chris@16
|
128 static void construct(T * t){
|
Chris@16
|
129 // default is inplace invocation of default constructor
|
Chris@16
|
130 // Note the :: before the placement new. Required if the
|
Chris@16
|
131 // class doesn't have a class-specific placement new defined.
|
Chris@16
|
132 ::new(t)T;
|
Chris@16
|
133 }
|
Chris@16
|
134 template<class T, class U>
|
Chris@16
|
135 static T & cast_reference(U & u){
|
Chris@16
|
136 return static_cast<T &>(u);
|
Chris@16
|
137 }
|
Chris@16
|
138 template<class T, class U>
|
Chris@16
|
139 static T * cast_pointer(U * u){
|
Chris@16
|
140 return static_cast<T *>(u);
|
Chris@16
|
141 }
|
Chris@16
|
142 };
|
Chris@16
|
143
|
Chris@16
|
144 } // namespace serialization
|
Chris@16
|
145 } // namespace boost
|
Chris@16
|
146
|
Chris@16
|
147 #endif // BOOST_SERIALIZATION_ACCESS_HPP
|