Boost logo

Boost Users :

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


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.


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