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