Brian Silverman | 8867871 | 2018-08-04 23:56:48 -0700 | [diff] [blame^] | 1 | #ifndef BOOST_SERIALIZATION_SLIST_HPP |
| 2 | #define BOOST_SERIALIZATION_SLIST_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 | // slist.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 | #ifdef BOOST_HAS_SLIST |
| 21 | #include BOOST_SLIST_HEADER |
| 22 | |
| 23 | #include <boost/serialization/collections_save_imp.hpp> |
| 24 | #include <boost/serialization/collections_load_imp.hpp> |
| 25 | #include <boost/archive/detail/basic_iarchive.hpp> |
| 26 | #include <boost/serialization/nvp.hpp> |
| 27 | #include <boost/serialization/collection_size_type.hpp> |
| 28 | #include <boost/serialization/item_version_type.hpp> |
| 29 | #include <boost/serialization/split_free.hpp> |
| 30 | #include <boost/serialization/detail/stack_constructor.hpp> |
| 31 | #include <boost/serialization/detail/is_default_constructible.hpp> |
| 32 | #include <boost/move/utility_core.hpp> |
| 33 | |
| 34 | namespace boost { |
| 35 | namespace serialization { |
| 36 | |
| 37 | template<class Archive, class U, class Allocator> |
| 38 | inline void save( |
| 39 | Archive & ar, |
| 40 | const BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t, |
| 41 | const unsigned int file_version |
| 42 | ){ |
| 43 | boost::serialization::stl::save_collection< |
| 44 | Archive, |
| 45 | BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> |
| 46 | >(ar, t); |
| 47 | } |
| 48 | |
| 49 | namespace stl { |
| 50 | |
| 51 | template< |
| 52 | class Archive, |
| 53 | class T, |
| 54 | class Allocator |
| 55 | > |
| 56 | typename boost::disable_if< |
| 57 | typename detail::is_default_constructible< |
| 58 | typename BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator>::value_type |
| 59 | >, |
| 60 | void |
| 61 | >::type |
| 62 | collection_load_impl( |
| 63 | Archive & ar, |
| 64 | BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator> &t, |
| 65 | collection_size_type count, |
| 66 | item_version_type item_version |
| 67 | ){ |
| 68 | t.clear(); |
| 69 | boost::serialization::detail::stack_construct<Archive, T> u(ar, item_version); |
| 70 | ar >> boost::serialization::make_nvp("item", u.reference()); |
| 71 | t.push_front(boost::move(u.reference())); |
| 72 | typename BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator>::iterator last; |
| 73 | last = t.begin(); |
| 74 | ar.reset_object_address(&(*t.begin()) , & u.reference()); |
| 75 | while(--count > 0){ |
| 76 | detail::stack_construct<Archive, T> u(ar, item_version); |
| 77 | ar >> boost::serialization::make_nvp("item", u.reference()); |
| 78 | last = t.insert_after(last, boost::move(u.reference())); |
| 79 | ar.reset_object_address(&(*last) , & u.reference()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | } // stl |
| 84 | |
| 85 | template<class Archive, class U, class Allocator> |
| 86 | inline void load( |
| 87 | Archive & ar, |
| 88 | BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t, |
| 89 | const unsigned int file_version |
| 90 | ){ |
| 91 | const boost::archive::library_version_type library_version( |
| 92 | ar.get_library_version() |
| 93 | ); |
| 94 | // retrieve number of elements |
| 95 | item_version_type item_version(0); |
| 96 | collection_size_type count; |
| 97 | ar >> BOOST_SERIALIZATION_NVP(count); |
| 98 | if(boost::archive::library_version_type(3) < library_version){ |
| 99 | ar >> BOOST_SERIALIZATION_NVP(item_version); |
| 100 | } |
| 101 | if(detail::is_default_constructible<U>()){ |
| 102 | t.resize(count); |
| 103 | typename BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator hint; |
| 104 | hint = t.begin(); |
| 105 | while(count-- > 0){ |
| 106 | ar >> boost::serialization::make_nvp("item", *hint++); |
| 107 | } |
| 108 | } |
| 109 | else{ |
| 110 | t.clear(); |
| 111 | boost::serialization::detail::stack_construct<Archive, U> u(ar, item_version); |
| 112 | ar >> boost::serialization::make_nvp("item", u.reference()); |
| 113 | t.push_front(boost::move(u.reference())); |
| 114 | typename BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last; |
| 115 | last = t.begin(); |
| 116 | ar.reset_object_address(&(*t.begin()) , & u.reference()); |
| 117 | while(--count > 0){ |
| 118 | detail::stack_construct<Archive, U> u(ar, item_version); |
| 119 | ar >> boost::serialization::make_nvp("item", u.reference()); |
| 120 | last = t.insert_after(last, boost::move(u.reference())); |
| 121 | ar.reset_object_address(&(*last) , & u.reference()); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // split non-intrusive serialization function member into separate |
| 127 | // non intrusive save/load member functions |
| 128 | template<class Archive, class U, class Allocator> |
| 129 | inline void serialize( |
| 130 | Archive & ar, |
| 131 | BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t, |
| 132 | const unsigned int file_version |
| 133 | ){ |
| 134 | boost::serialization::split_free(ar, t, file_version); |
| 135 | } |
| 136 | |
| 137 | } // serialization |
| 138 | } // namespace boost |
| 139 | |
| 140 | #include <boost/serialization/collection_traits.hpp> |
| 141 | |
| 142 | BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist) |
| 143 | |
| 144 | #endif // BOOST_HAS_SLIST |
| 145 | #endif // BOOST_SERIALIZATION_SLIST_HPP |