Dear all,
I'm having problems to serialize a std::vector of a small class I use
in my code. The class contains 3 members: a std::string, a size_t, and
an another class passed as a template parameter (see the code below.)
The class passed as a template is basically a std::map >(see this post
http://lists.boost.org/boost-users/2008/05/36282.php). I'm using the
serialization library with the last class elsewhere in my code and
works with no problems, so I guess the error must be in the code
below. My program compiles and finishes OK, but the results I'm
getting are slightly different from what I should get: it seems that
somewhere in the serialization process the numbers stored in the third
class get corrupted.
I'm using boost 1.35, I need the binary file (I'm taking advantage of
the serialization stuff for arrays contiguous in memory), and
everything happens in the same machine in a single run of my code (so
it is not a problem of different binary archives for different
machines.)
Thanks in advance,
Ivan
//--------------------------------------------------------------------------------------------
#include <iostream>
#include <sstream> // for std::istringstream
#include
#include
#include
#include
template<class DataType>
class ThingToStore{
public:
typedef DataType data_type;
ThingToStore() :
site_(), name_(), data_() {}
ThingToStore(const data_type& data,
const std::string& name, int site) :
site_(site), name_(name), data_(data) {}
const std::string & name() const { return name_; }
size_t site() const { return site_; }
const data_type& map() const { return data_; }
private:
friend class boost::serialization::access;
template<class Archive>
inline void serialize(Archive& ar,
const unsigned int file_version)
{
ar & BOOST_SERIALIZATION_NVP(site_);
ar & BOOST_SERIALIZATION_NVP(name_);
ar & data_;
}
size_t site_;
std::string name_;
data_type data_;
};
template<class DataType>
class StoredThingList {
private:
typedef std::vector this_type;
public:
StoredThingList() {}
template<class Index>
void save(const Index& i,
const std::string& name="blockOps_") const
{
// make a string for the name file
std::ostringstream oss;
oss<