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.
*** If an object is written through a derived
type pointer, there is really no need for the "class_name" - it's
redundant. Note that this also means that the "BOOST_CLASS_EXPORT" isn't
necessary either. In general, archives hold that information - and ONLY
that information required to (re)load the object.
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.
*** correct, casting overrides the C++ typing
system - that's the purpose of the cast. In general, you can serialized
the derived type or the base type (which will retrieve the derived type
information. What you CANNOT do is to save as one type and load as
different type.
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.
***
The only function of the tag is to permit a name
for the html tag. It has no purpose as far as serialization itself is
concerned. As a useful aid in debugging, the starting/ending tags are
matched be sure someone has munched up the xml file between the time the
archive has been saved and loaded
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?
***
The archive is "woundup" when it's destructor is
called. If the underlying stream is closed before that happens, you
won't get the last tag. What I recommend is to do something
like:
{
std::fostream
os("filename")
{
boost::archive::xml_archive xa(os);
xa <<
....
// xa
destructor finishs off the archive
}
// os.close called by os
destructor
}
which guarentees that the archive destructor is
called before the stream is closed.
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.
***
You're welcome. If you have a guilty
conscience about consuming so much time, feel free to submit a "trouble
shooting tips and techniques" to the serialzation documentation. Your
submission can take the form of a TRAK item.