demo_dll_b.hpp 2.9 KB

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