Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] serializing a pointer without causingobject tracking
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-04-01 16:48:10


Stefan Strasser wrote:
> Am 30.03.2013 19:03, schrieb Robert Ramey:
>>> is there a solution to this? is there a serialization wrapper that
>>> says "don't track this type just because of this pointer"?
>>
>> so you want "don't track this particular save - but leave others as
>> normal" Try something like
>>
>> class A ....
>>
>> class UntrackedA : public A {
>> ...
>> };
>>
>> BOOST_SERIALIZATION_TRACK(UntrackedA, track_never);
>
> interesting idea. does this eventually track the object if the base
> class of UntrackedA is track_selectively and saved through a pointer
> anywhere else?
>
> for example, an object graph that stores a pointer to its own root
> (through intermediaries in practice):
>
> class A{ //tracking level: selectively
> void serialize(...){ ar & a; }
> A *a; //==this
> };
>
> class UntrackedA : A{ //tracking level: never
> void serialize(...){ ar & base_object<A>(*this); }
> }
>
> void save(UntrackedA *a){ ar << a; }
>
> is "a" serialized twice, or tracked because of track_selectively and
> the pointer serialization in A::serialize?

lol - I didn't think about this when I responded though I'm sure I did it
when I made the code. I'm going to speculate since it's easier than
doing any work.

class UntrackedA : public A {
    // instead of this:
    void serialize(Archive & ar, unsigned int file_version){
        boost::serialization:base_object<A>(*this);
    }
    // consider this
    void serialize(Archive & ar, unsigned int file_version){
        ar & m_a; // where m_a is a member of a
        ar & m_b; // other member of a etc ...
    }
   ...
};

Robert Ramey


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