Boost logo

Boost Users :

From: Cyril (cyril.delmas_at_[hidden])
Date: 2007-05-04 10:27:14


Hughes, James a écrit :
>
>
>
>> -----Original Message-----
>> From: boost-users-bounces_at_[hidden]
>> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Cyril
>> Sent: 04 May 2007 15:02
>> To: boost-users_at_[hidden]
>> Subject: [Boost-users] xml serialization : compilation fails
>>
>> Hello all,
>> I have a problem while attempting to serialize a simple
>> object using xml (text works fine !).
>>
>> This is my code :
>>
>> // SomeData.h
>> #include <boost/serialization/utility.hpp> #include
>> <boost/serialization/base_object.hpp>
>>
>> class OBJECTS_API InternalData {
>> public:
>> InternalData();
>> virtual ~InternalData();
>> virtual int getInternals() const = 0;
>> private:
>> friend class boost::serialization::access;
>> template<class Archive>
>> void serialize(Archive & ar, const unsigned int version)
>> {
>> }
>> };
>>
>> class OBJECTS_API RealData : public InternalData {
>> public:
>> RealData(int internals=0);
>> int getInternals() const;
>> private:
>> int _internals;
>>
>> friend class boost::serialization::access;
>> template<class Archive>
>> void serialize(Archive & ar, const unsigned int version)
>> {
>> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(InternalData)
>> & BOOST_SERIALIZATION_NVP(_internals);
>> }
>> };
>>
>> class OBJECTS_API SomeData {
>> public:
>> SomeData(int internals=0);
>> ~SomeData();
>> InternalData* getInternals() const;
>> private:
>> InternalData* _data;
>> static InternalData* createData(int internals);
>>
>> friend class boost::serialization::access;
>> template<class Archive>
>> void serialize(Archive & ar, const unsigned int version)
>> {
>> //ar.register_type(static_cast<RealData*>(0));
>> ar & BOOST_SERIALIZATION_NVP(_data);
>> }
>> };
>> //////////////////
>> // somewhere else
>> const SomeData data(4);
>> boost::archive::xml_oarchive xoa(archive); //archive is a
>> file stream xoa << data;
>>
>> ////////////////////
>>
>> This fails to compile because :
>> // basic_xml_oarchive.hpp
>> // Anything not an attribute and not a name-value pair is an
>> // error and should be trapped here.
>> template<class T>
>> void save_override(T & t, BOOST_PFTO int) {
>> // If your program fails to compile here, its most
>> likely due to
>> // not specifying an nvp wrapper around the variable to
>> // be serialized.
>> BOOST_STATIC_ASSERT(0 == sizeof(T)); }
>>
>> I can't see why my code isn't correct according to that
>> constraint. Any help ?
>>
>> Thanks in advance.
>>
>
> I just had a very similar (if not the same) problem - I spent some time
> assigning GUID's to all the classes, and ensuring all base classes were
> correctly serialised using BOOST_SERIALIZATION_BASE_OBJECT_NVP and that
> seems to have fixed the problem. Whether it was that or something else
> that got changed during the figuring out period is anyones guess!!
>
> See BOOST_CLASS_EXPORT_GUID
>
> James
>
>
>
>
>
>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>
> This message (including any attachments) contains confidential
> and/or proprietary information intended only for the addressee.
> Any unauthorized disclosure, copying, distribution or reliance on
> the contents of this information is strictly prohibited and may
> constitute a violation of law. If you are not the intended
> recipient, please notify the sender immediately by responding to
> this e-mail, and delete the message from your system. If you
> have any questions about this e-mail please notify the sender
> immediately.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
>
It seems that it's not the solution. I tried to add
BOOST_CLASS_EXPORT_GUID call for each class in the header, but that
doesn't change the problem.
Another suggestion ?

cd


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