demo_dll_b.ipp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef BOOST_SERIALIZATION_TEST_B_HPP
  2. #define BOOST_SERIALIZATION_TEST_B_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. // B.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 <cstdlib> // for rand()
  15. #include <boost/config.hpp>
  16. #if defined(BOOST_NO_STDC_NAMESPACE)
  17. namespace std{
  18. using ::rand;
  19. }
  20. #endif
  21. #include <boost/serialization/version.hpp>
  22. #include <boost/serialization/split_member.hpp>
  23. #include <boost/serialization/base_object.hpp>
  24. #include "A.hpp"
  25. ///////////////////////////////////////////////////////
  26. // Derived class test
  27. class B : public A
  28. {
  29. private:
  30. friend class boost::serialization::access;
  31. template<class Archive>
  32. void save(Archive &ar, const unsigned int /* file_version */) const
  33. {
  34. // write any base class info to the archive
  35. ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
  36. // write out members
  37. ar << BOOST_SERIALIZATION_NVP(s);
  38. ar << BOOST_SERIALIZATION_NVP(t);
  39. ar << BOOST_SERIALIZATION_NVP(u);
  40. ar << BOOST_SERIALIZATION_NVP(v);
  41. ar << BOOST_SERIALIZATION_NVP(w);
  42. ar << BOOST_SERIALIZATION_NVP(x);
  43. }
  44. template<class Archive>
  45. void load(Archive & ar, const unsigned int file_version)
  46. {
  47. // read any base class info to the archive
  48. ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
  49. switch(file_version){
  50. case 1:
  51. case 2:
  52. ar >> BOOST_SERIALIZATION_NVP(s);
  53. ar >> BOOST_SERIALIZATION_NVP(t);
  54. ar >> BOOST_SERIALIZATION_NVP(u);
  55. ar >> BOOST_SERIALIZATION_NVP(v);
  56. ar >> BOOST_SERIALIZATION_NVP(w);
  57. ar >> BOOST_SERIALIZATION_NVP(x);
  58. default:
  59. break;
  60. }
  61. }
  62. BOOST_SERIALIZATION_SPLIT_MEMBER()
  63. signed char s;
  64. unsigned char t;
  65. signed int u;
  66. unsigned int v;
  67. float w;
  68. double x;
  69. public:
  70. B();
  71. virtual ~B(){};
  72. bool operator==(const B &rhs) const;
  73. };
  74. B::B() :
  75. s(std::rand()),
  76. t(std::rand()),
  77. u(std::rand()),
  78. v(std::rand()),
  79. w((float)std::rand() / std::rand()),
  80. x((double)std::rand() / std::rand())
  81. {
  82. }
  83. BOOST_CLASS_VERSION(B, 2)
  84. inline bool B::operator==(const B &rhs) const
  85. {
  86. return
  87. A::operator==(rhs)
  88. && s == rhs.s
  89. && t == rhs.t
  90. && u == rhs.u
  91. && v == rhs.v
  92. && std::abs( boost::math::float_distance(w, rhs.w)) < 2
  93. && std::abs( boost::math::float_distance(x, rhs.x)) < 2
  94. ;
  95. }
  96. #endif // BOOST_SERIALIZATION_TEST_B_HPP