| 1 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 2 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 3 | #include <boost/serialization/serialization.hpp>
|
|---|
| 4 | #include <boost/serialization/vector.hpp>
|
|---|
| 5 | #include <vector>
|
|---|
| 6 | #include <sstream>
|
|---|
| 7 |
|
|---|
| 8 | class A
|
|---|
| 9 | {
|
|---|
| 10 | public:
|
|---|
| 11 | A(int i) {}
|
|---|
| 12 |
|
|---|
| 13 | private:
|
|---|
| 14 | A() {}
|
|---|
| 15 | friend class boost::serialization::access;
|
|---|
| 16 | template<class Archive>
|
|---|
| 17 | void serialize(Archive& ar, const unsigned int version)
|
|---|
| 18 | {
|
|---|
| 19 | }
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 | class B
|
|---|
| 23 | {
|
|---|
| 24 | public:
|
|---|
| 25 | B() {}
|
|---|
| 26 |
|
|---|
| 27 | private:
|
|---|
| 28 | std::vector<A> m_a;
|
|---|
| 29 |
|
|---|
| 30 | friend class boost::serialization::access;
|
|---|
| 31 | template<class Archive>
|
|---|
| 32 | void serialize(Archive& ar, const unsigned int version)
|
|---|
| 33 | {
|
|---|
| 34 | ar & BOOST_SERIALIZATION_NVP(m_a);
|
|---|
| 35 | }
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | int main(int argc, char* argv[])
|
|---|
| 40 | {
|
|---|
| 41 | std::ostringstream os;
|
|---|
| 42 | boost::archive::text_oarchive oa(os);
|
|---|
| 43 | {
|
|---|
| 44 | B b;
|
|---|
| 45 | oa & b;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | {
|
|---|
| 49 | std::stringstream myIstream;
|
|---|
| 50 | myIstream.write(os.str().c_str(), os.str().length());
|
|---|
| 51 | boost::archive::text_iarchive ia(myIstream);
|
|---|
| 52 |
|
|---|
| 53 | B b;
|
|---|
| 54 | ia >> b;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | return 0;
|
|---|
| 58 | }
|
|---|