|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2006-07-10 13:30:09
Joel de Guzman wrote:
> Robert Ramey wrote:
>
>> And here's another idea.
>>
>> create an archive adaptor which takes any archive and replaces
>> its loading of primitives to something that just throws them away.
>>
>> so at some point one would try
>>
>> load(Archive & ar, Y & y, const unsigned version){
>> ar >> x;
>> if(version == 1){
>> dummy_archive<Archive> da(ar);
>> da >>y;
>> }
>> ar >> z;
>> }
>>
>> I havn't written documentation on archive adaptor but
>> polymorphic_?archives are examples of such a thing.
>
> Clever! But again, what if Y is already obsolete at version 2?
LOL - once an object of class Y is stored in an archive and
kept around - by definition - it can't be obsolete. Obsolete
suggests it will never be used - archiving suggest it will be.
One might work around this with something like:
void save(Archive & ar, const A &a, const unsigned version){
assert(1 == version);
ar << x;
ar << sizeof(y);
ar << y;
ar << z;
}
void load(Archive & ar, const A &a, const unsigned version){
std::size_t s;
ar >> x;
ar << s;
if(1 == version){
// skip over stream s bytes
}
ar << z;
}
Of course the current archive concept doesn't include the stream
and archives aren't guarenteed to have them. So the skip operation
would have to be added to the archive itself either by making an
archive adaptor that could be applied to any archive with a stream.
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