[serialization] working around the pointer_conflict exception?

I have implemented the serialise library of BOOST to my own classes. Using a single entry point it recursively goes through every member and saves the values. Of course initial implementation yielded the pointer_conflict expression as for example while going through objects A,B,C object A may have a pointer to B, and only afterwards is B actually saved. I tried - and thought - to fix this by using a two-phased approach. First I save all the actual objects from the entry point, secondly only the pointers. eg save_objects = true; ar & my_object; save_objects = false; ar & my_objects; and inside every class: class A { public: int a; int *b; serialise() { if (save_objects) { ar & a; } else { ar & b; } } }; This seemed sound but only during debugging did I realise that the second run of the serialiser doesn't do anything since my_object is already saved. So this won't work. Does anyone have better ideas on solving this problem, or has encountered and already solved this issue? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

T. Farago wrote:
I have implemented the serialise library of BOOST to my own classes. Using a single entry point it recursively goes through every member and saves the values. Of course initial implementation yielded the pointer_conflict expression as for example while going through objects A,B,C object A may have a pointer to B, and only afterwards is B actually saved.
I tried - and thought - to fix this by using a two-phased approach. First I save all the actual objects from the entry point, secondly only the pointers. eg
save_objects = true; ar & my_object; save_objects = false; ar & my_objects;
and inside every class: class A { public: int a; int *b; serialise() { if (save_objects) { ar & a; } else { ar & b; } } };
This seemed sound but only during debugging did I realise that the second run of the serialiser doesn't do anything since my_object is already saved. So this won't work.
Does anyone have better ideas on solving this problem, or has encountered and already solved this issue?

T. Farago wrote:
I have implemented the serialise library of BOOST to my own classes. Using a single entry point it recursively goes through every member and saves the values. Of course initial implementation yielded the pointer_conflict expression as for example while going through objects A,B,C object A may have a pointer to B, and only afterwards is B actually saved.
The following should work without problem class A { public: int a; int *b; template<class Archive> void serialise(Archive & ar, const unsigned int version) { ar & a; ar & b; } }; If you still have a problem you could save all the objects first ar & my_obect; You don't have to do anything else. The serialization library includes the tracking of repeated objects. Robert Ramey
participants (2)
-
Robert Ramey
-
T. Farago