Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/serialization/test/test_contained_class.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 1.7 KB
Line 
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_contained_class.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// should pass compilation and execution
10
11#include <fstream>
12
13#include <cstdio> // remove
14#include <boost/config.hpp>
15#if defined(BOOST_NO_STDC_NAMESPACE)
16namespace std{ 
17    using ::remove;
18}
19#endif
20
21#include "test_tools.hpp"
22#include <boost/preprocessor/stringize.hpp>
23#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
24#include <boost/serialization/nvp.hpp>
25
26#include "B.hpp"
27
28///////////////////////////////////////////////////////
29// Contained class
30class C
31{
32private:
33    friend class boost::serialization::access;
34    template<class Archive>
35    void serialize(Archive & ar, const unsigned int /* file_version */){
36        ar & BOOST_SERIALIZATION_NVP(b);
37    }
38    B b;
39public:
40    bool operator==(const C &rhs) const
41    {
42        return b == rhs.b;
43    }
44};
45
46int test_main( int /* argc */, char* /* argv */[] )
47{
48    const char * testfile = boost::archive::tmpnam(NULL);
49    BOOST_REQUIRE(NULL != testfile);
50
51    const C c;
52    C c1;
53    {   
54        test_ostream os(testfile, TEST_STREAM_FLAGS);
55        test_oarchive oa(os);
56        oa << boost::serialization::make_nvp("c", c);
57    }
58    {
59        test_istream is(testfile, TEST_STREAM_FLAGS);
60        test_iarchive ia(is);
61        ia >> boost::serialization::make_nvp("c", c1);
62    }
63    BOOST_CHECK(c == c1);
64    std::remove(testfile);
65    return EXIT_SUCCESS;
66}
67
68// EOF
Note: See TracBrowser for help on using the repository browser.