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