hash_set.hpp 5.8 KB

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