| 1 | #include <boost/shared_ptr.hpp>
|
|---|
| 2 | #include <boost/serialization/nvp.hpp>
|
|---|
| 3 | #include <boost/serialization/shared_ptr.hpp>
|
|---|
| 4 | #include <boost/archive/binary_iarchive.hpp>
|
|---|
| 5 |
|
|---|
| 6 | #include <fstream>
|
|---|
| 7 |
|
|---|
| 8 | struct XXX
|
|---|
| 9 | {
|
|---|
| 10 | std::string name;
|
|---|
| 11 | int age;
|
|---|
| 12 |
|
|---|
| 13 | template<class Archive>
|
|---|
| 14 | void serialize(Archive & ar, const unsigned int)
|
|---|
| 15 | {
|
|---|
| 16 | ar & BOOST_SERIALIZATION_NVP(name)
|
|---|
| 17 | & BOOST_SERIALIZATION_NVP(age);
|
|---|
| 18 | }
|
|---|
| 19 | };
|
|---|
| 20 | BOOST_SERIALIZATION_SHARED_PTR(XXX)
|
|---|
| 21 |
|
|---|
| 22 | struct YYY
|
|---|
| 23 | {
|
|---|
| 24 | boost::shared_ptr<XXX> xxx;
|
|---|
| 25 |
|
|---|
| 26 | template<class Archive>
|
|---|
| 27 | void serialize(Archive & ar, const unsigned int)
|
|---|
| 28 | {
|
|---|
| 29 | ar & BOOST_SERIALIZATION_NVP(xxx);
|
|---|
| 30 | }
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | int main(int argc, char**argv)
|
|---|
| 35 | {
|
|---|
| 36 | YYY yyy;
|
|---|
| 37 | std::ifstream ifs("test_output", std::ios::binary);
|
|---|
| 38 | typedef boost::archive::binary_iarchive InArchive;
|
|---|
| 39 | InArchive ia(ifs);
|
|---|
| 40 | ia >> yyy;
|
|---|
| 41 |
|
|---|
| 42 | return 0;
|
|---|
| 43 | }
|
|---|