Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-11 11:33:00


From: "Vladimir Prus"

> Peter Dimov wrote:
> >
> > If you are willing to confine yourself to a given
platform/compiler/version,
> > which I am not, you don't need to demangle type_info::name.
>
> Why confine yourself to a single platform. If you have
> platform-dependent demanglers for type_info::name(), then everything
> else should be portable.

Well, yes, for some suitable definition of "demangler". :-)

> >>1. Register all polymorphic classes with any instance of
> >>basic_{i,o}archive that you create
> >
> >
> > My own serialization framework has the same requirement, unfortunately.
I
> > haven't been able to avoid it.
>
> Why can't polymorphic classes be registered globally?

I misread your statement above; my code currently requires that you register
the (reader/writer, class) type pair. Registration is global.

On the other hand, I don't handle pointers well, if at all, so I can't
really say whether Robert Ramey's approach is needlessly restrictive.

> > Having to write essentially the same code twice seems inconvenient, but
I am
> > willing to pay the price. In fact currently I'm writing the same code
three
> > times (the third variation includes variable names).
>
> Oh... I thought about variable names too! Did I understood correctly
> that you use scheme with const and non-const 'describe'?

Here is what I do currently:

struct X
{
    explicit X(int i = 0): i(i)
    {
    }

    virtual ~X()
    {
    }

    int i;
};

template<class R> void read(R & r, X & x)
{
    begin_struct(r);
    read(r, x.i);
    end_struct(r);
}

template<class W> void write(W & w, X const & x)
{
    begin_struct(w);
    write(w, x.i);
    end_struct(w);
}

template<class W, class A> void write(W & w, X const & x, A const & a)
{
    begin_struct(w, a);
    write(w, x.i, "i");
    end_struct(w, a);
}

This is quite repetitive and error-prone, but without reflection/metadata...


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