1 #ifndef BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
2 #define BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
9 #if defined(_MSC_VER) && (_MSC_VER <= 1020)
10 # pragma warning (disable : 4786) // too long name, harmless warning
13 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
14 // collections_load_imp.hpp: serialization for loading stl collections
16 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
17 // Use, modification and distribution is subject to the Boost Software
18 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
21 // See http://www.boost.org for updates, documentation, and revision history.
23 // helper function templates for serialization of collections
26 #include <cstddef> // size_t
27 #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
28 #if defined(BOOST_NO_STDC_NAMESPACE)
33 #include <boost/detail/workaround.hpp>
35 #include <boost/serialization/access.hpp>
36 #include <boost/serialization/nvp.hpp>
37 #include <boost/serialization/detail/stack_constructor.hpp>
38 #include <boost/serialization/collection_size_type.hpp>
42 namespace serialization
{
45 //////////////////////////////////////////////////////////////////////
46 // implementation of serialization for STL containers
49 // sequential container input
50 template<class Archive
, class Container
>
51 struct archive_input_seq
53 inline void operator()(
58 typedef BOOST_DEDUCED_TYPENAME
Container::value_type type
;
59 detail::stack_construct
<Archive
, type
> t(ar
, v
);
60 // borland fails silently w/o full namespace
61 ar
>> boost::serialization::make_nvp("item", t
.reference());
62 s
.push_back(t
.reference());
63 ar
.reset_object_address(& s
.back() , & t
.reference());
68 template<class Archive
, class Container
>
69 struct archive_input_map
71 inline void operator()(
76 typedef BOOST_DEDUCED_TYPENAME
Container::value_type type
;
77 detail::stack_construct
<Archive
, type
> t(ar
, v
);
78 // borland fails silently w/o full namespace
79 ar
>> boost::serialization::make_nvp("item", t
.reference());
80 std::pair
<BOOST_DEDUCED_TYPENAME
Container::const_iterator
, bool> result
=
81 s
.insert(t
.reference());
82 // note: the following presumes that the map::value_type was NOT tracked
83 // in the archive. This is the usual case, but here there is no way
86 ar
.reset_object_address(
87 & (result
.first
->second
),
88 & t
.reference().second
95 template<class Archive
, class Container
>
96 struct archive_input_multimap
98 inline void operator()(
103 typedef BOOST_DEDUCED_TYPENAME
Container::value_type type
;
104 detail::stack_construct
<Archive
, type
> t(ar
, v
);
105 // borland fails silently w/o full namespace
106 ar
>> boost::serialization::make_nvp("item", t
.reference());
107 BOOST_DEDUCED_TYPENAME
Container::const_iterator result
108 = s
.insert(t
.reference());
109 // note: the following presumes that the map::value_type was NOT tracked
110 // in the archive. This is the usual case, but here there is no way
111 // to determine that.
112 ar
.reset_object_address(
120 template<class Archive
, class Container
>
121 struct archive_input_set
123 inline void operator()(
128 typedef BOOST_DEDUCED_TYPENAME
Container::value_type type
;
129 detail::stack_construct
<Archive
, type
> t(ar
, v
);
130 // borland fails silently w/o full namespace
131 ar
>> boost::serialization::make_nvp("item", t
.reference());
132 std::pair
<BOOST_DEDUCED_TYPENAME
Container::const_iterator
, bool> result
=
133 s
.insert(t
.reference());
135 ar
.reset_object_address(& (* result
.first
), & t
.reference());
140 template<class Archive
, class Container
>
141 struct archive_input_multiset
143 inline void operator()(
148 typedef BOOST_DEDUCED_TYPENAME
Container::value_type type
;
149 detail::stack_construct
<Archive
, type
> t(ar
, v
);
150 // borland fails silently w/o full namespace
151 ar
>> boost::serialization::make_nvp("item", t
.reference());
152 BOOST_DEDUCED_TYPENAME
Container::const_iterator result
153 = s
.insert(t
.reference());
154 ar
.reset_object_address(& (* result
), & t
.reference());
158 template<class Container
>
162 void operator()(Container
&s
, std::size_t count
) const {
167 template<class Container
>
171 void operator()(Container
& /* s */, std::size_t /* count */) const{}
174 template<class Archive
, class Container
, class InputFunction
, class R
>
175 inline void load_collection(Archive
& ar
, Container
&s
)
178 // retrieve number of elements
179 collection_size_type count
;
180 unsigned int item_version
;
181 ar
>> BOOST_SERIALIZATION_NVP(count
);
182 if(3 < ar
.get_library_version())
183 ar
>> BOOST_SERIALIZATION_NVP(item_version
);
188 std::size_t c
= count
;
191 ifunc(ar
, s
, item_version
);
196 } // namespace serialization
199 #endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP