Noah Roberts wrote:
Sometimes during serialization an object needs to know a lot more than it does during normal operation. The way I've dealt with this in the past is to subclass the archive I want to use and add setter/getters for the data that various objects down the line are going to need to store and retrieve themselves.
Is there a better way though, something that's built into the library already maybe? I don't see anything but I thought I'd ask.
I needed this to implement serialization for shared_pointers. For this reason if you look into text_iarchive.hpp you'll see the "shared_pointer_helper". That is, I subclassed the "naked_text_iarchive". with multiple inheritance. This works well for me. Except one thing.... I've now built in a dependency into ...archive to shared_ptr. Sometime ago, I had an undocumented concept "attach runtime helper". I saw this as "polluting" the otherwise "pristine" archive code with something that didn't belong there so I factored it out and made is specific to shared_pointer_helper. I see now that the second decision was a mistake and that I should have left it generic after I factored it out. So the definitive solution is: a) replace shared_pointer_helper with a "generic runtime helper". b) adjust shared_pointer_helper interface to be an instance of the above c) document all this. Feel free to take this on. Robert Ramey