Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/serialization/vector.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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) && (_MSC_VER >= 1020) | |
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 #include <boost/type_traits/is_arithmetic.hpp> | |
25 | |
26 #include <boost/serialization/collections_save_imp.hpp> | |
27 #include <boost/serialization/collections_load_imp.hpp> | |
28 #include <boost/serialization/split_free.hpp> | |
29 #include <boost/serialization/array.hpp> | |
30 #include <boost/serialization/detail/get_data.hpp> | |
31 #include <boost/mpl/bool.hpp> | |
32 | |
33 // default is being compatible with version 1.34.1 files, not 1.35 files | |
34 #ifndef BOOST_SERIALIZATION_VECTOR_VERSIONED | |
35 #define BOOST_SERIALIZATION_VECTOR_VERSIONED(V) (V==4 || V==5) | |
36 #endif | |
37 | |
38 // function specializations must be defined in the appropriate | |
39 // namespace - boost::serialization | |
40 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) | |
41 #define STD _STLP_STD | |
42 #else | |
43 #define STD std | |
44 #endif | |
45 | |
46 namespace boost { | |
47 namespace serialization { | |
48 | |
49 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
50 // vector< T > | |
51 | |
52 // the default versions | |
53 | |
54 template<class Archive, class U, class Allocator> | |
55 inline void save( | |
56 Archive & ar, | |
57 const std::vector<U, Allocator> &t, | |
58 const unsigned int /* file_version */, | |
59 mpl::false_ | |
60 ){ | |
61 boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >( | |
62 ar, t | |
63 ); | |
64 } | |
65 | |
66 template<class Archive, class U, class Allocator> | |
67 inline void load( | |
68 Archive & ar, | |
69 std::vector<U, Allocator> &t, | |
70 const unsigned int /* file_version */, | |
71 mpl::false_ | |
72 ){ | |
73 boost::serialization::stl::load_collection< | |
74 Archive, | |
75 std::vector<U, Allocator>, | |
76 boost::serialization::stl::archive_input_seq< | |
77 Archive, STD::vector<U, Allocator> | |
78 >, | |
79 boost::serialization::stl::reserve_imp<STD::vector<U, Allocator> > | |
80 >(ar, t); | |
81 } | |
82 | |
83 // the optimized versions | |
84 | |
85 template<class Archive, class U, class Allocator> | |
86 inline void save( | |
87 Archive & ar, | |
88 const std::vector<U, Allocator> &t, | |
89 const unsigned int /* file_version */, | |
90 mpl::true_ | |
91 ){ | |
92 const collection_size_type count(t.size()); | |
93 ar << BOOST_SERIALIZATION_NVP(count); | |
94 if (!t.empty()) | |
95 ar << make_array(detail::get_data(t),t.size()); | |
96 } | |
97 | |
98 template<class Archive, class U, class Allocator> | |
99 inline void load( | |
100 Archive & ar, | |
101 std::vector<U, Allocator> &t, | |
102 const unsigned int /* file_version */, | |
103 mpl::true_ | |
104 ){ | |
105 collection_size_type count(t.size()); | |
106 ar >> BOOST_SERIALIZATION_NVP(count); | |
107 t.resize(count); | |
108 unsigned int item_version=0; | |
109 if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) { | |
110 ar >> BOOST_SERIALIZATION_NVP(item_version); | |
111 } | |
112 if (!t.empty()) | |
113 ar >> make_array(detail::get_data(t),t.size()); | |
114 } | |
115 | |
116 // dispatch to either default or optimized versions | |
117 | |
118 template<class Archive, class U, class Allocator> | |
119 inline void save( | |
120 Archive & ar, | |
121 const std::vector<U, Allocator> &t, | |
122 const unsigned int file_version | |
123 ){ | |
124 typedef BOOST_DEDUCED_TYPENAME | |
125 boost::serialization::use_array_optimization<Archive>::template apply< | |
126 BOOST_DEDUCED_TYPENAME remove_const<U>::type | |
127 >::type use_optimized; | |
128 save(ar,t,file_version, use_optimized()); | |
129 } | |
130 | |
131 template<class Archive, class U, class Allocator> | |
132 inline void load( | |
133 Archive & ar, | |
134 std::vector<U, Allocator> &t, | |
135 const unsigned int file_version | |
136 ){ | |
137 #ifdef BOOST_SERIALIZATION_VECTOR_135_HPP | |
138 if (ar.get_library_version()==boost::archive::library_version_type(5)) | |
139 { | |
140 load(ar,t,file_version, boost::is_arithmetic<U>()); | |
141 return; | |
142 } | |
143 #endif | |
144 typedef BOOST_DEDUCED_TYPENAME | |
145 boost::serialization::use_array_optimization<Archive>::template apply< | |
146 BOOST_DEDUCED_TYPENAME remove_const<U>::type | |
147 >::type use_optimized; | |
148 load(ar,t,file_version, use_optimized()); | |
149 } | |
150 | |
151 // split non-intrusive serialization function member into separate | |
152 // non intrusive save/load member functions | |
153 template<class Archive, class U, class Allocator> | |
154 inline void serialize( | |
155 Archive & ar, | |
156 std::vector<U, Allocator> & t, | |
157 const unsigned int file_version | |
158 ){ | |
159 boost::serialization::split_free(ar, t, file_version); | |
160 } | |
161 | |
162 #if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1300) | |
163 | |
164 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
165 // vector<bool> | |
166 template<class Archive, class Allocator> | |
167 inline void save( | |
168 Archive & ar, | |
169 const std::vector<bool, Allocator> &t, | |
170 const unsigned int /* file_version */ | |
171 ){ | |
172 // record number of elements | |
173 collection_size_type count (t.size()); | |
174 ar << BOOST_SERIALIZATION_NVP(count); | |
175 std::vector<bool>::const_iterator it = t.begin(); | |
176 while(count-- > 0){ | |
177 bool tb = *it++; | |
178 ar << boost::serialization::make_nvp("item", tb); | |
179 } | |
180 } | |
181 | |
182 template<class Archive, class Allocator> | |
183 inline void load( | |
184 Archive & ar, | |
185 std::vector<bool, Allocator> &t, | |
186 const unsigned int /* file_version */ | |
187 ){ | |
188 // retrieve number of elements | |
189 collection_size_type count; | |
190 ar >> BOOST_SERIALIZATION_NVP(count); | |
191 t.clear(); | |
192 while(count-- > 0){ | |
193 bool i; | |
194 ar >> boost::serialization::make_nvp("item", i); | |
195 t.push_back(i); | |
196 } | |
197 } | |
198 | |
199 // split non-intrusive serialization function member into separate | |
200 // non intrusive save/load member functions | |
201 template<class Archive, class Allocator> | |
202 inline void serialize( | |
203 Archive & ar, | |
204 std::vector<bool, Allocator> & t, | |
205 const unsigned int file_version | |
206 ){ | |
207 boost::serialization::split_free(ar, t, file_version); | |
208 } | |
209 | |
210 #endif // BOOST_WORKAROUND | |
211 | |
212 } // serialization | |
213 } // namespace boost | |
214 | |
215 #include <boost/serialization/collection_traits.hpp> | |
216 | |
217 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector) | |
218 #undef STD | |
219 | |
220 #endif // BOOST_SERIALIZATION_VECTOR_HPP |