hash_set.hpp 5.8 KB

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