slist.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef BOOST_SERIALIZATION_SLIST_HPP
  2. #define BOOST_SERIALIZATION_SLIST_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. // 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 <cstddef> // size_t
  15. #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
  16. #if defined(BOOST_NO_STDC_NAMESPACE)
  17. namespace std{
  18. using ::size_t;
  19. } // namespace std
  20. #endif
  21. #ifdef BOOST_HAS_SLIST
  22. #include BOOST_SLIST_HEADER
  23. #include <boost/serialization/collections_save_imp.hpp>
  24. #include <boost/serialization/collections_load_imp.hpp>
  25. #include <boost/serialization/split_free.hpp>
  26. #include <boost/serialization/nvp.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. template<class Archive, class U, class Allocator>
  41. inline void load(
  42. Archive & ar,
  43. BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
  44. const unsigned int file_version
  45. ){
  46. // retrieve number of elements
  47. t.clear();
  48. // retrieve number of elements
  49. collection_size_type count;
  50. ar >> BOOST_SERIALIZATION_NVP(count);
  51. if(std::size_t(0) == count)
  52. return;
  53. unsigned int v;
  54. if(3 < ar.get_library_version()){
  55. ar >> boost::serialization::make_nvp("item_version", v);
  56. }
  57. boost::serialization::detail::stack_construct<Archive, U> u(ar, v);
  58. ar >> boost::serialization::make_nvp("item", u.reference());
  59. t.push_front(u.reference());
  60. BOOST_DEDUCED_TYPENAME BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last;
  61. last = t.begin();
  62. std::size_t c = count;
  63. while(--c > 0){
  64. boost::serialization::detail::stack_construct<Archive, U>
  65. u(ar, file_version);
  66. ar >> boost::serialization::make_nvp("item", u.reference());
  67. last = t.insert_after(last, u.reference());
  68. ar.reset_object_address(& (*last), & u.reference());
  69. }
  70. }
  71. // split non-intrusive serialization function member into separate
  72. // non intrusive save/load member functions
  73. template<class Archive, class U, class Allocator>
  74. inline void serialize(
  75. Archive & ar,
  76. BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
  77. const unsigned int file_version
  78. ){
  79. boost::serialization::split_free(ar, t, file_version);
  80. }
  81. } // serialization
  82. } // namespace boost
  83. #include <boost/serialization/collection_traits.hpp>
  84. BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist)
  85. #endif // BOOST_HAS_SLIST
  86. #endif // BOOST_SERIALIZATION_SLIST_HPP