serialization library - reloading objects
Hello, All! Are there any way to load existing objects by base class pointer without creating new? Examination of input archives source code does not give me any idea how I can achieve it. I think I need some mechanism for runtime switching archive object tracking behaviour in that way so all objects will interpreted as already created (or per-object tracking registration without actual object loading to pre-register pointer to object as already created before object loading). With best regards, Sergey.
Hmmm - I've considered that in the past in order to implement a "memento
archive" that could be used for do/undo functionality. This wouldn't be too
hard as it would be an derivation from any existing archive which
specializes the archive save/load member templates for pointers. In
considering this, a couple of quesions come to mind like:
a) for collections, what if members are added/deleted between the save and
load.
b) This would basically replace the deep class assignment capability which
is often already built-in. Its not clear that using the serialization is any
better.
Robert Ramey
"Sergey Skorniakov"
Hello, All!
Are there any way to load existing objects by base class pointer without creating new? Examination of input archives source code does not give me any idea how I can achieve it. I think I need some mechanism for runtime switching archive object tracking behaviour in that way so all objects will interpreted as already created (or per-object tracking registration without actual object loading to pre-register pointer to object as already created before object loading).
With best regards, Sergey.
Hello, Robert!
You wrote on Fri, 3 Dec 2004 08:25:02 -0800:
RR> Hmmm - I've considered that in the past in order to implement a
RR> "memento archive" that could be used for do/undo functionality. This
RR> wouldn't be too hard as it would be an derivation from any existing
RR> archive which specializes the archive save/load member templates for
RR> pointers.
Thanks, I'll try to do it.
RR> In considering this, a couple of quesions come to mind like:
RR> a) for collections, what if members are added/deleted between the save
RR> and load.
In my case, it is impossible. I'm writing custom RPC and has difficulties
with returning function arguments by reference or pointer.
RR> b) This would basically replace the deep class assignment capability
RR> which is often already built-in. Its not clear that using the
RR> serialization is any better.
Yes, I need exactly such a replacement.
RR> Robert Ramey
RR> "Sergey Skorniakov"
Hello, Robert! You wrote on Fri, 3 Dec 2004 08:25:02 -0800: RR> Hmmm - I've considered that in the past in order to implement a RR> "memento archive" that could be used for do/undo functionality. This RR> wouldn't be too hard as it would be an derivation from any existing RR> archive which specializes the archive save/load member templates for RR> pointers. Its look like that I need to reimplement the whole basic_iarchive_impl. Am I right? With best regards, Sergey.
Note: the following is just speculation on my part - take with a grain of
salt.
"Sergey Skorniakov"
Hello, Robert! You wrote on Fri, 3 Dec 2004 08:25:02 -0800:
RR> Hmmm - I've considered that in the past in order to implement a RR> "memento archive" that could be used for do/undo functionality. This RR> wouldn't be too hard as it would be an derivation from any existing RR> archive which specializes the archive save/load member templates for RR> pointers.
Its look like that I need to reimplement the whole basic_iarchive_impl. Am I right?
I don't think that would be necessary nor would it be desirable.
The way I would go about is to make an "memento_iarchive" class as an
"archive adaptor". This template would be used to alter the function of any
other existing archive to convert it into a "memento" archive. See attached
sample. This sample adapts any existing archive class to a "memento"
equivalent by overriding the serialization of pointers to simple copy of the
de-referenced data.
The attached sample does compile on two compilers.
Good Luck
Robert Ramey
begin 666 memento_iarchive.hpp
M+R\@;65M96YT;R!A
Hello, Robert! You wrote on Mon, 6 Dec 2004 10:25:07 -0800: ??>> ??>> Its look like that I need to reimplement the whole ??>> basic_iarchive_impl. Am RR> I ??>> right? ??>> RR> I don't think that would be necessary nor would it be desirable. RR> The way I would go about is to make an "memento_iarchive" class as an RR> "archive adaptor". This template would be used to alter the function RR> of any other existing archive to convert it into a "memento" archive. RR> See attached sample. This sample adapts any existing archive class to RR> a "memento" equivalent by overriding the serialization of pointers to RR> simple copy of the de-referenced data. Thanks, Robert. This great! No one can say why I tried to override load_pointer member. If I already know real object types, I can just create special output archive and load objects with incompatible input archives, without worring about tracking and object creation stuff. This works fine. With best regards, Sergey.
Hello, Sergey! You wrote to Robert Ramey on Tue, 7 Dec 2004 12:42:01 +0300: SS> Thanks, Robert. This great! No one can say why I tried to override SS> load_pointer member. If I already know real object types, I can just SS> create special output archive and load objects with incompatible input SS> archives, without worring about tracking and object creation stuff. SS> This works fine. Unfortunately, I was to hasty with conlusions - this solution doesn't work when objects serialized by base class pointers. With best regards, Sergey.
As usual, things turn out to be more complex than first meets the eye.
I believe this could be addressed by making our implementation of
memento_iarchive adaptor
a little more elaborate. Perhaps this could be done by overloading the
following from iserializer.hpp
"Sergey Skorniakov"
Hello, Sergey! You wrote to Robert Ramey on Tue, 7 Dec 2004 12:42:01 +0300:
SS> Thanks, Robert. This great! No one can say why I tried to override SS> load_pointer member. If I already know real object types, I can just SS> create special output archive and load objects with incompatible input SS> archives, without worring about tracking and object creation stuff. SS> This works fine.
Unfortunately, I was to hasty with conlusions - this solution doesn't work when objects serialized by base class pointers.
With best regards, Sergey.
Ahhh - everything is more involved that it first appears.
I believe the same basic approach could be made two work. Perhaps
overloading
pointer_iserializer::load_object_ptr from iserializer.hpp could be made to
work.
I did play around a little with this but couldn't make it work without
investing too much effort. Sorry I don't have a complete solution. Let me
know when you find one.
Robert Ramey
"Sergey Skorniakov"
Hello, Sergey! You wrote to Robert Ramey on Tue, 7 Dec 2004 12:42:01 +0300:
SS> Thanks, Robert. This great! No one can say why I tried to override SS> load_pointer member. If I already know real object types, I can just SS> create special output archive and load objects with incompatible input SS> archives, without worring about tracking and object creation stuff. SS> This works fine.
Unfortunately, I was to hasty with conlusions - this solution doesn't work when objects serialized by base class pointers.
With best regards, Sergey.
participants (2)
-
Robert Ramey
-
Sergey Skorniakov