-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspni.cpp
60 lines (51 loc) · 1.38 KB
/
spni.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <sstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class Lattice;
// forward declaration
namespace boost {
namespace serialization {
template <class Archive>
void serialize(Archive&, Lattice*, const unsigned int=0);
}
}
class Lattice
{
int a;
public:
Lattice() {}
Lattice(int _a) {a = _a; }
void str(std::string indent=" ")
{
std::cout << "val :" << indent << a << std::endl;
}
template <class Archive>
friend void boost::serialization::serialize(Archive&, Lattice*, const unsigned int version=0);
};
// non-intrusive serialization
namespace boost {
namespace serialization {
template <class Archive>
void serialize(Archive& ar, Lattice* lattice, const unsigned int version=0)
{
ar & lattice->a;
}
}
}
int main()
{
Lattice *wlattice = new Lattice(14);
Lattice *rlattice = new Lattice();
std::stringstream w_str;
// serialize wlattice into w_str
boost::archive::text_oarchive oarchive(w_str);
boost::serialization::serialize(oarchive, wlattice);
rlattice->str();
// deserialize wlattice from w_str to r_lattice
boost::archive::text_iarchive iarchive(w_str);
boost::serialization::serialize(iarchive, rlattice);
rlattice->str();
return 0;
}