• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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 #include <boost/move/utility_core.hpp>
32 
33 namespace boost {
34 namespace serialization {
35 
36 template<class Archive, class U, class Allocator>
save(Archive & ar,const BOOST_STD_EXTENSION_NAMESPACE::slist<U,Allocator> & t,const unsigned int file_version)37 inline 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 
48 namespace stl {
49 
50 template<
51     class Archive,
52     class T,
53     class Allocator
54 >
55 typename 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
collection_load_impl(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::slist<T,Allocator> & t,collection_size_type count,item_version_type item_version)61 collection_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(boost::move(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, boost::move(u.reference()));
78         ar.reset_object_address(&(*last) , & u.reference());
79     }
80 }
81 
82 } // stl
83 
84 template<class Archive, class U, class Allocator>
load(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::slist<U,Allocator> & t,const unsigned int file_version)85 inline void load(
86     Archive & ar,
87     BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
88     const unsigned int file_version
89 ){
90     const boost::serialization::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::serialization::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(boost::move(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, boost::move(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
127 template<class Archive, class U, class Allocator>
serialize(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::slist<U,Allocator> & t,const unsigned int file_version)128 inline 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 
141 BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist)
142 
143 #endif  // BOOST_HAS_SLIST
144 #endif  // BOOST_SERIALIZATION_SLIST_HPP
145