source: NonGTP/Boost/boost/serialization/slist.hpp @ 857

Revision 857, 2.8 KB checked in by igarcia, 18 years ago (diff)
Line 
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) && (_MSC_VER >= 1020)
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
22#include <slist>
23#include <boost/serialization/collections_save_imp.hpp>
24#include <boost/serialization/collections_load_imp.hpp>
25#include <boost/serialization/split_free.hpp>
26#include <boost/serialization/nvp.hpp>
27
28#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
29#define STD _STLP_STD
30#else
31#define STD BOOST_STD_EXTENSION_NAMESPACE
32#endif
33
34namespace boost {
35namespace serialization {
36
37template<class Archive, class U, class Allocator>
38inline void save(
39    Archive & ar,
40    const STD::slist<U, Allocator> &t,
41    const unsigned int file_version
42){
43    boost::serialization::stl::save_collection<
44        Archive,
45        STD::slist<U, Allocator>
46    >(ar, t);
47}
48
49template<class Archive, class U, class Allocator>
50inline void load(
51    Archive & ar,
52    STD::slist<U, Allocator> &t,
53    const unsigned int file_version
54){
55    // retrieve number of elements
56    t.clear();
57    // retrieve number of elements
58    unsigned int count;
59    ar >> BOOST_SERIALIZATION_NVP(count);
60    if(0 == count)
61        return;
62
63    boost::serialization::detail::stack_construct<Archive, U> u(ar);
64    ar >> boost::serialization::make_nvp("item", u.reference());
65    t.push_front(u.reference());
66    BOOST_DEDUCED_TYPENAME BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last;
67    last = t.begin();
68    while(--count > 0){
69        boost::serialization::detail::stack_construct<Archive, U> u(ar);
70        ar >> boost::serialization::make_nvp("item", u.reference());
71        last = t.insert_after(last, u.reference());
72        ar.reset_object_address(& (*last), & u.reference());
73    }
74}
75
76// split non-intrusive serialization function member into separate
77// non intrusive save/load member functions
78template<class Archive, class U, class Allocator>
79inline void serialize(
80    Archive & ar,
81    STD::slist<U, Allocator> &t,
82    const unsigned int file_version
83){
84    boost::serialization::split_free(ar, t, file_version);
85}
86
87} // serialization
88} // namespace boost
89
90#include <boost/serialization/collection_traits.hpp>
91
92BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::slist)
93#undef STD
94
95#endif  // BOOST_HAS_SLIST
96#endif  // BOOST_SERIALIZATION_SLIST_HPP
Note: See TracBrowser for help on using the repository browser.