1 | #ifndef BOOST_SERIALIZATION_SPLIT_FREE_HPP |
2 | #define BOOST_SERIALIZATION_SPLIT_FREE_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 | // split_free.hpp: |
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 | #include <boost/mpl/eval_if.hpp> |
21 | #include <boost/mpl/identity.hpp> |
22 | #include <boost/serialization/serialization.hpp> |
23 | |
24 | namespace boost { |
25 | namespace archive { |
26 | namespace detail { |
27 | template<class Archive> class interface_oarchive; |
28 | template<class Archive> class interface_iarchive; |
29 | } // namespace detail |
30 | } // namespace archive |
31 | |
32 | namespace serialization { |
33 | |
34 | template<class Archive, class T> |
35 | struct free_saver { |
36 | static void invoke( |
37 | Archive & ar, |
38 | const T & t, |
39 | const unsigned int file_version |
40 | ){ |
41 | // use function overload (version_type) to workaround |
42 | // two-phase lookup issue |
43 | const version_type v(file_version); |
44 | save(ar, t, v); |
45 | } |
46 | }; |
47 | template<class Archive, class T> |
48 | struct free_loader { |
49 | static void invoke( |
50 | Archive & ar, |
51 | T & t, |
52 | const unsigned int file_version |
53 | ){ |
54 | // use function overload (version_type) to workaround |
55 | // two-phase lookup issue |
56 | const version_type v(file_version); |
57 | load(ar, t, v); |
58 | } |
59 | }; |
60 | |
61 | template<class Archive, class T> |
62 | inline void split_free( |
63 | Archive & ar, |
64 | T & t, |
65 | const unsigned int file_version |
66 | ){ |
67 | typedef typename mpl::eval_if< |
68 | typename Archive::is_saving, |
69 | mpl::identity</* detail:: */ free_saver<Archive, T> >, |
70 | mpl::identity</* detail:: */ free_loader<Archive, T> > |
71 | >::type typex; |
72 | typex::invoke(ar, t, file_version); |
73 | } |
74 | |
75 | } // namespace serialization |
76 | } // namespace boost |
77 | |
78 | #define BOOST_SERIALIZATION_SPLIT_FREE(T) \ |
79 | namespace boost { namespace serialization { \ |
80 | template<class Archive> \ |
81 | inline void serialize( \ |
82 | Archive & ar, \ |
83 | T & t, \ |
84 | const unsigned int file_version \ |
85 | ){ \ |
86 | split_free(ar, t, file_version); \ |
87 | } \ |
88 | }} |
89 | /**/ |
90 | |
91 | #endif // BOOST_SERIALIZATION_SPLIT_FREE_HPP |
92 | |