archive_input_unordered_set.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_SET_HPP
  2. #define BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_SET_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. // archive_input_unordered_set.hpp
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // (C) Copyright 2014 Jim Bell
  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 <utility>
  16. #include <boost/serialization/nvp.hpp>
  17. #include <boost/serialization/detail/stack_constructor.hpp>
  18. #include <boost/move/utility_core.hpp>
  19. namespace boost {
  20. namespace serialization {
  21. namespace stl {
  22. // unordered_set input
  23. template<class Archive, class Container>
  24. struct archive_input_unordered_set
  25. {
  26. inline void operator()(
  27. Archive &ar,
  28. Container &s,
  29. const unsigned int v
  30. ){
  31. typedef typename Container::value_type type;
  32. detail::stack_construct<Archive, type> t(ar, v);
  33. // borland fails silently w/o full namespace
  34. ar >> boost::serialization::make_nvp("item", t.reference());
  35. std::pair<typename Container::const_iterator, bool> result =
  36. s.insert(boost::move(t.reference()));
  37. if(result.second)
  38. ar.reset_object_address(& (* result.first), & t.reference());
  39. }
  40. };
  41. // unordered_multiset input
  42. template<class Archive, class Container>
  43. struct archive_input_unordered_multiset
  44. {
  45. inline void operator()(
  46. Archive &ar,
  47. Container &s,
  48. const unsigned int v
  49. ){
  50. typedef typename Container::value_type type;
  51. detail::stack_construct<Archive, type> t(ar, v);
  52. ar >> boost::serialization::make_nvp("item", t.reference());
  53. typename Container::const_iterator result =
  54. s.insert(boost::move(t.reference()));
  55. ar.reset_object_address(& (* result), & t.reference());
  56. }
  57. };
  58. } // stl
  59. } // serialization
  60. } // boost
  61. #endif // BOOST_SERIALIZATION_ARCHIVE_INPUT_UNORDERED_SET_HPP