1 #ifndef BOOST_SERIALIZATION_TEST_B_HPP
2 #define BOOST_SERIALIZATION_TEST_B_HPP
3
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER)
6 # pragma once
7 #endif
8
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // B.hpp
11
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16
17 // See http://www.boost.org for updates, documentation, and revision history.
18
19 #include <cstdlib> // for rand()
20 #include <boost/math/special_functions/next.hpp>
21
22 #include <boost/config.hpp>
23 #if defined(BOOST_NO_STDC_NAMESPACE)
24 namespace std{
25 using ::rand;
26 }
27 #endif
28
29 #include <boost/serialization/version.hpp>
30 #include <boost/serialization/split_member.hpp>
31 #include <boost/serialization/base_object.hpp>
32
33 #include "A.hpp"
34
35 ///////////////////////////////////////////////////////
36 // Derived class test
37 class B : public A
38 {
39 private:
40 friend class boost::serialization::access;
41 template<class Archive>
save(Archive & ar,const unsigned int) const42 void save(Archive &ar, const unsigned int /* file_version */) const
43 {
44 // write any base class info to the archive
45 ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
46
47 // write out members
48 ar << BOOST_SERIALIZATION_NVP(s);
49 ar << BOOST_SERIALIZATION_NVP(t);
50 ar << BOOST_SERIALIZATION_NVP(u);
51 ar << BOOST_SERIALIZATION_NVP(v);
52 ar << BOOST_SERIALIZATION_NVP(w);
53 ar << BOOST_SERIALIZATION_NVP(x);
54 }
55
56 template<class Archive>
load(Archive & ar,const unsigned int file_version)57 void load(Archive & ar, const unsigned int file_version)
58 {
59 // read any base class info to the archive
60 ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
61 switch(file_version){
62 case 1:
63 case 2:
64 ar >> BOOST_SERIALIZATION_NVP(s);
65 ar >> BOOST_SERIALIZATION_NVP(t);
66 ar >> BOOST_SERIALIZATION_NVP(u);
67 ar >> BOOST_SERIALIZATION_NVP(v);
68 ar >> BOOST_SERIALIZATION_NVP(w);
69 ar >> BOOST_SERIALIZATION_NVP(x);
70 default:
71 break;
72 }
73 }
74
75 BOOST_SERIALIZATION_SPLIT_MEMBER()
76 signed char s;
77 unsigned char t;
78 signed int u;
79 unsigned int v;
80 float w;
81 double x;
82 public:
83 B();
~B()84 virtual ~B(){};
85 bool operator==(const B &rhs) const;
86 };
87
B()88 B::B() :
89 s(std::rand()),
90 t(std::rand()),
91 u(std::rand()),
92 v(std::rand()),
93 w((float)std::rand() / std::rand()),
94 x((double)std::rand() / std::rand())
95 {
96 }
97
98 BOOST_CLASS_VERSION(B, 2)
99
operator ==(const B & rhs) const100 inline bool B::operator==(const B &rhs) const
101 {
102 return
103 A::operator==(rhs)
104 && s == rhs.s
105 && t == rhs.t
106 && u == rhs.u
107 && v == rhs.v
108 && std::abs( boost::math::float_distance(w, rhs.w)) < 2
109 && std::abs( boost::math::float_distance(x, rhs.x)) < 2
110 ;
111 }
112
113 #endif // BOOST_SERIALIZATION_TEST_B_HPP
114