collections_load_imp.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
  2. #define BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. #if defined(_MSC_VER) && (_MSC_VER <= 1020)
  8. # pragma warning (disable : 4786) // too long name, harmless warning
  9. #endif
  10. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  11. // collections_load_imp.hpp: serialization for loading stl collections
  12. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  13. // Use, modification and distribution is subject to the Boost Software
  14. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. // See http://www.boost.org for updates, documentation, and revision history.
  17. // helper function templates for serialization of collections
  18. #include <boost/assert.hpp>
  19. #include <cstddef> // size_t
  20. #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
  21. #if defined(BOOST_NO_STDC_NAMESPACE)
  22. namespace std{
  23. using ::size_t;
  24. } // namespace std
  25. #endif
  26. #include <boost/detail/workaround.hpp>
  27. #include <boost/archive/detail/basic_iarchive.hpp>
  28. #include <boost/serialization/access.hpp>
  29. #include <boost/serialization/nvp.hpp>
  30. #include <boost/serialization/detail/stack_constructor.hpp>
  31. #include <boost/serialization/collection_size_type.hpp>
  32. #include <boost/serialization/item_version_type.hpp>
  33. #include <boost/serialization/detail/is_default_constructible.hpp>
  34. #include <boost/utility/enable_if.hpp>
  35. #include <boost/move/utility_core.hpp>
  36. namespace boost{
  37. namespace serialization {
  38. namespace stl {
  39. //////////////////////////////////////////////////////////////////////
  40. // implementation of serialization for STL containers
  41. //
  42. template<
  43. class Archive,
  44. class T
  45. >
  46. typename boost::enable_if<
  47. typename detail::is_default_constructible<
  48. typename T::value_type
  49. >,
  50. void
  51. >::type
  52. collection_load_impl(
  53. Archive & ar,
  54. T & t,
  55. collection_size_type count,
  56. item_version_type /*item_version*/
  57. ){
  58. t.resize(count);
  59. typename T::iterator hint;
  60. hint = t.begin();
  61. while(count-- > 0){
  62. ar >> boost::serialization::make_nvp("item", *hint++);
  63. }
  64. }
  65. template<
  66. class Archive,
  67. class T
  68. >
  69. typename boost::disable_if<
  70. typename detail::is_default_constructible<
  71. typename T::value_type
  72. >,
  73. void
  74. >::type
  75. collection_load_impl(
  76. Archive & ar,
  77. T & t,
  78. collection_size_type count,
  79. item_version_type item_version
  80. ){
  81. t.clear();
  82. while(count-- > 0){
  83. detail::stack_construct<Archive, typename T::value_type> u(ar, item_version);
  84. ar >> boost::serialization::make_nvp("item", u.reference());
  85. t.push_back(boost::move(u.reference()));
  86. ar.reset_object_address(& t.back() , & u.reference());
  87. }
  88. }
  89. } // namespace stl
  90. } // namespace serialization
  91. } // namespace boost
  92. #endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP