problem with serialization of pure virtual

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with serialization of pure virtual

Tobias Combe
Hello

I read the documention and some prior postings to related topics.
But none of the proposed solutions seems to work for me.

My problem:

I have an abstarct base class(with pure vitual function) and several
derived from that. All are written in the same source/header -file. I
want to serialize an object via a pointer to the base-class.
When i use "ar.register<derived>();" in the template of the base-class
to register the derived classes, i get a syntax error.
When i export them with "BOOST_CLASS_EXPORT(derived);" or
BOOST_CLASS_EXPORT_GUID(derived,"derived") it doesn't work (i think
because they are all in the same file).
I'm also using "BOOST_IS_ABSTRACT(base);"
When i comment "oa << object;" ervything compiles fine.
Uncommented i get a:
boost/archive/detail/oserializer.hpp:567: error: incomplete type `
 boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
error...

So is there a solution (without seperating the derived classes into
different files) for this problem?
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

RIVASSEAU Jean Noel
You should send a code snippet.

What are the syntax error you get, and the error you get when doing a "BOOST_CLASS_EXPORT(derived);" ?

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).

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).

Jean-Noël

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Tobias Combe
Envoyé : mardi 28 février 2006 13:18
À : [hidden email]
Objet : [Boost-users] problem with serialization of pure virtual

Hello

I read the documention and some prior postings to related topics.
But none of the proposed solutions seems to work for me.

My problem:

I have an abstarct base class(with pure vitual function) and several
derived from that. All are written in the same source/header -file. I
want to serialize an object via a pointer to the base-class.
When i use "ar.register<derived>();" in the template of the base-class
to register the derived classes, i get a syntax error.
When i export them with "BOOST_CLASS_EXPORT(derived);" or
BOOST_CLASS_EXPORT_GUID(derived,"derived") it doesn't work (i think
because they are all in the same file).
I'm also using "BOOST_IS_ABSTRACT(base);"
When i comment "oa << object;" ervything compiles fine.
Uncommented i get a:
boost/archive/detail/oserializer.hpp:567: error: incomplete type `
 boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
error...

So is there a solution (without seperating the derived classes into
different files) for this problem?
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

Tobias Combe
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
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

Nat Goodspeed
In reply to this post by Tobias Combe
> -----Original Message-----
> From: [hidden email] [mailto:boost-users-
> [hidden email]] On Behalf Of Tobias Combe
> Sent: Tuesday, February 28, 2006 7:18 AM
> To: [hidden email]
> Subject: [Boost-users] problem with serialization of pure virtual
>
> When i use "ar.register<derived>();" in the template of the base-class
> to register the derived classes, i get a syntax error.

[Nat] What compiler are you using?

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

RIVASSEAU Jean Noel
In reply to this post by Tobias Combe
>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 : [hidden email] [mailto:[hidden email]] De la part de Tobias Combe
Envoyé : mardi 28 février 2006 16:51
À : [hidden email]
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
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

Robert Ramey
In reply to this post by Tobias Combe
Tobias Combe wrote:

> Hello
>
> I read the documention and some prior postings to related topics.
> But none of the proposed solutions seems to work for me.
>
> My problem:
>
> I have an abstarct base class(with pure vitual function) and several
> derived from that. All are written in the same source/header -file. I
> want to serialize an object via a pointer to the base-class.
> When i use "ar.register<derived>();" in the template of the base-class
> to register the derived classes, i get a syntax error.

what syntax error do you get? conforming compilers can't compile
ar.register<derived>()
but need ar.template register<derived>() (or something like that).  To
avoid have to remember this I use the following idiot proof syntax:

ar.register(static_cast<derived *>(0))

> When i export them with "BOOST_CLASS_EXPORT(derived);" or
> BOOST_CLASS_EXPORT_GUID(derived,"derived") it doesn't work (i think
> because they are all in the same file).

In order for BOOST_CLASS_EXPORT to function - it has to follow the
the boost/archive/... declarations.

> I'm also using "BOOST_IS_ABSTRACT(base);"

and...?

> When i comment "oa << object;" ervything compiles fine.
> Uncommented i get a:
> boost/archive/detail/oserializer.hpp:567: error: incomplete type `
> boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
> error...

This is an entirely separate issue.  Check the comments at oserializer.hpp
567 and
the documentation rationale for information on this topic.

Robert Ramey



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

Robert Ramey
In reply to this post by Tobias Combe
> void Sensor::send(const SENSOR_Event *event){
> ...
> // serialize to string
>    std::stringstream s;
>    boost::archive::text_oarchive oa(s);
>    //SENSOR_Event tmp = *event;
      const SENSOR_Event tmp = *event;
>    oa << tmp;
>    std::string p = s.str();
> ...
> }
>

Note that the above change will fix the "problem" .  The following would
be much better:

void Sensor::send(const SENSOR_Event * const event){
 // serialize to string
    std::stringstream s;
    boost::archive::text_oarchive oa(s);
    oa << event;
    std::string p = s.str();
}




_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with serialization of pure virtual

Tobias Combe
In reply to this post by Nat Goodspeed
I'm using gcc 3.3.5
and now i get the following error:
with oa << event; :
boost/serialization/access.hpp: In static member function `static void
   boost::serialization::access::serialize(Archive&, T&, unsigned int) [with
   Archive = boost::archive::text_oarchive, T = DataNode]':
boost/serialization/serialization.hpp:81:   instantiated from `void
boost::serialization::serialize(Archive&, T&, unsigned int) [with
Archive = boost::archive::text_oarchive, T = DataNode]'
boost/serialization/serialization.hpp:140:   instantiated from `void
boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with
Archive = boost::archive::text_oarchive, T = DataNode]'
boost/archive/detail/oserializer.hpp:148:   instantiated from `void
boost::archive::detail::oserializer<Archive,
T>::save_object_data(boost::archive::detail::basic_oarchive&, const
void*) const [with Archive = boost::archive::text_oarchive, T = DataNode]'
boost/mpl/if.hpp:67:   instantiated from here
boost/serialization/access.hpp:109: error: `serialize' undeclared (first use
   this function)
boost/serialization/access.hpp:109: error: (Each undeclared identifier is
   reported only once for each function it appears in.)

with //oa << event; :
IDSNet/Sensor.o(.text+0x367): In function `Sensor::~Sensor
[not-in-charge]()':
Sensor.cc: undefined reference to `vtable for Sensor'
IDSNet/Sensor.o(.text+0x3c9): In function `Sensor::~Sensor [in-charge]()':
Sensor.cc: undefined reference to `vtable for Sensor'
IDSNet/Sensor.o(.text+0x42b): In function `Sensor::~Sensor [in-charge
deleting]()':
Sensor.cc: undefined reference to `vtable for Sensor'
IDSNet/Sensor.o(.gnu.linkonce.r._ZTI10PollSensor+0x8): undefined
reference to `typeinfo for Sensor'
IDSNet/Sensor.o(.gnu.linkonce.r._ZTI10PushSensor+0x8): undefined
reference to `typeinfo for Sensor'
IDSNet/Sensor.o(.gnu.linkonce.t._ZN6SensorC2Ev+0xb): In function
`Sensor::Sensor[not-in-charge]()':
Sensor.cc: undefined reference to `vtable for Sensor'
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users