1 #ifndef BOOST_SERIALIZATION_HASH_MAP_HPP
2 #define BOOST_SERIALIZATION_HASH_MAP_HPP
3
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER)
6 # pragma once
7 #endif
8
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // serialization/hash_map.hpp:
11 // serialization for stl hash_map templates
12
13 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
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)
17
18 // See http://www.boost.org for updates, documentation, and revision history.
19
20 #include <boost/config.hpp>
21 #ifdef BOOST_HAS_HASH
22 #include BOOST_HASH_MAP_HEADER
23
24 #include <boost/serialization/utility.hpp>
25 #include <boost/serialization/hash_collections_save_imp.hpp>
26 #include <boost/serialization/hash_collections_load_imp.hpp>
27 #include <boost/serialization/split_free.hpp>
28 #include <boost/move/utility_core.hpp>
29
30 namespace boost {
31 namespace serialization {
32
33 namespace stl {
34
35 // map input
36 template<class Archive, class Container>
37 struct archive_input_hash_map
38 {
operator ()boost::serialization::stl::archive_input_hash_map39 inline void operator()(
40 Archive &ar,
41 Container &s,
42 const unsigned int v
43 ){
44 typedef typename Container::value_type type;
45 detail::stack_construct<Archive, type> t(ar, v);
46 // borland fails silently w/o full namespace
47 ar >> boost::serialization::make_nvp("item", t.reference());
48 std::pair<typename Container::const_iterator, bool> result =
49 s.insert(boost::move(t.reference()));
50 // note: the following presumes that the map::value_type was NOT tracked
51 // in the archive. This is the usual case, but here there is no way
52 // to determine that.
53 if(result.second){
54 ar.reset_object_address(
55 & (result.first->second),
56 & t.reference().second
57 );
58 }
59 }
60 };
61
62 // multimap input
63 template<class Archive, class Container>
64 struct archive_input_hash_multimap
65 {
operator ()boost::serialization::stl::archive_input_hash_multimap66 inline void operator()(
67 Archive &ar,
68 Container &s,
69 const unsigned int v
70 ){
71 typedef typename Container::value_type type;
72 detail::stack_construct<Archive, type> t(ar, v);
73 // borland fails silently w/o full namespace
74 ar >> boost::serialization::make_nvp("item", t.reference());
75 typename Container::const_iterator result
76 = s.insert(boost::move(t.reference()));
77 // note: the following presumes that the map::value_type was NOT tracked
78 // in the archive. This is the usual case, but here there is no way
79 // to determine that.
80 ar.reset_object_address(
81 & result->second,
82 & t.reference()
83 );
84 }
85 };
86
87 } // stl
88
89 template<
90 class Archive,
91 class Key,
92 class T,
93 class HashFcn,
94 class EqualKey,
95 class Allocator
96 >
save(Archive & ar,const BOOST_STD_EXTENSION_NAMESPACE::hash_map<Key,T,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)97 inline void save(
98 Archive & ar,
99 const BOOST_STD_EXTENSION_NAMESPACE::hash_map<
100 Key, T, HashFcn, EqualKey, Allocator
101 > &t,
102 const unsigned int file_version
103 ){
104 boost::serialization::stl::save_hash_collection<
105 Archive,
106 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
107 Key, T, HashFcn, EqualKey, Allocator
108 >
109 >(ar, t);
110 }
111
112 template<
113 class Archive,
114 class Key,
115 class T,
116 class HashFcn,
117 class EqualKey,
118 class Allocator
119 >
load(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_map<Key,T,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)120 inline void load(
121 Archive & ar,
122 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
123 Key, T, HashFcn, EqualKey, Allocator
124 > &t,
125 const unsigned int file_version
126 ){
127 boost::serialization::stl::load_hash_collection<
128 Archive,
129 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
130 Key, T, HashFcn, EqualKey, Allocator
131 >,
132 boost::serialization::stl::archive_input_hash_map<
133 Archive,
134 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
135 Key, T, HashFcn, EqualKey, Allocator
136 >
137 >
138 >(ar, t);
139 }
140
141 // split non-intrusive serialization function member into separate
142 // non intrusive save/load member functions
143 template<
144 class Archive,
145 class Key,
146 class T,
147 class HashFcn,
148 class EqualKey,
149 class Allocator
150 >
serialize(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_map<Key,T,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)151 inline void serialize(
152 Archive & ar,
153 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
154 Key, T, HashFcn, EqualKey, Allocator
155 > &t,
156 const unsigned int file_version
157 ){
158 boost::serialization::split_free(ar, t, file_version);
159 }
160
161 // hash_multimap
162 template<
163 class Archive,
164 class Key,
165 class T,
166 class HashFcn,
167 class EqualKey,
168 class Allocator
169 >
save(Archive & ar,const BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<Key,T,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)170 inline void save(
171 Archive & ar,
172 const BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
173 Key, T, HashFcn, EqualKey, Allocator
174 > &t,
175 const unsigned int file_version
176 ){
177 boost::serialization::stl::save_hash_collection<
178 Archive,
179 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
180 Key, T, HashFcn, EqualKey, Allocator
181 >
182 >(ar, t);
183 }
184
185 template<
186 class Archive,
187 class Key,
188 class T,
189 class HashFcn,
190 class EqualKey,
191 class Allocator
192 >
load(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<Key,T,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)193 inline void load(
194 Archive & ar,
195 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
196 Key, T, HashFcn, EqualKey, Allocator
197 > &t,
198 const unsigned int file_version
199 ){
200 boost::serialization::stl::load_hash_collection<
201 Archive,
202 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
203 Key, T, HashFcn, EqualKey, Allocator
204 >,
205 boost::serialization::stl::archive_input_hash_multimap<
206 Archive,
207 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
208 Key, T, HashFcn, EqualKey, Allocator
209 >
210 >
211 >(ar, t);
212 }
213
214 // split non-intrusive serialization function member into separate
215 // non intrusive save/load member functions
216 template<
217 class Archive,
218 class Key,
219 class T,
220 class HashFcn,
221 class EqualKey,
222 class Allocator
223 >
serialize(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<Key,T,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)224 inline void serialize(
225 Archive & ar,
226 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
227 Key, T, HashFcn, EqualKey, Allocator
228 > &t,
229 const unsigned int file_version
230 ){
231 boost::serialization::split_free(ar, t, file_version);
232 }
233
234 } // namespace serialization
235 } // namespace boost
236
237 #endif // BOOST_HAS_HASH
238 #endif // BOOST_SERIALIZATION_HASH_MAP_HPP
239