collections_load_imp.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/serialization/access.hpp>
  28. #include <boost/serialization/nvp.hpp>
  29. #include <boost/serialization/detail/stack_constructor.hpp>
  30. #include <boost/serialization/collection_size_type.hpp>
  31. #include <boost/serialization/item_version_type.hpp>
  32. #include <boost/serialization/detail/is_default_constructible.hpp>
  33. #include <boost/utility/enable_if.hpp>
  34. #include <boost/move/utility_core.hpp>
  35. namespace boost{
  36. namespace serialization {
  37. namespace stl {
  38. //////////////////////////////////////////////////////////////////////
  39. // implementation of serialization for STL containers
  40. //
  41. template<
  42. class Archive,
  43. class T
  44. >
  45. typename boost::enable_if<
  46. typename detail::is_default_constructible<
  47. typename T::value_type
  48. >,
  49. void
  50. >::type
  51. collection_load_impl(
  52. Archive & ar,
  53. T & t,
  54. collection_size_type count,
  55. item_version_type /*item_version*/
  56. ){
  57. t.resize(count);
  58. typename T::iterator hint;
  59. hint = t.begin();
  60. while(count-- > 0){
  61. ar >> boost::serialization::make_nvp("item", *hint++);
  62. }
  63. }
  64. template<
  65. class Archive,
  66. class T
  67. >
  68. typename boost::disable_if<
  69. typename detail::is_default_constructible<
  70. typename T::value_type
  71. >,
  72. void
  73. >::type
  74. collection_load_impl(
  75. Archive & ar,
  76. T & t,
  77. collection_size_type count,
  78. item_version_type item_version
  79. ){
  80. t.clear();
  81. while(count-- > 0){
  82. detail::stack_construct<Archive, typename T::value_type> u(ar, item_version);
  83. ar >> boost::serialization::make_nvp("item", u.reference());
  84. t.push_back(boost::move(u.reference()));
  85. ar.reset_object_address(& t.back() , u.address());
  86. }
  87. }
  88. } // namespace stl
  89. } // namespace serialization
  90. } // namespace boost
  91. #endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP