Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/serialization/example/demo_polymorphic.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.0 KB
Line 
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// demo_polymorphic.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 <sstream>
12
13#include <boost/archive/polymorphic_text_iarchive.hpp>
14#include <boost/archive/polymorphic_text_oarchive.hpp>
15
16#include <boost/archive/polymorphic_binary_iarchive.hpp>
17#include <boost/archive/polymorphic_binary_oarchive.hpp>
18
19#include "demo_polymorphic_A.hpp"
20
21int main(int argc, char* argv[])
22{
23    const A a;
24    A a1;
25    {
26        // test with a text archive
27        std::stringstream ss;
28        {
29            // instantiate archive which inhertis polymorphic interface
30            // and the normal text archive implementation
31            boost::archive::polymorphic_text_oarchive oa(ss);
32            boost::archive::polymorphic_oarchive & oa_interface = oa; 
33            // we can just just the interface for saving
34            oa_interface << a;
35        }
36        {
37            // or we can use the implementation directly
38            boost::archive::polymorphic_text_iarchive ia(ss);
39            ia >> a1;
40        }
41    }
42    if(! (a == a1))
43        return 1;
44    {
45        //test with a binary archive
46        std::stringstream ss;
47        {
48            // instantiate archive which inhertis polymorphic interface
49            // and the normal binary archive implementation
50            boost::archive::polymorphic_binary_oarchive oa(ss);
51            oa << a;
52        }
53        {
54            // see above
55            boost::archive::polymorphic_binary_iarchive ia(ss);
56            boost::archive::polymorphic_iarchive & ia_interface = ia; 
57            // use just the polymorphic interface for loading.
58            ia_interface >> a1;
59        }
60    }
61    if(! (a == a1))
62        return 1;
63    return 0;
64}
65
Note: See TracBrowser for help on using the repository browser.