Boost logo

Boost :

From: quendezus (quendez_at_[hidden])
Date: 2002-02-28 12:16:54


--- In boost_at_y..., johan.nilsson_at_e... wrote:
>
> To keep as non-intrusive as possible, it would be possible to
support
> specialized marshallers to support non-default constructors -
thereby
> allowing legacy objects to be marshalled, e.g.:
>
> on reading:
>
> ... gps_position_marshaller::read(T& ar, ...)
> {
> X par1, par2;
> ar >> par1 >> par2;
> gps_position* pos = new gps_position(par1, par2);
> ...
> }
>
> // Johan
>

The problem is that you can not always express deserialization as an
existing constructor call. See the code below :

struct C
        {
        A a_; // An attribute of type A
        B b_; // An attribute of type B
        C veryHardToComputeValue_; // An attribute of type C

        C( const A& a, const B& b ) : a_( a ), b_( b )
                {
                // Very long computing
                veryHardToComputeValue_.compute( a, b );
                }
        };

void save( Archive& a, const C& c )
        {
        a << c.a_;
        a << c.b_;
        a << veryHardToComputeValue_;
        }

void load( Archive& a, C& c )
        {
        a >> c.a_;
        a >> c.b_;
        a >> veryHardToComputeValue_;
        }

In that case you do not have any constructor to call and pass
veryHardToComputeValue as a parameter. Even if you could modify the
class to add a constructor that would take A&, B& and C&, you could
have problem to pass the C& parameter because maybe you don't want to
copy it or deal with allocation of that parameter.

Sylvain


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