fix doc example typo
[boost.git] / boost / serialization / slist.hpp
blob0a03acf92beb41520beaf29e8662966eb382e751
1 #ifndef BOOST_SERIALIZATION_SLIST_HPP
2 #define BOOST_SERIALIZATION_SLIST_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // slist.hpp
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)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 #include <cstddef> // size_t
20 #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
21 #if defined(BOOST_NO_STDC_NAMESPACE)
22 namespace std{
23 using ::size_t;
24 } // namespace std
25 #endif
27 #ifdef BOOST_HAS_SLIST
28 #include BOOST_SLIST_HEADER
30 #include <boost/serialization/collections_save_imp.hpp>
31 #include <boost/serialization/collections_load_imp.hpp>
32 #include <boost/serialization/split_free.hpp>
33 #include <boost/serialization/nvp.hpp>
35 namespace boost {
36 namespace serialization {
38 template<class Archive, class U, class Allocator>
39 inline void save(
40 Archive & ar,
41 const BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
42 const unsigned int file_version
44 boost::serialization::stl::save_collection<
45 Archive,
46 BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>
47 >(ar, t);
50 template<class Archive, class U, class Allocator>
51 inline void load(
52 Archive & ar,
53 BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
54 const unsigned int file_version
56 // retrieve number of elements
57 t.clear();
58 // retrieve number of elements
59 collection_size_type count;
60 ar >> BOOST_SERIALIZATION_NVP(count);
61 if(std::size_t(0) == count)
62 return;
63 unsigned int v;
64 if(3 < ar.get_library_version()){
65 ar >> boost::serialization::make_nvp("item_version", v);
67 boost::serialization::detail::stack_construct<Archive, U> u(ar, v);
68 ar >> boost::serialization::make_nvp("item", u.reference());
69 t.push_front(u.reference());
70 BOOST_DEDUCED_TYPENAME BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last;
71 last = t.begin();
72 std::size_t c = count;
73 while(--c > 0){
74 boost::serialization::detail::stack_construct<Archive, U>
75 u(ar, file_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());
82 // split non-intrusive serialization function member into separate
83 // non intrusive save/load member functions
84 template<class Archive, class U, class Allocator>
85 inline void serialize(
86 Archive & ar,
87 BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
88 const unsigned int file_version
90 boost::serialization::split_free(ar, t, file_version);
93 } // serialization
94 } // namespace boost
96 #include <boost/serialization/collection_traits.hpp>
98 BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist)
100 #endif // BOOST_HAS_SLIST
101 #endif // BOOST_SERIALIZATION_SLIST_HPP