[Q] help serializing a multiset of shared ptrs

Hello,
I am sure I am not doing things quite right in serializing my
multiset, however I could not 'connect the dots' in the serialize
documentation between serializing shared pointers and containers.
Therefore, asking for help.
I created a complete compilable example, that I am attaching below
and the created output file. The program crashes on the last line
when I am trying to load the data back in.
Any help is greatly appreciated,
Vlad
-------------- prog start ----------------
#include <iostream>
#include <fstream>
#include <ostream>
#include <ctime>
#include <cstdlib>
#include <set>
#include <algorithm>
#include

Hi,
did not get any replies,
just wanted to see if may be there is serialize specific list
or if anybody can recommend an example that serializes
an associative container of shared pointers
thank you in advance
On Mon, 15 Jun 2009 00:57 -0400, "V S P"
Hello,
I am sure I am not doing things quite right in serializing my multiset, however I could not 'connect the dots' in the serialize documentation between serializing shared pointers and containers.
Therefore, asking for help.
I created a complete compilable example, that I am attaching below and the created output file. The program crashes on the last line when I am trying to load the data back in.
Any help is greatly appreciated, Vlad -------------- prog start ---------------- #include <iostream> #include <fstream> #include <ostream> #include <ctime> #include <cstdlib>
#include <set> #include <algorithm>
#include
#include #include #include #include #include #include #include #include #include
#include #include #include
using namespace std; using namespace boost;
template
> struct cactivetable_t: public TContainer, private boost::noncopyable { template <typename Archive> void serialize (Archive& ar, const unsigned int version) {
for (TContainer::const_iterator it=begin(); it!=end();it++) { (*it)->myserialize(ar,version); } }
};
struct tRow { int a; string b;
template <typename Archive> void myserialize (Archive& ar, const unsigned int version) { ar&boost::serialization::make_nvp("a", a); ar&boost::serialization::make_nvp("b", b); }
};
struct randrow { shared_ptr<tRow> operator()(void) { shared_ptr<tRow> p(new tRow); p->a=rand()%100; p->b=lexical_cast<string>(p->a); return p; }
};
void main (void) { cactivetable_t<tRow> mytb; shared_ptr<tRow> tmpP(new tRow);
for (size_t i=0;i<10;i++) { /*note for multiset we can insert the same thing many times */ mytb.insert(tmpP); }
randrow rw; generate(mytb.begin(),mytb.end(),rw);
// make an archive { ofstream ofs("xyz.sxml"); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa<
cout<<"finished serializing, now lets try to read back"<
{ // open the archive std::ifstream ifs("xyz.sxml"); assert(ifs.good()); boost::archive::xml_iarchive ia(ifs);
// restore the schedule from the archive ia >> BOOST_SERIALIZATION_NVP(mytb); }
cout<<"after restore tb size is: "<
}
-------------- prog end -------------------
-- archive xyz.sxml XML start ----
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<mytb class_id="0" tracking_level="0" version="0"> <a>41</a> <b>41</b> <a>67</a> <b>67</b> <a>34</a> <b>34</b> <a>0</a> <b>0</b> <a>69</a> <b>69</b> <a>24</a> <b>24</b> <a>78</a> <b>78</b> <a>58</a> <b>58</b> <a>62</a> <b>62</b> <a>64</a> <b>64</b> </mytb> --- archive XML end ---- -- V S P toreason@fastmail.fm
-- http://www.fastmail.fm - Access all of your messages and folders wherever you are
-- V S P toreason@fastmail.fm -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again
participants (1)
-
V S P