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/move/utility_core.hpp>
27 
28 namespace boost {
29 namespace serialization {
30 
31 namespace stl {
32 
33 // hash_set input
34 template<class Archive, class Container>
35 struct archive_input_hash_set
36 {
operator ()boost::serialization::stl::archive_input_hash_set37     inline void operator()(
38         Archive &ar,
39         Container &s,
40         const unsigned int v
41     ){
42         typedef typename Container::value_type type;
43         detail::stack_construct<Archive, type> t(ar, v);
44         // borland fails silently w/o full namespace
45         ar >> boost::serialization::make_nvp("item", t.reference());
46         std::pair<typename Container::const_iterator, bool> result =
47             s.insert(boost::move(t.reference()));
48         if(result.second)
49             ar.reset_object_address(& (* result.first), & t.reference());
50     }
51 };
52 
53 // hash_multiset input
54 template<class Archive, class Container>
55 struct archive_input_hash_multiset
56 {
operator ()boost::serialization::stl::archive_input_hash_multiset57     inline void operator()(
58         Archive &ar,
59         Container &s,
60         const unsigned int v
61     ){
62         typedef typename Container::value_type type;
63         detail::stack_construct<Archive, type> t(ar, v);
64         // borland fails silently w/o full namespace
65         ar >> boost::serialization::make_nvp("item", t.reference());
66         typename Container::const_iterator result
67             = s.insert(boost::move(t.reference()));
68         ar.reset_object_address(& (* result), & t.reference());
69     }
70 };
71 
72 } // stl
73 
74 template<
75     class Archive,
76     class Key,
77     class HashFcn,
78     class EqualKey,
79     class Allocator
80 >
save(Archive & ar,const BOOST_STD_EXTENSION_NAMESPACE::hash_set<Key,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)81 inline void save(
82     Archive & ar,
83     const BOOST_STD_EXTENSION_NAMESPACE::hash_set<
84         Key, HashFcn, EqualKey, Allocator
85     > &t,
86     const unsigned int file_version
87 ){
88     boost::serialization::stl::save_hash_collection<
89         Archive,
90         BOOST_STD_EXTENSION_NAMESPACE::hash_set<
91             Key, HashFcn, EqualKey, Allocator
92         >
93     >(ar, t);
94 }
95 
96 template<
97     class Archive,
98     class Key,
99     class HashFcn,
100     class EqualKey,
101     class Allocator
102 >
load(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_set<Key,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)103 inline void load(
104     Archive & ar,
105     BOOST_STD_EXTENSION_NAMESPACE::hash_set<
106         Key, HashFcn, EqualKey, Allocator
107     > &t,
108     const unsigned int file_version
109 ){
110     boost::serialization::stl::load_hash_collection<
111         Archive,
112         BOOST_STD_EXTENSION_NAMESPACE::hash_set<
113             Key, HashFcn, EqualKey, Allocator
114         >,
115         boost::serialization::stl::archive_input_hash_set<
116             Archive,
117             BOOST_STD_EXTENSION_NAMESPACE::hash_set<
118                 Key, HashFcn, EqualKey, Allocator
119             >
120         >
121     >(ar, t);
122 }
123 
124 // split non-intrusive serialization function member into separate
125 // non intrusive save/load member functions
126 template<
127     class Archive,
128     class Key,
129     class HashFcn,
130     class EqualKey,
131     class Allocator
132 >
serialize(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_set<Key,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)133 inline void serialize(
134     Archive & ar,
135     BOOST_STD_EXTENSION_NAMESPACE::hash_set<
136         Key, HashFcn, EqualKey, Allocator
137     > &t,
138     const unsigned int file_version
139 ){
140     boost::serialization::split_free(ar, t, file_version);
141 }
142 
143 // hash_multiset
144 template<
145     class Archive,
146     class Key,
147     class HashFcn,
148     class EqualKey,
149     class Allocator
150 >
save(Archive & ar,const BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<Key,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)151 inline void save(
152     Archive & ar,
153     const BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
154         Key, HashFcn, EqualKey, Allocator
155     > &t,
156     const unsigned int file_version
157 ){
158     boost::serialization::stl::save_hash_collection<
159         Archive,
160         BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
161             Key, HashFcn, EqualKey, Allocator
162         >
163     >(ar, t);
164 }
165 
166 template<
167     class Archive,
168     class Key,
169     class HashFcn,
170     class EqualKey,
171     class Allocator
172 >
load(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<Key,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)173 inline void load(
174     Archive & ar,
175     BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
176         Key, HashFcn, EqualKey, Allocator
177     > &t,
178     const unsigned int file_version
179 ){
180     boost::serialization::stl::load_hash_collection<
181         Archive,
182         BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
183             Key, HashFcn, EqualKey, Allocator
184         >,
185         boost::serialization::stl::archive_input_hash_multiset<
186             Archive,
187             BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
188                 Key, HashFcn, EqualKey, Allocator
189             >
190         >
191     >(ar, t);
192 }
193 
194 // split non-intrusive serialization function member into separate
195 // non intrusive save/load member functions
196 template<
197     class Archive,
198     class Key,
199     class HashFcn,
200     class EqualKey,
201     class Allocator
202 >
serialize(Archive & ar,BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<Key,HashFcn,EqualKey,Allocator> & t,const unsigned int file_version)203 inline void serialize(
204     Archive & ar,
205     BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
206         Key, HashFcn, EqualKey, Allocator
207     > & t,
208     const unsigned int file_version
209 ){
210     boost::serialization::split_free(ar, t, file_version);
211 }
212 
213 } // namespace serialization
214 } // namespace boost
215 
216 #include <boost/serialization/collection_traits.hpp>
217 
218 BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::hash_set)
219 BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::hash_multiset)
220 
221 #endif // BOOST_HAS_HASH
222 #endif // BOOST_SERIALIZATION_HASH_SET_HPP
223