1 #ifndef BOOST_SERIALIZATION_VECTOR_HPP
2 #define BOOST_SERIALIZATION_VECTOR_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // vector.hpp: serialization for stl vector templates
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)
18 // See http://www.boost.org for updates, documentation, and revision history.
22 #include <boost/config.hpp>
23 #include <boost/detail/workaround.hpp>
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>
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>
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)
44 // function specializations must be defined in the appropriate
45 // namespace - boost::serialization
46 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
53 namespace serialization {
55 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
58 // the default versions
60 template<class Archive, class U, class Allocator>
63 const std::vector<U, Allocator> &t,
64 const unsigned int /* file_version */,
67 boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >(
72 template<class Archive, class U, class Allocator>
75 std::vector<U, Allocator> &t,
76 const unsigned int /* file_version */,
79 const boost::serialization::library_version_type library_version(
80 ar.get_library_version()
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);
90 stl::collection_load_impl(ar, t, count, item_version);
93 // the optimized versions
95 template<class Archive, class U, class Allocator>
98 const std::vector<U, Allocator> &t,
99 const unsigned int /* file_version */,
102 const collection_size_type count(t.size());
103 ar << BOOST_SERIALIZATION_NVP(count);
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]),
112 template<class Archive, class U, class Allocator>
115 std::vector<U, Allocator> &t,
116 const unsigned int /* file_version */,
119 collection_size_type count(t.size());
120 ar >> BOOST_SERIALIZATION_NVP(count);
122 unsigned int item_version=0;
123 if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
124 ar >> BOOST_SERIALIZATION_NVP(item_version);
127 // explict template arguments to pass intel C++ compiler
128 ar >> serialization::make_array<U, collection_size_type>(
129 static_cast<U *>(&t[0]),
134 // dispatch to either default or optimized versions
136 template<class Archive, class U, class Allocator>
139 const std::vector<U, Allocator> &t,
140 const unsigned int file_version
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());
149 template<class Archive, class U, class Allocator>
152 std::vector<U, Allocator> &t,
153 const unsigned int file_version
155 #ifdef BOOST_SERIALIZATION_VECTOR_135_HPP
156 if (ar.get_library_version()==boost::serialization::library_version_type(5))
158 load(ar,t,file_version, boost::is_arithmetic<U>());
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());
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(
174 std::vector<U, Allocator> & t,
175 const unsigned int file_version
177 boost::serialization::split_free(ar, t, file_version);
180 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
182 template<class Archive, class Allocator>
185 const std::vector<bool, Allocator> &t,
186 const unsigned int /* file_version */
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();
194 ar << boost::serialization::make_nvp("item", tb);
198 template<class Archive, class Allocator>
201 std::vector<bool, Allocator> &t,
202 const unsigned int /* file_version */
204 // retrieve number of elements
205 collection_size_type count;
206 ar >> BOOST_SERIALIZATION_NVP(count);
208 for(collection_size_type i = collection_size_type(0); i < count; ++i){
210 ar >> boost::serialization::make_nvp("item", b);
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(
220 std::vector<bool, Allocator> & t,
221 const unsigned int file_version
223 boost::serialization::split_free(ar, t, file_version);
229 #include <boost/serialization/collection_traits.hpp>
231 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
234 #endif // BOOST_SERIALIZATION_VECTOR_HPP