slist.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(collection_size_type(0) == count)
  52. return;
  53. item_version_type item_version(0);
  54. const boost::archive::library_version_type library_version(
  55. ar.get_library_version()
  56. );
  57. if(boost::archive::library_version_type(3) < library_version){
  58. ar >> BOOST_SERIALIZATION_NVP(item_version);
  59. }
  60. boost::serialization::detail::stack_construct<Archive, U> u(ar, item_version);
  61. ar >> boost::serialization::make_nvp("item", u.reference());
  62. t.push_front(u.reference());
  63. BOOST_DEDUCED_TYPENAME BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator>::iterator last;
  64. last = t.begin();
  65. while(--count > 0){
  66. boost::serialization::detail::stack_construct<Archive, U>
  67. u(ar, file_version);
  68. ar >> boost::serialization::make_nvp("item", u.reference());
  69. last = t.insert_after(last, u.reference());
  70. ar.reset_object_address(& (*last), & u.reference());
  71. }
  72. }
  73. // split non-intrusive serialization function member into separate
  74. // non intrusive save/load member functions
  75. template<class Archive, class U, class Allocator>
  76. inline void serialize(
  77. Archive & ar,
  78. BOOST_STD_EXTENSION_NAMESPACE::slist<U, Allocator> &t,
  79. const unsigned int file_version
  80. ){
  81. boost::serialization::split_free(ar, t, file_version);
  82. }
  83. } // serialization
  84. } // namespace boost
  85. #include <boost/serialization/collection_traits.hpp>
  86. BOOST_SERIALIZATION_COLLECTION_TRAITS(BOOST_STD_EXTENSION_NAMESPACE::slist)
  87. #endif // BOOST_HAS_SLIST
  88. #endif // BOOST_SERIALIZATION_SLIST_HPP