| 1 | #ifndef BOOST_CORE_SERIALIZATION_HPP_INCLUDED |
| 2 | #define BOOST_CORE_SERIALIZATION_HPP_INCLUDED |
| 3 | |
| 4 | // MS compatible compilers support #pragma once |
| 5 | |
| 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 7 | # pragma once |
| 8 | #endif |
| 9 | |
| 10 | // Copyright 2023 Peter Dimov |
| 11 | // Distributed under the Boost Software License, Version 1.0. |
| 12 | // https://www.boost.org/LICENSE_1_0.txt |
| 13 | // |
| 14 | // Utilities needed to implement serialization support |
| 15 | // without including a Boost.Serialization header |
| 16 | |
| 17 | #include <boost/core/nvp.hpp> |
| 18 | #include <cstddef> |
| 19 | |
| 20 | namespace boost |
| 21 | { |
| 22 | |
| 23 | namespace serialization |
| 24 | { |
| 25 | |
| 26 | // Forward declarations (needed for specializations) |
| 27 | |
| 28 | template<class T> struct version; |
| 29 | |
| 30 | class access; |
| 31 | |
| 32 | // Our own version_type replacement. This has to be in |
| 33 | // the `serialization` namespace, because its only purpose |
| 34 | // is to add `serialization` as an associated namespace. |
| 35 | |
| 36 | struct core_version_type |
| 37 | { |
| 38 | unsigned int version_; |
| 39 | |
| 40 | core_version_type( unsigned int version ): version_( version ) {} |
| 41 | operator unsigned int () const { return version_; } |
| 42 | }; |
| 43 | |
| 44 | } // namespace serialization |
| 45 | |
| 46 | namespace core |
| 47 | { |
| 48 | |
| 49 | // nvp |
| 50 | |
| 51 | using serialization::nvp; |
| 52 | using serialization::make_nvp; |
| 53 | |
| 54 | // split_free |
| 55 | |
| 56 | namespace detail |
| 57 | { |
| 58 | |
| 59 | template<bool IsSaving> struct load_or_save_f; |
| 60 | |
| 61 | template<> struct load_or_save_f<true> |
| 62 | { |
| 63 | template<class A, class T> void operator()( A& a, T& t, unsigned int v ) const |
| 64 | { |
| 65 | save( a, t, serialization::core_version_type( v ) ); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | template<> struct load_or_save_f<false> |
| 70 | { |
| 71 | template<class A, class T> void operator()( A& a, T& t, unsigned int v ) const |
| 72 | { |
| 73 | load( a, t, serialization::core_version_type( v ) ); |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | } // namespace detail |
| 78 | |
| 79 | template<class A, class T> inline void split_free( A& a, T& t, unsigned int v ) |
| 80 | { |
| 81 | detail::load_or_save_f< A::is_saving::value >()( a, t, v ); |
| 82 | } |
| 83 | |
| 84 | // split_member |
| 85 | |
| 86 | namespace detail |
| 87 | { |
| 88 | |
| 89 | template<bool IsSaving, class Access = serialization::access> struct load_or_save_m; |
| 90 | |
| 91 | template<class Access> struct load_or_save_m<true, Access> |
| 92 | { |
| 93 | template<class A, class T> void operator()( A& a, T const& t, unsigned int v ) const |
| 94 | { |
| 95 | Access::member_save( a, t, v ); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | template<class Access> struct load_or_save_m<false, Access> |
| 100 | { |
| 101 | template<class A, class T> void operator()( A& a, T& t, unsigned int v ) const |
| 102 | { |
| 103 | Access::member_load( a, t, v ); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | } // namespace detail |
| 108 | |
| 109 | template<class A, class T> inline void split_member( A& a, T& t, unsigned int v ) |
| 110 | { |
| 111 | detail::load_or_save_m< A::is_saving::value >()( a, t, v ); |
| 112 | } |
| 113 | |
| 114 | // load_construct_data_adl |
| 115 | |
| 116 | template<class Ar, class T> void load_construct_data_adl( Ar& ar, T* t, unsigned int v ) |
| 117 | { |
| 118 | load_construct_data( ar, t, serialization::core_version_type( v ) ); |
| 119 | } |
| 120 | |
| 121 | // save_construct_data_adl |
| 122 | |
| 123 | template<class Ar, class T> void save_construct_data_adl( Ar& ar, T const* t, unsigned int v ) |
| 124 | { |
| 125 | save_construct_data( ar, t, serialization::core_version_type( v ) ); |
| 126 | } |
| 127 | |
| 128 | } // namespace core |
| 129 | } // namespace boost |
| 130 | |
| 131 | #endif // #ifndef BOOST_CORE_SERIALIZATION_HPP_INCLUDED |
| 132 | |