|
Boost : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2002-11-20 00:38:09
From: brangdon_at_[hidden] (Dave Harris)
>In-Reply-To: <01C28E6B.3B8768D0_at_[hidden]>
>On Sun, 17 Nov 2002 18:57:52 -0800 Robert Ramey (ramey_at_[hidden]) wrote:
> I did briefly consider this, but it seemed it wasn't worth it. My
> real main objection was that it broke the symetry of the load/save
> system. I have found this symmetry is very helpful to permit
> verification that serialization is correctly used. Also, my "thought
> experiments" along these lines considered fundamental types
> where copying was really an efficiency issue. Finally it
> became clear that I couldn't figure out a way to handle
> the versioning problem. So there you are
>OK... is the main problem access to the version number, or is there more
>to it?
Start with a simple case:
Suppose MyClass looks like
class MyClass
{
const int i;
int k;
version_type version(){
return 1;
}
static load(boost::basic_iarchive &ar, version_type i){
ar >> k;
}
MyClass(int _i) :
i(_i);
{
ar >> *this;
}
MyClass(boost::basic_iarchive &ar) :
i(?)
{
ar >> *this
}
};
How do we intialize the const member? That was the main reason for non default
constructor. But suppose that's not a problem? What about version 2
class MyClass
{
const int i;
int k;
const int j; // particular to version 2
int l; // particular to version 2
version_type version(){
return 2;
}
static load(boost::basic_iarchive &ar, version_type v){
ar >>k;
if(v > 1){
ar >> l;
}
}
MyClass(int _i, int _j) :
i(_i, _j)
{}
MyClass(boost::basic_iarchive &ar) :
i(?),
? if version? > 1 j(?)
{}
};
It wasn't obvious how to initialize constant members and base classes
where that initialization depends upon the version number.
It seems to me that access to the version number could be got with syntax
like:
> MyClass( boost::basic_iarchive &ar ) {
> boost::version_type version = ar.version( this );
> //
> }
>via an archive member template with a signature like:
> template <typename T>
> version_type basic_iarchive::version( const T *p ) const;
>which seems to have enough information to look up typeid<T> in the
>cobject_id_set.
given the above, I never even got to the point of considering how to get the
version number out of the stream at the right time. maybe it easy.
I never thought about it.
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk