D.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef BOOST_SERIALIZATION_TEST_D_HPP
  2. #define BOOST_SERIALIZATION_TEST_D_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. // D.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> // NULL
  15. #include "test_tools.hpp"
  16. #include <boost/detail/no_exceptions_support.hpp>
  17. #include <boost/serialization/throw_exception.hpp>
  18. #include <boost/serialization/split_member.hpp>
  19. #include "B.hpp"
  20. ///////////////////////////////////////////////////////
  21. // Contained class with multiple identical pointers
  22. class D
  23. {
  24. private:
  25. friend class boost::serialization::access;
  26. B *b1;
  27. B *b2;
  28. template<class Archive>
  29. void save(Archive &ar, const unsigned int file_version) const{
  30. ar << BOOST_SERIALIZATION_NVP(b1);
  31. ar << BOOST_SERIALIZATION_NVP(b2);
  32. }
  33. template<class Archive>
  34. void load(Archive & ar, const unsigned int file_version){
  35. BOOST_TRY {
  36. ar >> boost::serialization::make_nvp("b", b1);
  37. ar >> boost::serialization::make_nvp("b", b2);
  38. }
  39. BOOST_CATCH (...){
  40. // eliminate invalid pointers
  41. b1 = NULL;
  42. b2 = NULL;
  43. BOOST_FAIL( "multiple identical pointers failed to load" );
  44. }
  45. BOOST_CATCH_END
  46. // check that loading was correct
  47. BOOST_CHECK(b1 == b2);
  48. }
  49. BOOST_SERIALIZATION_SPLIT_MEMBER()
  50. public:
  51. D();
  52. ~D();
  53. bool operator==(const D &rhs) const;
  54. };
  55. BOOST_CLASS_VERSION(D, 3)
  56. D::D()
  57. {
  58. b1 = new B();
  59. b2 = b1;
  60. }
  61. D::~D()
  62. {
  63. delete b1;
  64. }
  65. bool D::operator==(const D &rhs) const
  66. {
  67. if(! (*b1 == *(rhs.b1)) )
  68. return false;
  69. if(! (*b2 == *(rhs.b2)) )
  70. return false;
  71. return true;
  72. }
  73. #endif // BOOST_SERIALIZATION_TEST_D_HPP