trallallero
07-04-2009, 13:41
Ho un problema con un'eccezione "unregistered class":
Nel mio "main" serializzo un LLElementHandler (m_EleHandler):
(registro quì le classi ma ho provato a registrarle ovunque ...)
std::ofstream ofs("archive.txt");
boost::archive::text_oarchive oa(ofs);
ar.register_type(static_cast<LLBaseEntity *>(NULL));
ar.register_type(static_cast<LLElementHandler*>(NULL));
ar.register_type(static_cast<LLBaseHandler *>(NULL));
oa << m_EleHandler;
Nella classe LLElementHandler ho questo codice per serializzare:
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */)
{
puts("LLElementHandler serialize");
ar & boost::serialization::base_object<LLBaseHandler>(*this);
}
In pratica non faccio altro che andare nella classe base dell LLElementHandler che è LLBaseHandler
dove c'è questo codice:
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */)
{
puts("LLBaseHandler serialize");
ar & m_OwnEntities;
}
m_OwnEntities è un vector di puntatori a classi LLBaseEntity che devono serializzare solo il membro int "m_State".
Infatti:
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */)
{
puts("LLBaseEntity serialize");
ar & m_State;
}
L'output:
LLElementHandler serialize
LLBaseHandler serialize
terminate called after throwing an instance of 'boost::archive::archive_exception'
what(): unregistered class
In pratica si blocca al LLBaseEntity.
Questa è l'istruzione che crea problemi: ar & m_OwnEntities;
... perchè ?
Nel mio "main" serializzo un LLElementHandler (m_EleHandler):
(registro quì le classi ma ho provato a registrarle ovunque ...)
std::ofstream ofs("archive.txt");
boost::archive::text_oarchive oa(ofs);
ar.register_type(static_cast<LLBaseEntity *>(NULL));
ar.register_type(static_cast<LLElementHandler*>(NULL));
ar.register_type(static_cast<LLBaseHandler *>(NULL));
oa << m_EleHandler;
Nella classe LLElementHandler ho questo codice per serializzare:
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */)
{
puts("LLElementHandler serialize");
ar & boost::serialization::base_object<LLBaseHandler>(*this);
}
In pratica non faccio altro che andare nella classe base dell LLElementHandler che è LLBaseHandler
dove c'è questo codice:
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */)
{
puts("LLBaseHandler serialize");
ar & m_OwnEntities;
}
m_OwnEntities è un vector di puntatori a classi LLBaseEntity che devono serializzare solo il membro int "m_State".
Infatti:
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */)
{
puts("LLBaseEntity serialize");
ar & m_State;
}
L'output:
LLElementHandler serialize
LLBaseHandler serialize
terminate called after throwing an instance of 'boost::archive::archive_exception'
what(): unregistered class
In pratica si blocca al LLBaseEntity.
Questa è l'istruzione che crea problemi: ar & m_OwnEntities;
... perchè ?