Boost logo

Boost Users :

Subject: Re: [Boost-users] Problems using boost serializing and custom constructors
From: Allan Nielsen (a_at_[hidden])
Date: 2012-03-12 11:49:55


Hi again,

I have now tried to get your suggested solution to work, but did not succeed.

> template<typename Archive>
> void serialize(Archive &ar, const unsigned int) {
>  auto * data_ptr = &data;
>  ar & data_ptr; // load and save through pointer
>
>  if(Archive::is_loading::value) {
>    data = std::move(*data_ptr); // no-throw
>    ar.reset_object_address(&data, data_ptr);
>    delete data_ptr; // not sure here
>  }

This produced a compiler error, so I slitted it into separated load
and save methods which looks like this:

    BOOST_SERIALIZATION_SPLIT_MEMBER();

    template<class Archive>
    void save(Archive & ar, const unsigned int version) const
    {
        const std::vector<unsigned> * data_ptr = &data;
        ar & data_ptr; // load and save through pointer
    }

    template<class Archive>
    void load(Archive & ar, const unsigned int version)
    {
        const vector<int> * data_ptr;
        ar & data_ptr; // load and save through pointer
        data = std::move(*data_ptr); // no-throw
        ar.reset_object_address(&data, data_ptr);
        delete data_ptr;
    }

But unfortunately, when I loads all the remaining pointers to data,
the pointers has not been reset. This make me think the
"ar.reset_object_address(&data, data_ptr);" method does not work
properly ( I have ensured that it is executed before the loads ).

Also, if I add:

BOOST_STATIC_ASSERT( (boost::serialization::tracking_level< const
std::vector<unsigned> * >::value != boost::serialization::track_never)
);

I get an compiler error saying static assert failed. Why is that?
shouldn't everything serialized through a pointer be tracked? What can
I do to fix this?

Best regards
Allan W. Nielsen


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