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/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>
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_wrapper.hpp>
35 #include <boost/mpl/bool_fwd.hpp>
36 #include <boost/mpl/if.hpp>
38 // default is being compatible with version 1.34.1 files, not 1.35 files
39 #ifndef BOOST_SERIALIZATION_VECTOR_VERSIONED
40 #define BOOST_SERIALIZATION_VECTOR_VERSIONED(V) (V==4 || V==5)
43 // function specializations must be defined in the appropriate
44 // namespace - boost::serialization
45 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
52 namespace serialization {
54 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
57 // the default versions
59 template<class Archive, class U, class Allocator>
62 const std::vector<U, Allocator> &t,
63 const unsigned int /* file_version */,
66 boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >(
71 template<class Archive, class U, class Allocator>
74 std::vector<U, Allocator> &t,
75 const unsigned int /* file_version */,
78 const boost::archive::library_version_type library_version(
79 ar.get_library_version()
81 // retrieve number of elements
82 item_version_type item_version(0);
83 collection_size_type count;
84 ar >> BOOST_SERIALIZATION_NVP(count);
85 if(boost::archive::library_version_type(3) < library_version){
86 ar >> BOOST_SERIALIZATION_NVP(item_version);
89 stl::collection_load_impl(ar, t, count, item_version);
92 // the optimized versions
94 template<class Archive, class U, class Allocator>
97 const std::vector<U, Allocator> &t,
98 const unsigned int /* file_version */,
101 const collection_size_type count(t.size());
102 ar << BOOST_SERIALIZATION_NVP(count);
104 // explict template arguments to pass intel C++ compiler
105 ar << serialization::make_array<const U, collection_size_type>(
106 static_cast<const U *>(&t[0]),
111 template<class Archive, class U, class Allocator>
114 std::vector<U, Allocator> &t,
115 const unsigned int /* file_version */,
118 collection_size_type count(t.size());
119 ar >> BOOST_SERIALIZATION_NVP(count);
121 unsigned int item_version=0;
122 if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
123 ar >> BOOST_SERIALIZATION_NVP(item_version);
126 // explict template arguments to pass intel C++ compiler
127 ar >> serialization::make_array<U, collection_size_type>(
128 static_cast<U *>(&t[0]),
133 // dispatch to either default or optimized versions
135 template<class Archive, class U, class Allocator>
138 const std::vector<U, Allocator> &t,
139 const unsigned int file_version
142 boost::serialization::use_array_optimization<Archive>::template apply<
143 typename remove_const<U>::type
144 >::type use_optimized;
145 save(ar,t,file_version, use_optimized());
148 template<class Archive, class U, class Allocator>
151 std::vector<U, Allocator> &t,
152 const unsigned int file_version
154 #ifdef BOOST_SERIALIZATION_VECTOR_135_HPP
155 if (ar.get_library_version()==boost::archive::library_version_type(5))
157 load(ar,t,file_version, boost::is_arithmetic<U>());
162 boost::serialization::use_array_optimization<Archive>::template apply<
163 typename remove_const<U>::type
164 >::type use_optimized;
165 load(ar,t,file_version, use_optimized());
168 // split non-intrusive serialization function member into separate
169 // non intrusive save/load member functions
170 template<class Archive, class U, class Allocator>
171 inline void serialize(
173 std::vector<U, Allocator> & t,
174 const unsigned int file_version
176 boost::serialization::split_free(ar, t, file_version);
179 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
181 template<class Archive, class Allocator>
184 const std::vector<bool, Allocator> &t,
185 const unsigned int /* file_version */
187 // record number of elements
188 collection_size_type count (t.size());
189 ar << BOOST_SERIALIZATION_NVP(count);
190 std::vector<bool>::const_iterator it = t.begin();
193 ar << boost::serialization::make_nvp("item", tb);
197 template<class Archive, class Allocator>
200 std::vector<bool, Allocator> &t,
201 const unsigned int /* file_version */
203 // retrieve number of elements
204 collection_size_type count;
205 ar >> BOOST_SERIALIZATION_NVP(count);
207 for(collection_size_type i = collection_size_type(0); i < count; ++i){
209 ar >> boost::serialization::make_nvp("item", b);
214 // split non-intrusive serialization function member into separate
215 // non intrusive save/load member functions
216 template<class Archive, class Allocator>
217 inline void serialize(
219 std::vector<bool, Allocator> & t,
220 const unsigned int file_version
222 boost::serialization::split_free(ar, t, file_version);
228 #include <boost/serialization/collection_traits.hpp>
230 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
233 #endif // BOOST_SERIALIZATION_VECTOR_HPP