I have a class that inherit from another, both implement serialization
the derived class has this code:
#ifndef _GENREMETADATA_H_
#define _GENREMETADATA_H_
#include "fetchableMetadataObject.h"
#include
#include
class GenreMetadata : public FetchableMetadataObject
{
public:
.....
private:
std::string m_abbreviation;
std::string m_displayName;
std::string m_name;
std::auto_ptr m_childGenresMetadata;
std::auto_ptr m_parentGenresMetadata;
std::auto_ptrstd::string m_description;
std::auto_ptr<GenreMetadata> m_primaryParentGenreMetadata;
template<class Archive> void serialize(Archive & inArchive,
const unsigned int version)
{
//serialize the base class
//
inArchive & BOOST_SERIALIZATION_BASE_OBJECT_NVP
(FetchableMetadataObject);
//then our own properties
//
inArchive & BOOST_SERIALIZATION_NVP(m_abbreviation);
inArchive & BOOST_SERIALIZATION_NVP(m_displayName);
inArchive & BOOST_SERIALIZATION_NVP(m_name);
inArchive & BOOST_SERIALIZATION_NVP(m_childGenresMetadata);
inArchive & BOOST_SERIALIZATION_NVP(m_parentGenresMetadata);
inArchive & BOOST_SERIALIZATION_NVP(m_description);
inArchive & BOOST_SERIALIZATION_NVP
(m_primaryParentGenreMetadata);
}
};
#endif //_GENREMETADATA_H_
i included a version of auto_ptr serialization:
#include <list>
#include <memory>
#include <fstream>
#include // std::autoptr inteface wrong in dinkumware
#include
#include
#include
#include
#include
namespace boost {
namespace serialization {
/////////////////////////////////////////////////////////////
// implement serialization for auto_ptr<T>
// note: this must be added to the boost namespace in order to
// be called by the library
template
inline void save(
Archive & ar,
const std::auto_ptr<T> &t,
const unsigned int file_version
){
// only the raw pointer has to be saved
// the ref count is rebuilt automatically on load
T *objectPtr = t.get();
ar << BOOST_SERIALIZATION_NVP(objectPtr);
}
template
inline void load(
Archive & ar,
std::auto_ptr<T> &t,
const unsigned int file_version
){
T *objectPtr;
ar >> BOOST_SERIALIZATION_NVP(objectPtr);
// note that the reset automagically maintains the
reference count
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
t.release();
t = std::auto_ptr<T>(objectPtr);
#else
t.reset(objectPtr);
#endif
}
// split non-intrusive serialization function member into
separate
// non intrusive save/load member functions
template
inline void serialize(
Archive & ar,
std::auto_ptr<T> &t,
const unsigned int file_version
){
split_free(ar, t, file_version);
}
} // namespace serialization
} // namespace boost
When i compile this code i get the following error:
../../common_rn/import/boost/debug/include/boost-1_33_1/boost/
serialization/access.hpp:109: error: 'struct std::basic_string' has no member named
'serialize'
I looked at the serialization code for string and it treats it as a
primitive type. Could my problem come from there. Notice how it
complains about the string contained in the auto_ptr, but not the
other strings. Also it does not complain about the array contain in
the auto_ptr.
Also if i split the serialization of my object an manually try to
archive the string object, it complain about the serialization if i
pass in a pointer to the string, but not if i pass the object itself
any help appreciated
Best,
Olivier Destrebecq
olivierd@real.com