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