mlpack  2.0.1
unordered_map.hpp
Go to the documentation of this file.
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 // (C) Copyright 2014 Jim Bell
15 // Use, modification and distribution is subject to the Boost Software
16 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 
19 // See http://www.boost.org for updates, documentation, and revision history.
20 
21 #include <boost/config.hpp>
22 
23 #include <unordered_map>
24 
25 #include <boost/serialization/utility.hpp>
28 #include <boost/serialization/split_free.hpp>
29 
30 namespace boost {
31 namespace serialization {
32 
33 namespace stl {
34 
35 // map input
36 template<class Archive, class Container>
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(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>
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(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 HashFcn,
93  class EqualKey,
94  class Allocator
95 >
96 inline void save(
97  Archive & ar,
98  const std::unordered_map<
99  Key, HashFcn, EqualKey, Allocator
100  > &t,
101  const unsigned int /*file_version*/
102 ){
104  Archive,
105  std::unordered_map<
106  Key, HashFcn, EqualKey, Allocator
107  >
108  >(ar, t);
109 }
110 
111 template<
112  class Archive,
113  class Key,
114  class HashFcn,
115  class EqualKey,
116  class Allocator
117 >
118 inline void load(
119  Archive & ar,
120  std::unordered_map<
121  Key, HashFcn, EqualKey, Allocator
122  > &t,
123  const unsigned int /*file_version*/
124 ){
126  Archive,
127  std::unordered_map<
128  Key, HashFcn, EqualKey, Allocator
129  >,
131  Archive,
132  std::unordered_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
141 template<
142  class Archive,
143  class Key,
144  class HashFcn,
145  class EqualKey,
146  class Allocator
147 >
148 inline void serialize(
149  Archive & ar,
150  std::unordered_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 // unordered_multimap
159 template<
160  class Archive,
161  class Key,
162  class HashFcn,
163  class EqualKey,
164  class Allocator
165 >
166 inline void save(
167  Archive & ar,
168  const std::unordered_multimap<
169  Key, HashFcn, EqualKey, Allocator
170  > &t,
171  const unsigned int /*file_version*/
172 ){
174  Archive,
175  std::unordered_multimap<
176  Key, HashFcn, EqualKey, Allocator
177  >
178  >(ar, t);
179 }
180 
181 template<
182  class Archive,
183  class Key,
184  class HashFcn,
185  class EqualKey,
186  class Allocator
187 >
188 inline void load(
189  Archive & ar,
190  std::unordered_multimap<
191  Key, HashFcn, EqualKey, Allocator
192  > &t,
193  const unsigned int /*file_version*/
194 ){
196  Archive,
197  std::unordered_multimap<
198  Key, HashFcn, EqualKey, Allocator
199  >,
201  Archive,
202  std::unordered_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
211 template<
212  class Archive,
213  class Key,
214  class HashFcn,
215  class EqualKey,
216  class Allocator
217 >
218 inline void serialize(
219  Archive & ar,
220  std::unordered_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_SERIALIZATION_UNORDERED_MAP_HPP
void save(Archive &ar, const std::unordered_map< Key, HashFcn, EqualKey, Allocator > &t, const unsigned int)
void load(Archive &ar, std::unordered_map< Key, HashFcn, EqualKey, Allocator > &t, const unsigned int)
void operator()(Archive &ar, Container &s, const unsigned int v)
void serialize(Archive &ar, std::unordered_map< Key, HashFcn, EqualKey, Allocator > &t, const unsigned int file_version)
void operator()(Archive &ar, Container &s, const unsigned int v)
void save_unordered_collection(Archive &ar, const Container &s)
void load_unordered_collection(Archive &ar, Container &s)