]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/include/boost/serialization/vector.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / include / boost / serialization / vector.hpp
1 #ifndef BOOST_SERIALIZATION_VECTOR_HPP
2 #define BOOST_SERIALIZATION_VECTOR_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 // vector.hpp: serialization for stl vector templates
11
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // fast array serialization (C) Copyright 2005 Matthias Troyer
14 // Use, modification and distribution is subject to the Boost Software
15 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
17
18 // See http://www.boost.org for updates, documentation, and revision history.
19
20 #include <vector>
21
22 #include <boost/config.hpp>
23 #include <boost/detail/workaround.hpp>
24
25 #include <boost/archive/detail/basic_iarchive.hpp>
26 #include <boost/serialization/access.hpp>
27 #include <boost/serialization/nvp.hpp>
28 #include <boost/serialization/collection_size_type.hpp>
29 #include <boost/serialization/item_version_type.hpp>
30
31 #include <boost/serialization/collections_save_imp.hpp>
32 #include <boost/serialization/collections_load_imp.hpp>
33 #include <boost/serialization/split_free.hpp>
34 #include <boost/serialization/array.hpp>
35 #include <boost/serialization/detail/get_data.hpp>
36 #include <boost/serialization/detail/stack_constructor.hpp>
37 #include <boost/mpl/bool_fwd.hpp>
38 #include <boost/mpl/if.hpp>
39
40 // default is being compatible with version 1.34.1 files, not 1.35 files
41 #ifndef BOOST_SERIALIZATION_VECTOR_VERSIONED
42 #define BOOST_SERIALIZATION_VECTOR_VERSIONED(V) (V==4 || V==5)
43 #endif
44
45 // function specializations must be defined in the appropriate
46 // namespace - boost::serialization
47 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
48 #define STD _STLP_STD
49 #else
50 #define STD std
51 #endif
52
53 namespace boost {
54 namespace serialization {
55
56 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
57 // vector< T >
58
59 // the default versions
60
61 template<class Archive, class U, class Allocator>
62 inline void save(
63 Archive & ar,
64 const std::vector<U, Allocator> &t,
65 const unsigned int /* file_version */,
66 mpl::false_
67 ){
68 boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >(
69 ar, t
70 );
71 }
72
73 template<class Archive, class U, class Allocator>
74 inline void load(
75 Archive & ar,
76 std::vector<U, Allocator> &t,
77 const unsigned int /* file_version */,
78 mpl::false_
79 ){
80 const boost::archive::library_version_type library_version(
81 ar.get_library_version()
82 );
83 // retrieve number of elements
84 item_version_type item_version(0);
85 collection_size_type count;
86 ar >> BOOST_SERIALIZATION_NVP(count);
87 if(boost::archive::library_version_type(3) < library_version){
88 ar >> BOOST_SERIALIZATION_NVP(item_version);
89 }
90 t.reserve(count);
91 stl::collection_load_impl(ar, t, count, item_version);
92 }
93
94 // the optimized versions
95
96 template<class Archive, class U, class Allocator>
97 inline void save(
98 Archive & ar,
99 const std::vector<U, Allocator> &t,
100 const unsigned int /* file_version */,
101 mpl::true_
102 ){
103 const collection_size_type count(t.size());
104 ar << BOOST_SERIALIZATION_NVP(count);
105 if (!t.empty())
106 ar << boost::serialization::make_array(detail::get_data(t),t.size());
107 }
108
109 template<class Archive, class U, class Allocator>
110 inline void load(
111 Archive & ar,
112 std::vector<U, Allocator> &t,
113 const unsigned int /* file_version */,
114 mpl::true_
115 ){
116 collection_size_type count(t.size());
117 ar >> BOOST_SERIALIZATION_NVP(count);
118 t.resize(count);
119 unsigned int item_version=0;
120 if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
121 ar >> BOOST_SERIALIZATION_NVP(item_version);
122 }
123 if (!t.empty())
124 ar >> boost::serialization::make_array(detail::get_data(t),t.size());
125 }
126
127 // dispatch to either default or optimized versions
128
129 template<class Archive, class U, class Allocator>
130 inline void save(
131 Archive & ar,
132 const std::vector<U, Allocator> &t,
133 const unsigned int file_version
134 ){
135 typedef typename
136 boost::serialization::use_array_optimization<Archive>::template apply<
137 typename remove_const<U>::type
138 >::type use_optimized;
139 save(ar,t,file_version, use_optimized());
140 }
141
142 template<class Archive, class U, class Allocator>
143 inline void load(
144 Archive & ar,
145 std::vector<U, Allocator> &t,
146 const unsigned int file_version
147 ){
148 #ifdef BOOST_SERIALIZATION_VECTOR_135_HPP
149 if (ar.get_library_version()==boost::archive::library_version_type(5))
150 {
151 load(ar,t,file_version, boost::is_arithmetic<U>());
152 return;
153 }
154 #endif
155 typedef typename
156 boost::serialization::use_array_optimization<Archive>::template apply<
157 typename remove_const<U>::type
158 >::type use_optimized;
159 load(ar,t,file_version, use_optimized());
160 }
161
162 // split non-intrusive serialization function member into separate
163 // non intrusive save/load member functions
164 template<class Archive, class U, class Allocator>
165 inline void serialize(
166 Archive & ar,
167 std::vector<U, Allocator> & t,
168 const unsigned int file_version
169 ){
170 boost::serialization::split_free(ar, t, file_version);
171 }
172
173 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
174 // vector<bool>
175 template<class Archive, class Allocator>
176 inline void save(
177 Archive & ar,
178 const std::vector<bool, Allocator> &t,
179 const unsigned int /* file_version */
180 ){
181 // record number of elements
182 collection_size_type count (t.size());
183 ar << BOOST_SERIALIZATION_NVP(count);
184 std::vector<bool>::const_iterator it = t.begin();
185 while(count-- > 0){
186 bool tb = *it++;
187 ar << boost::serialization::make_nvp("item", tb);
188 }
189 }
190
191 template<class Archive, class Allocator>
192 inline void load(
193 Archive & ar,
194 std::vector<bool, Allocator> &t,
195 const unsigned int /* file_version */
196 ){
197 // retrieve number of elements
198 collection_size_type count;
199 ar >> BOOST_SERIALIZATION_NVP(count);
200 t.resize(count);
201 for(collection_size_type i = collection_size_type(0); i < count; ++i){
202 bool b;
203 ar >> boost::serialization::make_nvp("item", b);
204 t[i] = b;
205 }
206 }
207
208 // split non-intrusive serialization function member into separate
209 // non intrusive save/load member functions
210 template<class Archive, class Allocator>
211 inline void serialize(
212 Archive & ar,
213 std::vector<bool, Allocator> & t,
214 const unsigned int file_version
215 ){
216 boost::serialization::split_free(ar, t, file_version);
217 }
218
219 } // serialization
220 } // namespace boost
221
222 #include <boost/serialization/collection_traits.hpp>
223
224 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
225 #undef STD
226
227 #endif // BOOST_SERIALIZATION_VECTOR_HPP