|
Boost Users : |
From: Tobias Combe (tobias.combe_at_[hidden])
Date: 2006-02-28 10:51:22
Jean Noel wrote:
>You should send a code snippet.
>
Event.h:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/export.hpp>
#include <fstream>
class SENSOR_Event{
friend class Sensor;
friend class AODVRTSensor;
friend class OLSRRTSensor;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar.register<NodeEvent>();
""// for each derived class
ar & time;
ar & sourceId;
ar & sourceType;
ar & eventType;
ar & *data;
}
protected:
double time;
int sourceId;
std::string sourceType;
std::string eventType;
DataNode *data;
public:
...
};
class NodeEvent : public SENSOR_Event{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<SENSOR_Event>(*this);
}
public:
NodeEvent();
NodeEvent(double nodeId, double x, double y, double z, double
speed);
};
...//other derived Events
BOOST_CLASS_EXPORT(NodeEvent);
""// for each derived class
BOOST_IS_ABSTRACT(SENSOR_Event);
Sensor.cc:
#include "Event.h"
void Sensor::send(const SENSOR_Event *event){
...
// serialize to string
std::stringstream s;
boost::archive::text_oarchive oa(s);
SENSOR_Event tmp = *event;
oa << tmp;
std::string p = s.str();
...
}
Error:
...
boost/archive/detail/oserializer.hpp: In function `void
boost::archive::save(Archive&, T&) [with Archive =
boost::archive::text_oarchive, T = SENSOR_Event]':
boost/archive/basic_text_oarchive.hpp:78: instantiated from `void
boost::archive::basic_text_oarchive<Archive>::save_override(T&, int)
[with T = SENSOR_Event, Archive = boost::archive::text_oarchive]'
boost/archive/detail/interface_oarchive.hpp:78: instantiated from
`Archive&
boost::archive::detail::interface_oarchive<Archive>::operator<<(T&)
[with T = SENSOR_Event, Archive = boost::archive::text_oarchive]'
IDSNet/Sensor.cc:24: instantiated from here
boost/archive/detail/oserializer.hpp:567: error: incomplete type `
boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
>What are the syntax error you get, and the error you get when doing a "BOOST_CLASS_EXPORT(derived);" ?
>
"syntax error before `;' token" for that line
>I also have a problem with an abstract base class (although at link time, not compile time). Try removing the pure virtual function (just to see if it works).
>
this doesn't help
>Another hint too would be to try to serialize a constant member; sometimes I had strange ASSERTION_FAILURE related to serialization of non-constants (this is also explained in the docs)
>
I'm serializing a constant member...
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net