Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/serialization/test/B.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.9 KB
Line 
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) && (_MSC_VER >= 1020)
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::fabs(w - rhs.w) <= std::numeric_limits<float>::round_error()
108        && std::fabs(x - rhs.x) <= std::numeric_limits<float>::round_error()
109    ;
110}
111
112#if 0
113template<class Archive>
114void inline B::save(Archive &ar, const unsigned int /* file_version */) const
115{
116    // write any base class info to the archive
117    ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
118
119    // write out members
120    ar << BOOST_SERIALIZATION_NVP(s);
121    ar << BOOST_SERIALIZATION_NVP(t);
122    ar << BOOST_SERIALIZATION_NVP(u);
123    ar << BOOST_SERIALIZATION_NVP(v);
124    ar << BOOST_SERIALIZATION_NVP(w);
125    ar << BOOST_SERIALIZATION_NVP(x);
126}
127
128template<class Archive>
129inline void B::load(Archive & ar, const unsigned int file_version)
130{
131    // read any base class info to the archive
132    ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
133    switch(file_version){
134    case 1:
135    case 2:
136        ar >> BOOST_SERIALIZATION_NVP(s);
137        ar >> BOOST_SERIALIZATION_NVP(t);
138        ar >> BOOST_SERIALIZATION_NVP(u);
139        ar >> BOOST_SERIALIZATION_NVP(v);
140        ar >> BOOST_SERIALIZATION_NVP(w);
141        ar >> BOOST_SERIALIZATION_NVP(x);
142    default:
143        break;
144    }
145}
146#endif
147#endif // BOOST_SERIALIZATION_TEST_B_HPP
Note: See TracBrowser for help on using the repository browser.