weak_ptr.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // shared_ptr.hpp: serialization for boost shared 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("shared_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("shared_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. #endif // BOOST_SERIALIZATION_WEAK_PTR_HPP