|
Boost Users : |
From: Sean Cavanaugh (worksonmymachine_at_[hidden])
Date: 2007-07-10 05:11:52
I got the polymorphic behavior on serializing classes descending from my
root Asset class worked out, as well as the (tiny) changes required to get
the boost serialization library to load the objects my way :)
Basically it amounted to having to adding a set of symmetrical methods in
common_oarchive and common_archive, which the user-derived archive override.
common_oarchive:
template<class T>
bool save_object_ptr_custom(T& t)
{
return false;
}
common_iarchive:
template<class T>
bool load_object_ptr_custom(T& t)
{
return false;
}
pointer_oserializer::save_object_ptr -- wrap the last few lines with the
if implementing the callback:
if (!ar_impl.save_object_ptr_custom(t))
{
boost::serialization::save_construct_data_adl<Archive, T>(
ar_impl,
t,
file_version
);
ar_impl << boost::serialization::make_nvp(NULL, * t);
}
pointer_iserializer::load_object_ptr -- add this early out right before
the heap allocation and construction
T* t = NULL;
if (ar_impl.load_object_ptr_custom(t))
{
x = t;
return;
}
Attached are my two archive classes, which automagically search for all
Asset* derived classes and serialize handles to objects after the first
object of Asset* type is serialized.
It also seems a scheme similar to this should be able to provide custom type
specific memory allocators on loading.
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