|
Boost : |
From: Neal Becker (ndbecker2_at_[hidden])
Date: 2005-08-26 09:51:36
Here are a couple of useful additions for serialization. std::complex is
pretty trivial, and a no-brainer IMHO.
I implemented support for ublas::vector unbounded_array only. Would be nice
to do more, but that's all I need at the moment.
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/split_free.hpp>
template<typename Archive, typename T>
inline void save (Archive &ar, const std::complex<T>& z, const unsigned int)
{
ar << real (z);
ar << imag (z);
}
template<typename Archive, typename T>
inline void load (Archive &ar, std::complex<T>& z, const unsigned int) {
T i, r;
ar >> r;
ar >> i;
z = std::complex<T> (r, i);
}
namespace boost { namespace serialization {
template<class Archive, class T>
inline void serialize (Archive &ar, std::complex<T>& z, const unsigned int
file_version) {
boost::serialization::split_free (ar, z, file_version);
}
}
}
template<class Archive, class U>
inline void save (Archive &ar, const vector<U> &v, const unsigned int) {
unsigned int count = v.size();
ar << count;
typename vector<U>::const_iterator it = v.begin();
while (count-- > 0) {
ar << *it++;
}
}
template<class Archive, class U>
inline void load (Archive &ar, vector<U> &v, const unsigned int) {
unsigned int count;
ar >> count;
v.resize (count);
typename vector<U>::iterator it = v.begin();
while (count-- > 0) {
ar >> *it++;
}
}
namespace boost { namespace serialization {
template<class Archive, class U>
inline void serialize (Archive &ar, vector<U>& v, const unsigned int
file_version) {
boost::serialization::split_free (ar, v, file_version);
}
}
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk