1 | #ifndef BOOST_SERIALIZATION_HASH_SET_HPP |
2 | #define BOOST_SERIALIZATION_HASH_SET_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 | // hash_set.hpp: serialization for stl hash_set templates |
11 | |
12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
13 | // Use, modification and distribution is subject to the Boost Software |
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
15 | // http://www.boost.org/LICENSE_1_0.txt) |
16 | |
17 | // See http://www.boost.org for updates, documentation, and revision history. |
18 | |
19 | #include <boost/config.hpp> |
20 | #ifdef BOOST_HAS_HASH |
21 | #include BOOST_HASH_SET_HEADER |
22 | |
23 | #include <boost/serialization/hash_collections_save_imp.hpp> |
24 | #include <boost/serialization/hash_collections_load_imp.hpp> |
25 | #include <boost/serialization/split_free.hpp> |
26 | #include <boost/serialization/detail/stack_constructor.hpp> |
27 | #include <boost/move/utility_core.hpp> |
28 | |
29 | namespace boost { |
30 | namespace serialization { |
31 | |
32 | namespace stl { |
33 | |
34 | // hash_set input |
35 | template<class Archive, class Container> |
36 | struct archive_input_hash_set |
37 | { |
38 | inline void operator()( |
39 | Archive &ar, |
40 | Container &s, |
41 | const unsigned int v |
42 | ){ |
43 | typedef 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<typename Container::const_iterator, bool> result = |
48 | s.insert(boost::move(t.reference())); |
49 | if(result.second) |
50 | ar.reset_object_address(& (* result.first), & t.reference()); |
51 | } |
52 | }; |
53 | |
54 | // hash_multiset input |
55 | template<class Archive, class Container> |
56 | struct archive_input_hash_multiset |
57 | { |
58 | inline void operator()( |
59 | Archive &ar, |
60 | Container &s, |
61 | const unsigned int v |
62 | ){ |
63 | typedef typename Container::value_type type; |
64 | detail::stack_construct<Archive, type> t(ar, v); |
65 | // borland fails silently w/o full namespace |
66 | ar >> boost::serialization::make_nvp("item" , t.reference()); |
67 | typename Container::const_iterator result |
68 | = s.insert(boost::move(t.reference())); |
69 | ar.reset_object_address(& (* result), & t.reference()); |
70 | } |
71 | }; |
72 | |
73 | } // stl |
74 | |
75 | template< |
76 | class Archive, |
77 | class Key, |
78 | class HashFcn, |
79 | class EqualKey, |
80 | class Allocator |
81 | > |
82 | inline void save( |
83 | Archive & ar, |
84 | const BOOST_STD_EXTENSION_NAMESPACE::hash_set< |
85 | Key, HashFcn, EqualKey, Allocator |
86 | > &t, |
87 | const unsigned int file_version |
88 | ){ |
89 | boost::serialization::stl::save_hash_collection< |
90 | Archive, |
91 | BOOST_STD_EXTENSION_NAMESPACE::hash_set< |
92 | Key, HashFcn, EqualKey, Allocator |
93 | > |
94 | >(ar, t); |
95 | } |
96 | |
97 | template< |
98 | class Archive, |
99 | class Key, |
100 | class HashFcn, |
101 | class EqualKey, |
102 | class Allocator |
103 | > |
104 | inline void load( |
105 | Archive & ar, |
106 | BOOST_STD_EXTENSION_NAMESPACE::hash_set< |
107 | Key, HashFcn, EqualKey, Allocator |
108 | > &t, |
109 | const unsigned int file_version |
110 | ){ |
111 | boost::serialization::stl::load_hash_collection< |
112 | Archive, |
113 | BOOST_STD_EXTENSION_NAMESPACE::hash_set< |
114 | Key, HashFcn, EqualKey, Allocator |
115 | >, |
116 | boost::serialization::stl::archive_input_hash_set< |
117 | Archive, |
118 | BOOST_STD_EXTENSION_NAMESPACE::hash_set< |
119 | Key, HashFcn, EqualKey, Allocator |
120 | > |
121 | > |
122 | >(ar, t); |
123 | } |
124 | |
125 | // split non-intrusive serialization function member into separate |
126 | // non intrusive save/load member functions |
127 | template< |
128 | class Archive, |
129 | class Key, |
130 | class HashFcn, |
131 | class EqualKey, |
132 | class Allocator |
133 | > |
134 | inline void serialize( |
135 | Archive & ar, |
136 | BOOST_STD_EXTENSION_NAMESPACE::hash_set< |
137 | Key, HashFcn, EqualKey, Allocator |
138 | > &t, |
139 | const unsigned int file_version |
140 | ){ |
141 | boost::serialization::split_free(ar, t, file_version); |
142 | } |
143 | |
144 | // hash_multiset |
145 | template< |
146 | class Archive, |
147 | class Key, |
148 | class HashFcn, |
149 | class EqualKey, |
150 | class Allocator |
151 | > |
152 | inline void save( |
153 | Archive & ar, |
154 | const BOOST_STD_EXTENSION_NAMESPACE::hash_multiset< |
155 | Key, HashFcn, EqualKey, Allocator |
156 | > &t, |
157 | const unsigned int file_version |
158 | ){ |
159 | boost::serialization::stl::save_hash_collection< |
160 | Archive, |
161 | BOOST_STD_EXTENSION_NAMESPACE::hash_multiset< |
162 | Key, HashFcn, EqualKey, Allocator |
163 | > |
164 | >(ar, t); |
165 | } |
166 | |
167 | template< |
168 | class Archive, |
169 | class Key, |
170 | class HashFcn, |
171 | class EqualKey, |
172 | class Allocator |
173 | > |
174 | inline void load( |
175 | Archive & ar, |
176 | BOOST_STD_EXTENSION_NAMESPACE::hash_multiset< |
177 | Key, HashFcn, EqualKey, Allocator |
178 | > &t, |
179 | const unsigned int file_version |
180 | ){ |
181 | boost::serialization::stl::load_hash_collection< |
182 | Archive, |
183 | BOOST_STD_EXTENSION_NAMESPACE::hash_multiset< |
184 | Key, HashFcn, EqualKey, Allocator |
185 | >, |
186 | boost::serialization::stl::archive_input_hash_multiset< |
187 | Archive, |
188 | BOOST_STD_EXTENSION_NAMESPACE::hash_multiset< |
189 | Key, HashFcn, EqualKey, Allocator |
190 | > |
191 | > |
192 | >(ar, t); |
193 | } |
194 | |
195 | // split non-intrusive serialization function member into separate |
196 | // non intrusive save/load member functions |
197 | template< |
198 | class Archive, |
199 | class Key, |
200 | class HashFcn, |
201 | class EqualKey, |
202 | class Allocator |
203 | > |
204 | inline void serialize( |
205 | Archive & ar, |
206 | BOOST_STD_EXTENSION_NAMESPACE::hash_multiset< |
207 | Key, HashFcn, EqualKey, Allocator |
208 | > & t, |
209 | const unsigned int file_version |
210 | ){ |
211 | boost::serialization::split_free(ar, t, file_version); |
212 | } |
213 | |
214 | } // namespace serialization |
215 | } // namespace boost |
216 | |
217 | #include <boost/serialization/collection_traits.hpp> |
218 | |
219 | BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::hash_set) |
220 | BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::hash_multiset) |
221 | |
222 | #endif // BOOST_HAS_HASH |
223 | #endif // BOOST_SERIALIZATION_HASH_SET_HPP |
224 | |