blob: 22626db6838f215b76c0ab60f2aeffc83b02b015 [file] [log] [blame]
Brian Silverman88678712018-08-04 23:56:48 -07001#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
30namespace boost {
31namespace serialization {
32
33namespace stl {
34
35// map input
36template<class Archive, class Container>
37struct archive_input_hash_map
38{
39 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
63template<class Archive, class Container>
64struct archive_input_hash_multimap
65{
66 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
89template<
90 class Archive,
91 class Key,
92 class HashFcn,
93 class EqualKey,
94 class Allocator
95>
96inline void save(
97 Archive & ar,
98 const BOOST_STD_EXTENSION_NAMESPACE::hash_map<
99 Key, HashFcn, EqualKey, Allocator
100 > &t,
101 const unsigned int file_version
102){
103 boost::serialization::stl::save_hash_collection<
104 Archive,
105 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
106 Key, HashFcn, EqualKey, Allocator
107 >
108 >(ar, t);
109}
110
111template<
112 class Archive,
113 class Key,
114 class HashFcn,
115 class EqualKey,
116 class Allocator
117>
118inline void load(
119 Archive & ar,
120 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
121 Key, HashFcn, EqualKey, Allocator
122 > &t,
123 const unsigned int file_version
124){
125 boost::serialization::stl::load_hash_collection<
126 Archive,
127 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
128 Key, HashFcn, EqualKey, Allocator
129 >,
130 boost::serialization::stl::archive_input_hash_map<
131 Archive,
132 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
133 Key, HashFcn, EqualKey, Allocator
134 >
135 >
136 >(ar, t);
137}
138
139// split non-intrusive serialization function member into separate
140// non intrusive save/load member functions
141template<
142 class Archive,
143 class Key,
144 class HashFcn,
145 class EqualKey,
146 class Allocator
147>
148inline void serialize(
149 Archive & ar,
150 BOOST_STD_EXTENSION_NAMESPACE::hash_map<
151 Key, HashFcn, EqualKey, Allocator
152 > &t,
153 const unsigned int file_version
154){
155 boost::serialization::split_free(ar, t, file_version);
156}
157
158// hash_multimap
159template<
160 class Archive,
161 class Key,
162 class HashFcn,
163 class EqualKey,
164 class Allocator
165>
166inline void save(
167 Archive & ar,
168 const BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
169 Key, HashFcn, EqualKey, Allocator
170 > &t,
171 const unsigned int file_version
172){
173 boost::serialization::stl::save_hash_collection<
174 Archive,
175 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
176 Key, HashFcn, EqualKey, Allocator
177 >
178 >(ar, t);
179}
180
181template<
182 class Archive,
183 class Key,
184 class HashFcn,
185 class EqualKey,
186 class Allocator
187>
188inline void load(
189 Archive & ar,
190 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
191 Key, HashFcn, EqualKey, Allocator
192 > &t,
193 const unsigned int file_version
194){
195 boost::serialization::stl::load_hash_collection<
196 Archive,
197 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
198 Key, HashFcn, EqualKey, Allocator
199 >,
200 boost::serialization::stl::archive_input_hash_multimap<
201 Archive,
202 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
203 Key, HashFcn, EqualKey, Allocator
204 >
205 >
206 >(ar, t);
207}
208
209// split non-intrusive serialization function member into separate
210// non intrusive save/load member functions
211template<
212 class Archive,
213 class Key,
214 class HashFcn,
215 class EqualKey,
216 class Allocator
217>
218inline void serialize(
219 Archive & ar,
220 BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
221 Key, HashFcn, EqualKey, Allocator
222 > &t,
223 const unsigned int file_version
224){
225 boost::serialization::split_free(ar, t, file_version);
226}
227
228} // namespace serialization
229} // namespace boost
230
231#endif // BOOST_HAS_HASH
232#endif // BOOST_SERIALIZATION_HASH_MAP_HPP