hash_map.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #ifndef BOOST_SERIALIZATION_HASH_MAP_HPP
  2. #define BOOST_SERIALIZATION_HASH_MAP_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. // serialization/hash_map.hpp:
  9. // serialization for stl hash_map templates
  10. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  11. // Use, modification and distribution is subject to the Boost Software
  12. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. // See http://www.boost.org for updates, documentation, and revision history.
  15. #include <boost/config.hpp>
  16. #ifdef BOOST_HAS_HASH
  17. #include BOOST_HASH_MAP_HEADER
  18. #include <boost/serialization/utility.hpp>
  19. #include <boost/serialization/hash_collections_save_imp.hpp>
  20. #include <boost/serialization/hash_collections_load_imp.hpp>
  21. #include <boost/serialization/split_free.hpp>
  22. #include <boost/move/utility_core.hpp>
  23. namespace boost {
  24. namespace serialization {
  25. namespace stl {
  26. // map input
  27. template<class Archive, class Container>
  28. struct archive_input_hash_map
  29. {
  30. inline void operator()(
  31. Archive &ar,
  32. Container &s,
  33. const unsigned int v
  34. ){
  35. typedef typename Container::value_type type;
  36. detail::stack_construct<Archive, type> t(ar, v);
  37. // borland fails silently w/o full namespace
  38. ar >> boost::serialization::make_nvp("item", t.reference());
  39. std::pair<typename Container::const_iterator, bool> result =
  40. s.insert(boost::move(t.reference()));
  41. // note: the following presumes that the map::value_type was NOT tracked
  42. // in the archive. This is the usual case, but here there is no way
  43. // to determine that.
  44. if(result.second){
  45. ar.reset_object_address(
  46. & (result.first->second),
  47. & t.reference().second
  48. );
  49. }
  50. }
  51. };
  52. // multimap input
  53. template<class Archive, class Container>
  54. struct archive_input_hash_multimap
  55. {
  56. inline void operator()(
  57. Archive &ar,
  58. Container &s,
  59. const unsigned int v
  60. ){
  61. typedef typename Container::value_type type;
  62. detail::stack_construct<Archive, type> t(ar, v);
  63. // borland fails silently w/o full namespace
  64. ar >> boost::serialization::make_nvp("item", t.reference());
  65. typename Container::const_iterator result
  66. = s.insert(boost::move(t.reference()));
  67. // note: the following presumes that the map::value_type was NOT tracked
  68. // in the archive. This is the usual case, but here there is no way
  69. // to determine that.
  70. ar.reset_object_address(
  71. & result->second,
  72. & t.reference()
  73. );
  74. }
  75. };
  76. } // stl
  77. template<
  78. class Archive,
  79. class Key,
  80. class HashFcn,
  81. class EqualKey,
  82. class Allocator
  83. >
  84. inline void save(
  85. Archive & ar,
  86. const BOOST_STD_EXTENSION_NAMESPACE::hash_map<
  87. Key, HashFcn, EqualKey, Allocator
  88. > &t,
  89. const unsigned int file_version
  90. ){
  91. boost::serialization::stl::save_hash_collection<
  92. Archive,
  93. BOOST_STD_EXTENSION_NAMESPACE::hash_map<
  94. Key, HashFcn, EqualKey, Allocator
  95. >
  96. >(ar, t);
  97. }
  98. template<
  99. class Archive,
  100. class Key,
  101. class HashFcn,
  102. class EqualKey,
  103. class Allocator
  104. >
  105. inline void load(
  106. Archive & ar,
  107. BOOST_STD_EXTENSION_NAMESPACE::hash_map<
  108. Key, HashFcn, EqualKey, Allocator
  109. > &t,
  110. const unsigned int file_version
  111. ){
  112. boost::serialization::stl::load_hash_collection<
  113. Archive,
  114. BOOST_STD_EXTENSION_NAMESPACE::hash_map<
  115. Key, HashFcn, EqualKey, Allocator
  116. >,
  117. boost::serialization::stl::archive_input_hash_map<
  118. Archive,
  119. BOOST_STD_EXTENSION_NAMESPACE::hash_map<
  120. Key, HashFcn, EqualKey, Allocator
  121. >
  122. >
  123. >(ar, t);
  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_map<
  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. // hash_multimap
  144. template<
  145. class Archive,
  146. class Key,
  147. class HashFcn,
  148. class EqualKey,
  149. class Allocator
  150. >
  151. inline void save(
  152. Archive & ar,
  153. const BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
  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_multimap<
  161. Key, HashFcn, EqualKey, Allocator
  162. >
  163. >(ar, t);
  164. }
  165. template<
  166. class Archive,
  167. class Key,
  168. class HashFcn,
  169. class EqualKey,
  170. class Allocator
  171. >
  172. inline void load(
  173. Archive & ar,
  174. BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
  175. Key, HashFcn, EqualKey, Allocator
  176. > &t,
  177. const unsigned int file_version
  178. ){
  179. boost::serialization::stl::load_hash_collection<
  180. Archive,
  181. BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
  182. Key, HashFcn, EqualKey, Allocator
  183. >,
  184. boost::serialization::stl::archive_input_hash_multimap<
  185. Archive,
  186. BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
  187. Key, HashFcn, EqualKey, Allocator
  188. >
  189. >
  190. >(ar, t);
  191. }
  192. // split non-intrusive serialization function member into separate
  193. // non intrusive save/load member functions
  194. template<
  195. class Archive,
  196. class Key,
  197. class HashFcn,
  198. class EqualKey,
  199. class Allocator
  200. >
  201. inline void serialize(
  202. Archive & ar,
  203. BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
  204. Key, HashFcn, EqualKey, Allocator
  205. > &t,
  206. const unsigned int file_version
  207. ){
  208. boost::serialization::split_free(ar, t, file_version);
  209. }
  210. } // namespace serialization
  211. } // namespace boost
  212. #endif // BOOST_HAS_HASH
  213. #endif // BOOST_SERIALIZATION_HASH_MAP_HPP