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<> BOOST_SERIALIZATION_NVP(mytb);
}
cout<<"after restore tb size is: "<
<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