1 | #include <boost/archive/xml_oarchive.hpp>
|
---|
2 | #include <boost/archive/xml_iarchive.hpp>
|
---|
3 | #include <boost/serialization/nvp.hpp>
|
---|
4 | #include <boost/serialization/vector.hpp>
|
---|
5 | #include <boost/tuple/tuple.hpp>
|
---|
6 |
|
---|
7 | #include <iostream>
|
---|
8 | #include <vector>
|
---|
9 | #include <sstream>
|
---|
10 |
|
---|
11 | namespace boost {
|
---|
12 | namespace serialization {
|
---|
13 |
|
---|
14 | template<typename archive, typename T0, typename T1, typename T2>
|
---|
15 | void serialize(archive & ar, boost::tuple<T0, T1, T2> & tpl, unsigned int) {
|
---|
16 | using namespace boost;
|
---|
17 | using boost::serialization::make_nvp;
|
---|
18 |
|
---|
19 | ar
|
---|
20 | & make_nvp("tpl_0", boost::get<0>(tpl))
|
---|
21 | & make_nvp("tpl_1", boost::get<1>(tpl))
|
---|
22 | & make_nvp("tpl_2", boost::get<2>(tpl));
|
---|
23 | }
|
---|
24 |
|
---|
25 | } /* namespace serialization */
|
---|
26 | } /* namespace boost */
|
---|
27 |
|
---|
28 | int main() {
|
---|
29 | std::vector<boost::tuple<double, double, double> > t_vec, t_vec2(1);
|
---|
30 | std::ostringstream oss;
|
---|
31 |
|
---|
32 | t_vec.push_back(boost::tuple<double, double, double>(1.,2.,3.));
|
---|
33 | std::cout << "t_vec.size() = " << t_vec.size() << std::endl;
|
---|
34 |
|
---|
35 | // save data to archive
|
---|
36 | {
|
---|
37 | boost::archive::xml_oarchive oa(oss);
|
---|
38 | // write class instance to archive
|
---|
39 | oa & BOOST_SERIALIZATION_NVP(t_vec);
|
---|
40 | // archive and stream closed when destructors are called
|
---|
41 | // Data is now in oss
|
---|
42 | }
|
---|
43 |
|
---|
44 | // load data from archive
|
---|
45 | {
|
---|
46 | std::istringstream iss(oss.str());
|
---|
47 | boost::archive::xml_iarchive ia(iss);
|
---|
48 | // read class state from archive
|
---|
49 | ia & BOOST_SERIALIZATION_NVP(t_vec2);
|
---|
50 | // archive and stream closed when destructors are called
|
---|
51 | }
|
---|
52 |
|
---|
53 | std::cout << "t_vec2.size() = " << t_vec2.size() << std::endl;
|
---|
54 | }
|
---|