er wrote:
The issue of serializing a multi-array came up here:
http://lists.boost.org/boost-users/2007/06/28639.php
I was wondering if anyone had followed up on this and would be willing
to share his/her code.
Here's the code based on the above suggestions. I would have thought
that overloading serialize (see below) would permit oa << array and ia
array, but not (compile error : array has no member serialize).
Therefore, if I want to embed multi_array in another data-structure,
what is the next step?
Thanks in advance.
template
void load(
Archive & ar,
boost::multi_array & t,
const unsigned int file_version
)
{
typedef boost::multi_array multi_array_;
typedef typename multi_array_::size_type size_;
size_ n0;
ar >> BOOST_SERIALIZATION_NVP(n0);
size_ n1;
ar >> BOOST_SERIALIZATION_NVP(n1);
t.resize(boost::extents[n0][n1]);
ar >> make_array(t.data(), t.num_elements());
}
template
void save(
Archive & ar,
const boost::multi_array & t,
const unsigned int file_version
)
{
typedef boost::multi_array multi_array_;
typedef typename multi_array_::size_type size_;
size_ n0 = (t.shape()[0]);
ar << BOOST_SERIALIZATION_NVP(n0);
size_ n1 = (t.shape()[1]);
ar << BOOST_SERIALIZATION_NVP(n1);
ar << boost::serialization::make_array(t.data(),
t.num_elements());
}
template
void serialize(
Archive & ar,
const boost::multi_array& t,
const unsigned int file_version
)
{
split_free(ar, t, file_version);
}