Boost logo

Boost Users :

Subject: [Boost-users] [serialization] Object reference tracking on instances bug?
From: Robert P (robert.pel.83_at_[hidden])
Date: 2017-02-03 16:27:11


In my serialize function I am exporting a class which is a template wrapper
around std:vector.

template <typename E>
class MyArray
{
public:
    vector<E> array;
    ...

    template <typename Archive>
    void MyArray::serialize(Archive & ar, const unsigned int version)
    {
        ar & BOOST_SERIALIZATION_NVP(array);
    }

}

When I add unique class instance variables to this array and then serialize
it to XML...
...
MyArray<Color> colorsArray;

Color a;
a.name = "one";
colorsArray.add(a);

Color b;
b.name = "two";
colorsArray.add(b);
...

template <typename Archive>
void MyColorsObject::serialize(Archive & ar, const unsigned int version)
{
    ar & BOOST_SERIALIZATION_NVP(colorsArray);
}

Sometimes the XML comes out using object_id_reference instead of the unique
values, and this then gets improperly unserialized with incorrect values,
i.e. both colors will have "one" as the name.

I was able to disable object tracking and it works now, but I don't think
it should be doing object reference tracking on instance variables. Is it
because of the template wrapper around vector?



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