[code] multi_array serialization
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<typename Archive, typename T, std::size_t N> inline void save(Archive & ar, const boost::multi_array<T, N> & 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<typename Archive, typename T, std::size_t N> inline void load(Archive & ar, boost::multi_array<T, N> & t, const unsigned int file_version) { typedef typename boost::multi_array<T, N>::size_type size_type; boost::array<size_type, N> 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<typename Archive, typename T, std::size_t N> inline void serialize(Archive & ar, boost::multi_array<T, N>& t, const unsigned int file_version) { split_free(ar, t, file_version); } -- Andriy Gapon
participants (1)
-
Andriy Gapon