| 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|---|---|
| 2 | // test_private_ctor.cpp |
| 3 | |
| 4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
| 5 | // Use, modification and distribution is subject to the Boost Software |
| 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | #include <sstream> |
| 10 | |
| 11 | #include "test_tools.hpp" |
| 12 | |
| 13 | #include <boost/serialization/vector.hpp> |
| 14 | |
| 15 | #include <boost/archive/text_iarchive.hpp> |
| 16 | #include <boost/archive/text_oarchive.hpp> |
| 17 | |
| 18 | class V { |
| 19 | private: |
| 20 | friend int test_main(int /* argc */, char * /* argv */[]); |
| 21 | friend class boost::serialization::access; |
| 22 | int m_i; |
| 23 | V() : |
| 24 | m_i(0) |
| 25 | {} |
| 26 | template<class Archive> |
| 27 | void serialize(Archive& ar, unsigned /*version*/) |
| 28 | { |
| 29 | ar & m_i; |
| 30 | } |
| 31 | public: |
| 32 | ~V(){} |
| 33 | bool operator==(const V & v) const { |
| 34 | return m_i == v.m_i; |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | int test_main(int /* argc */, char * /* argv */[]) |
| 39 | { |
| 40 | std::stringstream ss; |
| 41 | const V v; |
| 42 | { |
| 43 | boost::archive::text_oarchive oa(ss); |
| 44 | oa << v; |
| 45 | ss.flush(); |
| 46 | } |
| 47 | V v1; |
| 48 | { |
| 49 | boost::archive::text_iarchive ia(ss); |
| 50 | ia >> v1; |
| 51 | } |
| 52 | BOOST_CHECK(v == v1); |
| 53 | |
| 54 | const V *vptr = & v; |
| 55 | { |
| 56 | boost::archive::text_oarchive oa(ss); |
| 57 | oa << vptr; |
| 58 | ss.flush(); |
| 59 | } |
| 60 | V *vptr1; |
| 61 | { |
| 62 | boost::archive::text_iarchive ia(ss); |
| 63 | ia >> vptr1; |
| 64 | } |
| 65 | BOOST_CHECK(*vptr == *vptr1); |
| 66 | |
| 67 | return EXIT_SUCCESS; |
| 68 | } |
| 69 |
