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.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>
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)
45 // function specializations must be defined in the appropriate
46 // namespace - boost::serialization
47 #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
54 namespace serialization {
56 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
59 // the default versions
61 template<class Archive, class U, class Allocator>
64 const std::vector<U, Allocator> &t,
65 const unsigned int /* file_version */,
68 boost::serialization::stl::save_collection<Archive, STD::vector<U, Allocator> >(
73 template<class Archive, class U, class Allocator>
76 std::vector<U, Allocator> &t,
77 const unsigned int /* file_version */,
80 const boost::archive::library_version_type library_version(
81 ar.get_library_version()
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);
91 stl::collection_load_impl(ar, t, count, item_version);
94 // the optimized versions
96 template<class Archive, class U, class Allocator>
99 const std::vector<U, Allocator> &t,
100 const unsigned int /* file_version */,
103 const collection_size_type count(t.size());
104 ar << BOOST_SERIALIZATION_NVP(count);
106 ar << boost::serialization::make_array(detail::get_data(t),t.size());
109 template<class Archive, class U, class Allocator>
112 std::vector<U, Allocator> &t,
113 const unsigned int /* file_version */,
116 collection_size_type count(t.size());
117 ar >> BOOST_SERIALIZATION_NVP(count);
119 unsigned int item_version=0;
120 if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
121 ar >> BOOST_SERIALIZATION_NVP(item_version);
124 ar >> boost::serialization::make_array(detail::get_data(t),t.size());
127 // dispatch to either default or optimized versions
129 template<class Archive, class U, class Allocator>
132 const std::vector<U, Allocator> &t,
133 const unsigned int file_version
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());
142 template<class Archive, class U, class Allocator>
145 std::vector<U, Allocator> &t,
146 const unsigned int file_version
148 #ifdef BOOST_SERIALIZATION_VECTOR_135_HPP
149 if (ar.get_library_version()==boost::archive::library_version_type(5))
151 load(ar,t,file_version, boost::is_arithmetic<U>());
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());
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(
167 std::vector<U, Allocator> & t,
168 const unsigned int file_version
170 boost::serialization::split_free(ar, t, file_version);
173 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
175 template<class Archive, class Allocator>
178 const std::vector<bool, Allocator> &t,
179 const unsigned int /* file_version */
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();
187 ar << boost::serialization::make_nvp("item", tb);
191 template<class Archive, class Allocator>
194 std::vector<bool, Allocator> &t,
195 const unsigned int /* file_version */
197 // retrieve number of elements
198 collection_size_type count;
199 ar >> BOOST_SERIALIZATION_NVP(count);
201 for(collection_size_type i = collection_size_type(0); i < count; ++i){
203 ar >> boost::serialization::make_nvp("item", b);
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(
213 std::vector<bool, Allocator> & t,
214 const unsigned int file_version
216 boost::serialization::split_free(ar, t, file_version);
222 #include <boost/serialization/collection_traits.hpp>
224 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector)
227 #endif // BOOST_SERIALIZATION_VECTOR_HPP