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