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