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