|
Boost Users : |
Subject: Re: [Boost-users] [Serialization]Can not export polymorphic types
From: Daniel Roberts (impulsionaudio_at_[hidden])
Date: 2008-12-30 13:23:53
That works. Some things I notice:
1) The xml file created has an attribute in the object tag called
"class_name", containing the name of the derived type. This attribute does
not exist in an xml file created using derived type pointers. I guess this
is the critical piece of information needed to reconstruct a derived type
using a base class pointer.
2) It also works if you create a derived class pointer/object, static_cast
the derived type pointer to a base class pointer and pass the base class
pointer to the serialization.
3) someInXMLArchive >> boost::serialization::make_nvp("", someTypePtr);
works, which is surprising since I am passing an empty string for a tag. It
appears serializing in ignores tag names and just processes data until the
class is constructed or a stream error occurs.
4) Calling close on the output file stream (e.g. std::ofstream::close)
causes the closing boost_serialization tag, </boost_serialization> to NOT be
written to the file. Is this an issue that needs to be resolved or am I
doing something else wrong?
Thanks a bunch for all the help. Hopefully I'll be running on my own now.
Please feel free to comment on my observations above, however.
Regards,
Daniel Roberts
What happens if you try the following:
TestBase * pT1 = new TestType1;
TestBase* pT2 = new TestType2;
testOutXML << boost::serialization::make_nvp("pT1", pT1);
testOutXML << boost::serialization::make_nvp("pT2", pT2);
testTypeOFS.close();
delete pT1;
delete pT2;
...
testInXML >> boost::serialization::make_nvp("pT1", pTB);
testInXML >> boost::serialization::make_nvp("pT2", pTB);
Robert Ramey
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