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

source code of boost/boost/serialization/forward_list.hpp