Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-11-19 01:42:34

Robert Ramey wrote:

> Lets expand your example:
> Once upon a time in a module far, far away, the following
> code is executed.
> D1* d1 = new D1;
> D2* d2 = new D2;
> B* b = d1;
> // sometime later in the serialize module the following is invoked
> oa << b;


> this invokes the following code from oserializer.hpp. We add some extra
> comments (////) to illustrate what happens in a this specific example.
> // at compile time T = B
> // at runtime t is a reference to either a B or the B part of a D1 or D2.
> // at runtimt bos_ptr points to a serializer for a type T poiner

Ehh.. does it point to serializer for B? Or for either D1 or D2, depending
on the type actually serialized? Since it should store the data, I'd assume
the latter.

> if(*this_type != *true_type){
> //// t(D1) refers to something other than a T (B)
> //// so shift the vp from pointing to B to point to
> //// the D1 part of t.
> // convert pointer to more derived type
> vp = void_downcast(*this_type, *true_type, &t);
> assert(NULL != vp);


> //// set the pointer to the serializer to the serializer
> //// corresponding to a D1
> bos_ptr = basic_oserializer::find(*true_type);
> }
> //// now we know that vp points to a D1
> //// and bos_ptr points to a pointer serializer for a type D1
> assert(NULL != bos_ptr);
> ar.save_pointer(vp, *bos_ptr);

I'm lost at this point. The 'save_pointer' somehow stores the *actual*
object, so it has some way to invoke serialization for the actual type.
Good, so if you pass void pointer to base object, the code which stores that
data will assume it points to the most derived type, and crash. Now, am I
right in assuming that you can detect the case where most derived type is
not equal to static type only for polymorphic classes? Is so, then you can

to get the most derived object in serialization code, without void_cast. Am
I missing something?

- Volodya

Boost list run by bdawes at, gregod at, cpdaniel at, john at