File: B.hpp

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (147 lines) | stat: -rw-r--r-- 3,970 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef BOOST_SERIALIZATION_TEST_B_HPP
#define BOOST_SERIALIZATION_TEST_B_HPP

// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// B.hpp

// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org for updates, documentation, and revision history.

#include <cstdlib> // for rand()

#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
    using ::rand; 
}
#endif

#include <boost/serialization/version.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/base_object.hpp>

#include "A.hpp"

///////////////////////////////////////////////////////
// Derived class test
class B : public A
{
private:
    friend class boost::serialization::access;
    template<class Archive>
    void save(Archive &ar, const unsigned int /* file_version */) const
    {
        // write any base class info to the archive
        ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);

        // write out members
        ar << BOOST_SERIALIZATION_NVP(s);
        ar << BOOST_SERIALIZATION_NVP(t);
        ar << BOOST_SERIALIZATION_NVP(u);
        ar << BOOST_SERIALIZATION_NVP(v);
        ar << BOOST_SERIALIZATION_NVP(w);
        ar << BOOST_SERIALIZATION_NVP(x);
    }

    template<class Archive>
    void load(Archive & ar, const unsigned int file_version)
    {
        // read any base class info to the archive
        ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
        switch(file_version){
        case 1:
        case 2:
            ar >> BOOST_SERIALIZATION_NVP(s);
            ar >> BOOST_SERIALIZATION_NVP(t);
            ar >> BOOST_SERIALIZATION_NVP(u);
            ar >> BOOST_SERIALIZATION_NVP(v);
            ar >> BOOST_SERIALIZATION_NVP(w);
            ar >> BOOST_SERIALIZATION_NVP(x);
        default:
            break;
        }
    }

    BOOST_SERIALIZATION_SPLIT_MEMBER()
    signed char s;
    unsigned char t;
    signed int u;
    unsigned int v;
    float w;
    double x;
public:
    B();
    virtual ~B(){};
    bool operator==(const B &rhs) const;
};

B::B() :
    s(std::rand()),
    t(std::rand()),
    u(std::rand()),
    v(std::rand()),
    w((float)std::rand() / std::rand()),
    x((double)std::rand() / std::rand())
{
}

BOOST_CLASS_VERSION(B, 2)

inline bool B::operator==(const B &rhs) const
{
    return
        A::operator==(rhs)
        && s == rhs.s 
        && t == rhs.t 
        && u == rhs.u 
        && v == rhs.v 
        && std::fabs(w - rhs.w) <= std::numeric_limits<float>::round_error()
        && std::fabs(x - rhs.x) <= std::numeric_limits<float>::round_error()
    ;
}

#if 0
template<class Archive>
void inline B::save(Archive &ar, const unsigned int /* file_version */) const
{
    // write any base class info to the archive
    ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);

    // write out members
    ar << BOOST_SERIALIZATION_NVP(s);
    ar << BOOST_SERIALIZATION_NVP(t);
    ar << BOOST_SERIALIZATION_NVP(u);
    ar << BOOST_SERIALIZATION_NVP(v);
    ar << BOOST_SERIALIZATION_NVP(w);
    ar << BOOST_SERIALIZATION_NVP(x);
}

template<class Archive>
inline void B::load(Archive & ar, const unsigned int file_version)
{
    // read any base class info to the archive
    ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
    switch(file_version){
    case 1:
    case 2:
        ar >> BOOST_SERIALIZATION_NVP(s);
        ar >> BOOST_SERIALIZATION_NVP(t);
        ar >> BOOST_SERIALIZATION_NVP(u);
        ar >> BOOST_SERIALIZATION_NVP(v);
        ar >> BOOST_SERIALIZATION_NVP(w);
        ar >> BOOST_SERIALIZATION_NVP(x);
    default:
        break;
    }
}
#endif
#endif // BOOST_SERIALIZATION_TEST_B_HPP