1 #ifndef BOOST_SERIALIZATION_VECTOR_HPP
2 #define BOOST_SERIALIZATION_VECTOR_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
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/collections_save_imp.hpp>
26 #include <boost/serialization/collections_load_imp.hpp>
27 #include <boost/serialization/split_free.hpp>
28 #include <boost/serialization/array.hpp>
29 #include <boost/serialization/detail/get_data.hpp>
30 #include <boost/mpl/bool.hpp>
32 // default is being compatible with version 1.34.1 files, not 1.35 files
33 #ifndef BOOST_SERIALIZATION_VECTOR_VERSION
34 #define BOOST_SERIALIZATION_VECTOR_VERSION 3
39 namespace serialization
{
41 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
44 // the default versions
46 template<class Archive
, class U
, class Allocator
>
49 const std::vector
<U
, Allocator
> &t
,
50 const unsigned int /* file_version */,
53 boost::serialization::stl::save_collection
<Archive
, STD::vector
<U
, Allocator
> >(
58 template<class Archive
, class U
, class Allocator
>
61 std::vector
<U
, Allocator
> &t
,
62 const unsigned int /* file_version */,
65 boost::serialization::stl::load_collection
<
67 std::vector
<U
, Allocator
>,
68 boost::serialization::stl::archive_input_seq
<
69 Archive
, STD::vector
<U
, Allocator
>
71 boost::serialization::stl::reserve_imp
<STD::vector
<U
, Allocator
> >
75 // the optimized versions
77 template<class Archive
, class U
, class Allocator
>
80 const std::vector
<U
, Allocator
> &t
,
81 const unsigned int /* file_version */,
84 const collection_size_type
count(t
.size());
85 ar
<< BOOST_SERIALIZATION_NVP(count
);
86 if(BOOST_SERIALIZATION_VECTOR_VERSION
< ar
.get_library_version()) {
87 const unsigned int item_version
= version
<U
>::value
;
88 ar
<< BOOST_SERIALIZATION_NVP(item_version
);
91 ar
<< make_array(detail::get_data(t
),t
.size());
94 template<class Archive
, class U
, class Allocator
>
97 std::vector
<U
, Allocator
> &t
,
98 const unsigned int /* file_version */,
101 collection_size_type
count(t
.size());
102 ar
>> BOOST_SERIALIZATION_NVP(count
);
104 unsigned int item_version
=0;
105 if(BOOST_SERIALIZATION_VECTOR_VERSION
< ar
.get_library_version())
106 ar
>> BOOST_SERIALIZATION_NVP(item_version
);
108 ar
>> make_array(detail::get_data(t
),t
.size());
111 // dispatch to either default or optimized versions
113 template<class Archive
, class U
, class Allocator
>
116 const std::vector
<U
, Allocator
> &t
,
117 const unsigned int file_version
119 typedef BOOST_DEDUCED_TYPENAME
120 boost::serialization::use_array_optimization
<Archive
>::template apply
<
121 BOOST_DEDUCED_TYPENAME remove_const
<U
>::type
122 >::type use_optimized
;
123 save(ar
,t
,file_version
, use_optimized());
126 template<class Archive
, class U
, class Allocator
>
129 std::vector
<U
, Allocator
> &t
,
130 const unsigned int file_version
132 typedef BOOST_DEDUCED_TYPENAME
133 boost::serialization::use_array_optimization
<Archive
>::template apply
<
134 BOOST_DEDUCED_TYPENAME remove_const
<U
>::type
135 >::type use_optimized
;
136 load(ar
,t
,file_version
, use_optimized());
139 // split non-intrusive serialization function member into separate
140 // non intrusive save/load member functions
141 template<class Archive
, class U
, class Allocator
>
142 inline void serialize(
144 std::vector
<U
, Allocator
> & t
,
145 const unsigned int file_version
147 boost::serialization::split_free(ar
, t
, file_version
);
150 #if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
152 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
154 template<class Archive
, class Allocator
>
157 const std::vector
<bool, Allocator
> &t
,
158 const unsigned int /* file_version */
160 // record number of elements
161 collection_size_type
count (t
.size());
162 ar
<< BOOST_SERIALIZATION_NVP(count
);
163 std::vector
<bool>::const_iterator it
= t
.begin();
166 ar
<< boost::serialization::make_nvp("item", tb
);
170 template<class Archive
, class Allocator
>
173 std::vector
<bool, Allocator
> &t
,
174 const unsigned int /* file_version */
176 // retrieve number of elements
177 collection_size_type count
;
178 ar
>> BOOST_SERIALIZATION_NVP(count
);
182 ar
>> boost::serialization::make_nvp("item", i
);
187 // split non-intrusive serialization function member into separate
188 // non intrusive save/load member functions
189 template<class Archive
, class Allocator
>
190 inline void serialize(
192 std::vector
<bool, Allocator
> & t
,
193 const unsigned int file_version
195 boost::serialization::split_free(ar
, t
, file_version
);
198 #endif // BOOST_WORKAROUND
203 #include <boost/serialization/collection_traits.hpp>
205 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::vector
)
207 #endif // BOOST_SERIALIZATION_VECTOR_HPP