Even when partial specialization for serialzation exists for std:vector<T>
this does not imply it will work for subclasses, so you have to add a serialization method for ring
:
template<class Archive>
inline void serialize(Archive & ar, ring &t, const unsigned int file_version)
{
// Impl
}
So what's in the implementation? As geometry
is not built to be serialized, you cannot access types that would be useful for the serialization (for example, to select the correct default implementation for the container ring
inherits), so you can force this somehow. For example, this seems to work:
template<class Archive>
inline void serialize(Archive & ar, ring &t, const unsigned int file_version)
{
std::cout << "Ring: Serializing a ring" << std::endl;
serialize(ar, static_cast< std::vector<point>& >(t), file_version);
}
You can also try to write some base class serialization call:
template<class Archive>
inline void serialize(Archive & ar, ring &t, const unsigned int file_version)
{
std::cout << "Ring: Serializing a ring" << std::endl;
ar & boost::serialization::make_nvp( "Base",
boost::serialization::base_object<std::vector<point> >(t));
}
but again, the problem is that you should be able to access that inherited class from within ring
. In fact, it is in the definition of ring
, as base_type
, but it is private to the class. If it was public, you could write the not so bad code using ring::base_type
as a parameter for the serialization (instead of the bare std::vector<point>
above).
Maybe knowing the inners of the serialization library you can "tie" the serialization machinery so that two calls are not neccessary, specializing some partial specialization for the ring
class itself, but I doubt this would be portable.