weak_ptr.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef BOOST_SERIALIZATION_WEAK_PTR_HPP
  2. #define BOOST_SERIALIZATION_WEAK_PTR_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. // weak_ptr.hpp: serialization for boost weak pointer
  9. // (C) Copyright 2004 Robert Ramey and Martin Ecker
  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/weak_ptr.hpp>
  15. #include <boost/serialization/shared_ptr.hpp>
  16. namespace boost {
  17. namespace serialization{
  18. template<class Archive, class T>
  19. inline void save(
  20. Archive & ar,
  21. const boost::weak_ptr< T > &t,
  22. const unsigned int /* file_version */
  23. ){
  24. const boost::shared_ptr< T > sp = t.lock();
  25. ar << boost::serialization::make_nvp("weak_ptr", sp);
  26. }
  27. template<class Archive, class T>
  28. inline void load(
  29. Archive & ar,
  30. boost::weak_ptr< T > &t,
  31. const unsigned int /* file_version */
  32. ){
  33. boost::shared_ptr< T > sp;
  34. ar >> boost::serialization::make_nvp("weak_ptr", sp);
  35. t = sp;
  36. }
  37. template<class Archive, class T>
  38. inline void serialize(
  39. Archive & ar,
  40. boost::weak_ptr< T > &t,
  41. const unsigned int file_version
  42. ){
  43. boost::serialization::split_free(ar, t, file_version);
  44. }
  45. } // namespace serialization
  46. } // namespace boost
  47. #ifndef BOOST_NO_CXX11_SMART_PTR
  48. #include <memory>
  49. namespace boost {
  50. namespace serialization{
  51. template<class Archive, class T>
  52. inline void save(
  53. Archive & ar,
  54. const std::weak_ptr< T > &t,
  55. const unsigned int /* file_version */
  56. ){
  57. const std::shared_ptr< T > sp = t.lock();
  58. ar << boost::serialization::make_nvp("weak_ptr", sp);
  59. }
  60. template<class Archive, class T>
  61. inline void load(
  62. Archive & ar,
  63. std::weak_ptr< T > &t,
  64. const unsigned int /* file_version */
  65. ){
  66. std::shared_ptr< T > sp;
  67. ar >> boost::serialization::make_nvp("weak_ptr", sp);
  68. t = sp;
  69. }
  70. template<class Archive, class T>
  71. inline void serialize(
  72. Archive & ar,
  73. std::weak_ptr< T > &t,
  74. const unsigned int file_version
  75. ){
  76. boost::serialization::split_free(ar, t, file_version);
  77. }
  78. } // namespace serialization
  79. } // namespace boost
  80. #endif // BOOST_NO_CXX11_SMART_PTR
  81. #endif // BOOST_SERIALIZATION_WEAK_PTR_HPP