|
Boost Users : |
From: gast128 (gast128_at_[hidden])
Date: 2007-03-06 04:14:21
Robert Ramey <ramey <at> rrsd.com> writes:
>
> I don't see any problem with the code snippet. Maybe you want
> to make small test which we run here.
ok here it comes. It looks artificial, but it is just a simplification of a
case. It gives an access violation after thhe load, when it tries to destroy
the object.
#include <boost/algorithm/string/replace.hpp>
namespace
{
struct BoostExampleData
{
BoostExampleData()
: m_i(0)
{}
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & BOOST_SERIALIZATION_NVP(m_i);
}
public: //data
int m_i;
};
struct BoostExample
{
BoostExample()
{
m_ptr.reset(new BoostExampleData);
m_ptr1.reset(new BoostExampleData);
}
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & BOOST_SERIALIZATION_NVP(m_ptr);
ar & BOOST_SERIALIZATION_NVP(m_ptr1);
}
public: //data
typedef boost::shared_ptr<BoostExampleData> Ptr;
Ptr m_ptr;
Ptr m_ptr1;
};
}
void Test()
{
BoostExample obj;
std::stringstream sstr;
//save
boost::archive::xml_oarchive oa(sstr);
oa << BOOST_SERIALIZATION_NVP(obj);
//triggers a load exception
std::string str = sstr.str();
boost::replace_all(str, "<m_ptr1>", "<m_ptr1");
sstr.str(str);
//load
obj.m_ptr.reset();
obj.m_ptr1.reset();
sstr.seekg(0);
//load
try
{
boost::archive::xml_iarchive ia(sstr);
try
{
ia >> BOOST_SERIALIZATION_NVP(obj);
}
catch (boost::archive::archive_exception& /*re*/)
{
ia.delete_created_pointers();
}
}
catch (boost::archive::archive_exception& /*re*/)
{
}
}
wkr,
me
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net