| 1 | #ifndef BOOST_SERIALIZATION_FORWARD_LIST_HPP |
| 2 | #define BOOST_SERIALIZATION_FORWARD_LIST_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 | // forward_list.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 | |
| 21 | #include <forward_list> |
| 22 | #include <iterator> // distance |
| 23 | |
| 24 | #include <boost/serialization/collections_save_imp.hpp> |
| 25 | #include <boost/serialization/collections_load_imp.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/library_version_type.hpp> |
| 30 | #include <boost/serialization/split_free.hpp> |
| 31 | #include <boost/serialization/detail/stack_constructor.hpp> |
| 32 | #include <boost/serialization/detail/is_default_constructible.hpp> |
| 33 | #include <boost/move/utility_core.hpp> |
| 34 | |
| 35 | namespace boost { |
| 36 | namespace serialization { |
| 37 | |
| 38 | template<class Archive, class U, class Allocator> |
| 39 | inline void save( |
| 40 | Archive & ar, |
| 41 | const std::forward_list<U, Allocator> &t, |
| 42 | const unsigned int /*file_version*/ |
| 43 | ){ |
| 44 | const collection_size_type count(std::distance(t.cbegin(), t.cend())); |
| 45 | boost::serialization::stl::save_collection< |
| 46 | Archive, |
| 47 | std::forward_list<U, Allocator> |
| 48 | >(ar, t, count); |
| 49 | } |
| 50 | |
| 51 | namespace stl { |
| 52 | |
| 53 | template< |
| 54 | class Archive, |
| 55 | class T, |
| 56 | class Allocator |
| 57 | > |
| 58 | typename boost::disable_if< |
| 59 | typename detail::is_default_constructible< |
| 60 | typename std::forward_list<T, Allocator>::value_type |
| 61 | >, |
| 62 | void |
| 63 | >::type |
| 64 | collection_load_impl( |
| 65 | Archive & ar, |
| 66 | std::forward_list<T, Allocator> &t, |
| 67 | collection_size_type count, |
| 68 | item_version_type item_version |
| 69 | ){ |
| 70 | t.clear(); |
| 71 | boost::serialization::detail::stack_construct<Archive, T> u(ar, item_version); |
| 72 | ar >> boost::serialization::make_nvp("item" , u.reference()); |
| 73 | t.push_front(boost::move(u.reference())); |
| 74 | typename std::forward_list<T, Allocator>::iterator last; |
| 75 | last = t.begin(); |
| 76 | ar.reset_object_address(&(*t.begin()) , & u.reference()); |
| 77 | while(--count > 0){ |
| 78 | detail::stack_construct<Archive, T> u(ar, item_version); |
| 79 | ar >> boost::serialization::make_nvp("item" , u.reference()); |
| 80 | last = t.insert_after(last, boost::move(u.reference())); |
| 81 | ar.reset_object_address(&(*last) , & u.reference()); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | } // stl |
| 86 | |
| 87 | template<class Archive, class U, class Allocator> |
| 88 | inline void load( |
| 89 | Archive & ar, |
| 90 | std::forward_list<U, Allocator> &t, |
| 91 | const unsigned int /*file_version*/ |
| 92 | ){ |
| 93 | const boost::serialization::library_version_type library_version( |
| 94 | ar.get_library_version() |
| 95 | ); |
| 96 | // retrieve number of elements |
| 97 | item_version_type item_version(0); |
| 98 | collection_size_type count; |
| 99 | ar >> BOOST_SERIALIZATION_NVP(count); |
| 100 | if(boost::serialization::library_version_type(3) < library_version){ |
| 101 | ar >> BOOST_SERIALIZATION_NVP(item_version); |
| 102 | } |
| 103 | stl::collection_load_impl(ar, t, count, item_version); |
| 104 | } |
| 105 | |
| 106 | // split non-intrusive serialization function member into separate |
| 107 | // non intrusive save/load member functions |
| 108 | template<class Archive, class U, class Allocator> |
| 109 | inline void serialize( |
| 110 | Archive & ar, |
| 111 | std::forward_list<U, Allocator> &t, |
| 112 | const unsigned int file_version |
| 113 | ){ |
| 114 | boost::serialization::split_free(ar, t, file_version); |
| 115 | } |
| 116 | |
| 117 | } // serialization |
| 118 | } // namespace boost |
| 119 | |
| 120 | #include <boost/serialization/collection_traits.hpp> |
| 121 | |
| 122 | BOOST_SERIALIZATION_COLLECTION_TRAITS(std::forward_list) |
| 123 | |
| 124 | #endif // BOOST_SERIALIZATION_FORWARD_LIST_HPP |
| 125 | |