archive_input_unordered_map.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_MAP_HPP
  2. #define BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_MAP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // serialization/unordered_map.hpp:
  9. // serialization for stl unordered_map templates
  10. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  11. // (C) Copyright 2014 Jim Bell
  12. // Use, modification and distribution is subject to the Boost Software
  13. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. // See http://www.boost.org for updates, documentation, and revision history.
  16. #include <boost/config.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/detail/stack_constructor.hpp>
  19. #include <boost/serialization/utility.hpp>
  20. #include <boost/move/utility_core.hpp>
  21. namespace boost {
  22. namespace serialization {
  23. namespace stl {
  24. // map input
  25. template<class Archive, class Container>
  26. struct archive_input_unordered_map
  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. ar >> boost::serialization::make_nvp("item", t.reference());
  36. std::pair<typename Container::const_iterator, bool> result =
  37. s.insert(boost::move(t.reference()));
  38. // note: the following presumes that the map::value_type was NOT tracked
  39. // in the archive. This is the usual case, but here there is no way
  40. // to determine that.
  41. if(result.second){
  42. ar.reset_object_address(
  43. & (result.first->second),
  44. & t.reference().second
  45. );
  46. }
  47. }
  48. };
  49. // multimap input
  50. template<class Archive, class Container>
  51. struct archive_input_unordered_multimap
  52. {
  53. inline void operator()(
  54. Archive &ar,
  55. Container &s,
  56. const unsigned int v
  57. ){
  58. typedef typename Container::value_type type;
  59. detail::stack_construct<Archive, type> t(ar, v);
  60. ar >> boost::serialization::make_nvp("item", t.reference());
  61. typename Container::const_iterator result =
  62. s.insert(t.reference());
  63. // note: the following presumes that the map::value_type was NOT tracked
  64. // in the archive. This is the usual case, but here there is no way
  65. // to determine that.
  66. ar.reset_object_address(
  67. & result->second,
  68. & t.reference()
  69. );
  70. }
  71. };
  72. } // stl
  73. } // namespace serialization
  74. } // namespace boost
  75. #endif // BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_MAP_HPP