I needed to serialize some multi_array objects in my project and came up with the
following code. How does it look? It's probably missing serialization of the
"quirks" like memory layout, dimension bases and similar.
template
inline void save(Archive & ar, const boost::multi_array & t, const unsigned
int file_version)
{
ar << boost::serialization::make_nvp("dimensions",
boost::serialization::make_array(t.shape(), N));
ar << boost::serialization::make_nvp("data",
boost::serialization::make_array(t.data(), t.num_elements()));
}
template
inline void load(Archive & ar, boost::multi_array & t, const unsigned int
file_version)
{
typedef typename boost::multi_array::size_type size_type;
boost::array dimensions;
ar >> boost::serialization::make_nvp("dimensions",
boost::serialization::make_array(dimensions.c_array(), N));
t.resize(dimensions);
ar >> boost::serialization::make_nvp("data",
boost::serialization::make_array(t.data(), t.num_elements()));
}
template
inline void serialize(Archive & ar, boost::multi_array& t, const unsigned
int file_version)
{
split_free(ar, t, file_version);
}
--
Andriy Gapon