DiaDes  0.1
DIAgnosis of Discrete-Event System
unordered_map.hh
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 // 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/tr1/unordered_map.hpp>
21 #include <unordered_map>
22 
23 #include <boost/config.hpp>
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 BOOST_DEDUCED_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<BOOST_DEDUCED_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 BOOST_DEDUCED_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  BOOST_DEDUCED_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::tr1::unordered_map<
99  const std::unordered_map<
100  Key, HashFcn, EqualKey, Allocator
101  > &t,
102  const unsigned int /*file_version*/
103 ){
105  Archive,
106  std::unordered_map<
107  // std::tr1::unordered_map<
108  Key, HashFcn, EqualKey, Allocator
109  >
110  >(ar, t);
111 }
112 
113 template<
114  class Archive,
115  class Key,
116  class HashFcn,
117  class EqualKey,
118  class Allocator
119 >
120 inline void load(
121  Archive & ar,
122  // std::tr1::unordered_map<
123  std::unordered_map<
124  Key, HashFcn, EqualKey, Allocator
125  > &t,
126  const unsigned int /*file_version*/
127 ){
129  Archive,
130  // std::tr1::unordered_map<
131  std::unordered_map<
132  Key, HashFcn, EqualKey, Allocator
133  >,
135  Archive,
136  // std::tr1::unordered_map<
137  std::unordered_map<
138  Key, HashFcn, EqualKey, Allocator
139  >
140  >
141  >(ar, t);
142 }
143 
144 // split non-intrusive serialization function member into separate
145 // non intrusive save/load member functions
146 template<
147  class Archive,
148  class Key,
149  class HashFcn,
150  class EqualKey,
151  class Allocator
152 >
153 inline void serialize(
154  Archive & ar,
155  // std::tr1::unordered_map<
156  std::unordered_map<
157  Key, HashFcn, EqualKey, Allocator
158  > &t,
159  const unsigned int file_version
160 ){
161  boost::serialization::split_free(ar, t, file_version);
162 }
163 
164 // unordered_multimap
165 template<
166  class Archive,
167  class Key,
168  class HashFcn,
169  class EqualKey,
170  class Allocator
171 >
172 inline void save(
173  Archive & ar,
174  //const std::tr1::unordered_multimap<
175  const std::unordered_multimap<
176  Key, HashFcn, EqualKey, Allocator
177  > &t,
178  const unsigned int /*file_version*/
179 ){
181  Archive,
182  //std::tr1::unordered_multimap<
183  std::unordered_multimap<
184  Key, HashFcn, EqualKey, Allocator
185  >
186  >(ar, t);
187 }
188 
189 template<
190  class Archive,
191  class Key,
192  class HashFcn,
193  class EqualKey,
194  class Allocator
195 >
196 inline void load(
197  Archive & ar,
198  // std::tr1::unordered_multimap<
199  std::unordered_multimap<
200  Key, HashFcn, EqualKey, Allocator
201  > &t,
202  const unsigned int /*file_version*/
203 ){
205  Archive,
206  //std::tr1::unordered_multimap<
207  std::unordered_multimap<
208  Key, HashFcn, EqualKey, Allocator
209  >,
211  Archive,
212  //std::tr1::unordered_multimap<
213  std::unordered_multimap<
214  Key, HashFcn, EqualKey, Allocator
215  >
216  >
217  >(ar, t);
218 }
219 
220 // split non-intrusive serialization function member into separate
221 // non intrusive save/load member functions
222 template<
223  class Archive,
224  class Key,
225  class HashFcn,
226  class EqualKey,
227  class Allocator
228 >
229 inline void serialize(
230  Archive & ar,
231  //std::tr1::unordered_multimap<
232  std::unordered_multimap<
233  Key, HashFcn, EqualKey, Allocator
234  > &t,
235  const unsigned int file_version
236 ){
237  boost::serialization::split_free(ar, t, file_version);
238 }
239 
240 } // namespace serialization
241 } // namespace boost
242 
243 #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)