|
Boost Users : |
From: Olivier Destrebecq (olivierd_at_[hidden])
Date: 2006-04-25 13:31:30
I have a base class and some derived class. Each class declare a
serialize method.
each derived class begin its serialization method by:
inArchive & BOOST_SERIALIZATION_BASE_OBJECT_NVP
(FetchableMetadataObject);
to declare the inheritance relationship
then they serialize their own members:
inArchive & BOOST_SERIALIZATION_NVP(xxxx);
I want the base class to declare a serialize as XML method that will
return a string containing the serialized XML representation
std::string baseClass::SerializeAsXML() const
{
return baseClass::saveToXML(this);
}
saveToXML is a static method on the baseClass
std::string baseClass::saveToXML(baseClass const* inObject)
{
std::ostringstream returnValue;
boost::archive::xml_oarchive archive(returnValue);
archive << boost::serialization::make_nvp("root", inObject);
return returnValue.str();
}
The serialization appear to work as when the object are printed for
the unit test, i pass the xml serialized data and it contains the
data that i expect it to contain.
The problems start when i want to reload the data into objects
I declared a constructor on the base class and on the derived class
that accept the XML string and then rebuild the object using that
string (is that a correct design decision?)
baseClass::MetadataObject(std::string const &serializedObject)
{
baseClass::LoadFromXML(serializedObject, this);
}
derivedClass::MetadataObject(std::string const &serializedObject)
{
baseClass::LoadFromXML(serializedObject, this);
}
LoadFromXML is a static method on the base class
void baseClass::LoadFromXML(std::string const &inXMLString, baseClass
*inObject)
{
std::istringstream inputStream (inXMLString);
// open the archive
assert(inputStream.good());
boost::archive::xml_iarchive inputArchive(inputStream);
// restore the schedule from the archive
inputArchive >> boost::serialization::make_nvp("root", inObject);
}
The serialize method is not even called when de-serializing the
object. So i assume i missed something:-)
Any help appreciated,
Olivier Destrebecq
olivierd_at_[hidden]
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