Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2002-02-08 07:23:48


Hi Sylvain,

On Friday, February 8, 2002, at 11:15 AM, quendezus wrote:
> See below a pseudocode of a mechanism to switch between compile time
> and run time serialization. The compile time code is executed if a
> terminal type is given to serialize_object( ). The run time code is
> executed if a base polymorphic type is given (and 'object' points on
> a derived type). Somehow, the user can thus choose the mechanism he
> wants to use through the type of the parameter. Does it correspond to
> your initial idea of "turn that off" ?
>
> Sylvain

Thanks for this nice piece of pseudo-code, which clearly shows
the one design problem in Jens' current persistence library:

> //--------------------------------------
>
> template <class E>
> void serialize_object( stream& dest, const E& object )
> {
>

We want to support different formats and thus should either
i) template it on the stream as done in Jens' library:

template <class stream, class E>
void serialize_object( stream& dest, const E& object )

or ii) make stream an abstract base class and implement
(de)serialization of the basic data types as virtual functions, which
is the approach I currently use in mine

....
> // If E is only a base class of 'object',
> // use the dynamic mechanism to
> // serialize. This mechanism requires
> // a previous registration of the type.
> else
> {
> // Get the serializer for the final type
> serializer& s =
> get_serializer( typeid( object ).name( ) );
>
> // Serialize the object (virtual method
> // of class 'serializer')
> s.serialize( dest,
> dynamic_cast< const void* >( &object ) );
>
....
Here serialize is a virtual method and will thus not work with the
nice approach i) above, since the stream type in a virtual function
cannot be a template parameter. Thus as far as I see we need an abstract
base class for the (de)serialization streams.

Matthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk