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
33namespace boost {
34namespace serialization {
35
36template<class Archive, class U, class Allocator>
37inline void save(
38 Archive & ar,
39 const BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
40 const unsigned int file_version
41){
42 boost::serialization::stl::save_collection<
43 Archive,
44 BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>
45 >(ar, t);
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 BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator>::value_type
58 >,
59 void
60>::type
61collection_load_impl(
62 Archive & ar,
63 BOOST_STD_EXTENSION_NAMESPACE::slist<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 BOOST_STD_EXTENSION_NAMESPACE::slist<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 BOOST_STD_EXTENSION_NAMESPACE::slist<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 if(detail::is_default_constructible<U>()){
101 t.resize(count);
102 typename BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator hint;
103 hint = t.begin();
104 while(count-- > 0){
105 ar >> boost::serialization::make_nvp("item", *hint++);
106 }
107 }
108 else{
109 t.clear();
110 boost::serialization::detail::stack_construct<Archive, U> u(ar, item_version);
111 ar >> boost::serialization::make_nvp("item", u.reference());
112 t.push_front(u.reference());
113 typename BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last;
114 last = t.begin();
115 ar.reset_object_address(&(*t.begin()) , & u.reference());
116 while(--count > 0){
117 detail::stack_construct<Archive, U> u(ar, item_version);
118 ar >> boost::serialization::make_nvp("item", u.reference());
119 last = t.insert_after(last, u.reference());
120 ar.reset_object_address(&(*last) , & u.reference());
121 }
122 }
123}
124
125// split non-intrusive serialization function member into separate
126// non intrusive save/load member functions
127template<class Archive, class U, class Allocator>
128inline void serialize(
129 Archive & ar,
130 BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
131 const unsigned int file_version
132){
133 boost::serialization::split_free(ar, t, file_version);
134}
135
136} // serialization
137} // namespace boost
138
139#include <boost/serialization/collection_traits.hpp>
140
141BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist)
142
143#endif // BOOST_HAS_SLIST
144#endif // BOOST_SERIALIZATION_SLIST_HPP
145

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