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