slist.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef BOOST_SERIALIZATION_SLIST_HPP
  2. #define BOOST_SERIALIZATION_SLIST_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. // slist.hpp
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <boost/config.hpp>
  15. #ifdef BOOST_HAS_SLIST
  16. #include BOOST_SLIST_HEADER
  17. #include <boost/serialization/collections_save_imp.hpp>
  18. #include <boost/serialization/collections_load_imp.hpp>
  19. #include <boost/serialization/nvp.hpp>
  20. #include <boost/serialization/collection_size_type.hpp>
  21. #include <boost/serialization/item_version_type.hpp>
  22. #include <boost/serialization/library_version_type.hpp>
  23. #include <boost/serialization/split_free.hpp>
  24. #include <boost/serialization/detail/stack_constructor.hpp>
  25. #include <boost/serialization/detail/is_default_constructible.hpp>
  26. #include <boost/move/utility_core.hpp>
  27. namespace boost {
  28. namespace serialization {
  29. template<class Archive, class U, class Allocator>
  30. inline void save(
  31. Archive & ar,
  32. const BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
  33. const unsigned int file_version
  34. ){
  35. boost::serialization::stl::save_collection<
  36. Archive,
  37. BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>
  38. >(ar, t);
  39. }
  40. namespace stl {
  41. template<
  42. class Archive,
  43. class T,
  44. class Allocator
  45. >
  46. typename boost::disable_if<
  47. typename detail::is_default_constructible<
  48. typename BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator>::value_type
  49. >,
  50. void
  51. >::type
  52. collection_load_impl(
  53. Archive & ar,
  54. BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator> &t,
  55. collection_size_type count,
  56. item_version_type item_version
  57. ){
  58. t.clear();
  59. boost::serialization::detail::stack_construct<Archive, T> u(ar, item_version);
  60. ar >> boost::serialization::make_nvp("item", u.reference());
  61. t.push_front(boost::move(u.reference()));
  62. typename BOOST_STD_EXTENSION_NAMESPACE::slist<T, Allocator>::iterator last;
  63. last = t.begin();
  64. ar.reset_object_address(&(*t.begin()) , & u.reference());
  65. while(--count > 0){
  66. detail::stack_construct<Archive, T> u(ar, item_version);
  67. ar >> boost::serialization::make_nvp("item", u.reference());
  68. last = t.insert_after(last, boost::move(u.reference()));
  69. ar.reset_object_address(&(*last) , & u.reference());
  70. }
  71. }
  72. } // stl
  73. template<class Archive, class U, class Allocator>
  74. inline void load(
  75. Archive & ar,
  76. BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
  77. const unsigned int file_version
  78. ){
  79. const boost::serialization::library_version_type library_version(
  80. ar.get_library_version()
  81. );
  82. // retrieve number of elements
  83. item_version_type item_version(0);
  84. collection_size_type count;
  85. ar >> BOOST_SERIALIZATION_NVP(count);
  86. if(boost::serialization::library_version_type(3) < library_version){
  87. ar >> BOOST_SERIALIZATION_NVP(item_version);
  88. }
  89. if(detail::is_default_constructible<U>()){
  90. t.resize(count);
  91. typename BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator hint;
  92. hint = t.begin();
  93. while(count-- > 0){
  94. ar >> boost::serialization::make_nvp("item", *hint++);
  95. }
  96. }
  97. else{
  98. t.clear();
  99. boost::serialization::detail::stack_construct<Archive, U> u(ar, item_version);
  100. ar >> boost::serialization::make_nvp("item", u.reference());
  101. t.push_front(boost::move(u.reference()));
  102. typename BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last;
  103. last = t.begin();
  104. ar.reset_object_address(&(*t.begin()) , & u.reference());
  105. while(--count > 0){
  106. detail::stack_construct<Archive, U> u(ar, item_version);
  107. ar >> boost::serialization::make_nvp("item", u.reference());
  108. last = t.insert_after(last, boost::move(u.reference()));
  109. ar.reset_object_address(&(*last) , & u.reference());
  110. }
  111. }
  112. }
  113. // split non-intrusive serialization function member into separate
  114. // non intrusive save/load member functions
  115. template<class Archive, class U, class Allocator>
  116. inline void serialize(
  117. Archive & ar,
  118. BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
  119. const unsigned int file_version
  120. ){
  121. boost::serialization::split_free(ar, t, file_version);
  122. }
  123. } // serialization
  124. } // namespace boost
  125. #include <boost/serialization/collection_traits.hpp>
  126. BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist)
  127. #endif // BOOST_HAS_SLIST
  128. #endif // BOOST_SERIALIZATION_SLIST_HPP