Boost logo

Boost Users :

From: RIVASSEAU Jean Noel (JN.RIVASSEAU_at_[hidden])
Date: 2006-02-28 11:10:39


>From the code snippet, I can say that you are not serializing via a pointer to base class, since you serialize tmp which is an object, not a pointer (by the way, tmp is just an object of the base class... you would lose the information of *event if event pointed to a derived class).

Try changing:

    SENSOR_Event tmp = *event;
    oa << tmp;

to just:

oa << event;

And also, include the BOOST_CLASS_EXPORT macro for the base class.
Or, you can try doing (to see what it does):

    const SENSOR_Event tmp = *event;
    oa << tmp;

but there, you are serializing a pointer, not an object.

Jean-Noël

-----Message d'origine-----
De : boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] De la part de Tobias Combe
Envoyé : mardi 28 février 2006 16:51
À : boost-users_at_[hidden]
Objet : Re: [Boost-users] problem with serialization of pure virtual

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 mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


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