1 | #ifndef BOOST_SERIALIZATION_TEST_D_HPP |
---|---|
2 | #define BOOST_SERIALIZATION_TEST_D_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 | // D.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 <cstddef> // NULL |
20 | |
21 | #include "test_tools.hpp" |
22 | #include <boost/core/no_exceptions_support.hpp> |
23 | #include <boost/serialization/throw_exception.hpp> |
24 | #include <boost/serialization/split_member.hpp> |
25 | |
26 | #include "B.hpp" |
27 | |
28 | /////////////////////////////////////////////////////// |
29 | // Contained class with multiple identical pointers |
30 | class D |
31 | { |
32 | private: |
33 | friend class boost::serialization::access; |
34 | B *b1; |
35 | B *b2; |
36 | template<class Archive> |
37 | void save(Archive &ar, const unsigned int file_version) const{ |
38 | ar << BOOST_SERIALIZATION_NVP(b1); |
39 | ar << BOOST_SERIALIZATION_NVP(b2); |
40 | } |
41 | |
42 | template<class Archive> |
43 | void load(Archive & ar, const unsigned int file_version){ |
44 | BOOST_TRY { |
45 | ar >> boost::serialization::make_nvp(n: "b", v&: b1); |
46 | ar >> boost::serialization::make_nvp(n: "b", v&: b2); |
47 | } |
48 | BOOST_CATCH (...){ |
49 | // eliminate invalid pointers |
50 | b1 = NULL; |
51 | b2 = NULL; |
52 | BOOST_FAIL( "multiple identical pointers failed to load"); |
53 | } |
54 | BOOST_CATCH_END |
55 | // check that loading was correct |
56 | BOOST_CHECK(b1 == b2); |
57 | } |
58 | |
59 | BOOST_SERIALIZATION_SPLIT_MEMBER() |
60 | public: |
61 | D(); |
62 | ~D(); |
63 | bool operator==(const D &rhs) const; |
64 | }; |
65 | |
66 | BOOST_CLASS_VERSION(D, 3) |
67 | |
68 | D::D() |
69 | { |
70 | b1 = new B(); |
71 | b2 = b1; |
72 | } |
73 | |
74 | D::~D() |
75 | { |
76 | delete b1; |
77 | } |
78 | |
79 | bool D::operator==(const D &rhs) const |
80 | { |
81 | if(! (*b1 == *(rhs.b1)) ) |
82 | return false; |
83 | if(! (*b2 == *(rhs.b2)) ) |
84 | return false; |
85 | return true; |
86 | } |
87 | |
88 | #endif // BOOST_SERIALIZATION_TEST_D_HPP |
89 |