Boost logo

Boost :

From: craigp98072 (craigp98072_at_[hidden])
Date: 2002-03-02 04:50:07


I've been playing around with a serialization library. One thought I
had was to use a (poor man's) generative approach. Use a macro to
define the members:

#define SUPPLIER_TYPE_LIST BOOST_PP_TUPLE_TO_LIST( 4, \
  ( DECLARE_MEMBER( S_Num, num_, "S#" ), \
    DECLARE_MEMBER( S_Name, name_, "SName" ), \
    DECLARE_MEMBER( Status, status_, "Status" ), \
    DECLARE_MEMBER( City, city_, "City" ) ))

class Supplier_Tuple
{
  PCLASS(Supplier_Tuple, BOOST_PP_LIST_NIL, SUPPLIER_TYPE_LIST );
public:
  bool operator<(const Supplier_Tuple& rhs) const { return num_ <
rhs.num_; }
};

At that point, you can customize PCLASS to be anything you want. You
can declare a special constructor, a static 'create' method,
describe methods (const and non-const - mine take a templated
visitor rather than i/o archive), reflective methods, support for
the named parameter pattern (I haven't tried that one yet), etc.

Note that one reason I define a name for the members is so I can
integrate with an RDBMS and XML/RPC. They are, in a sense, optional.

--craig

--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> Has anyone considered describe /types/ instead of describe methods?
> One very clever system I've seen used globally-declared structure
instances
> to do this job. I don't remember the details at all, so this could
be
> completely off-the-mark:
>
> struct my_record : description<my_record>
> {
> char const name[] = "my_record";
> member<int> x;
> member<int> y;
> ...
> };
>
> ...
>
>
> ----- Original Message -----
> From: "Peter Dimov" <pdimov_at_m...>
> To: <boost_at_y...>
> Sent: Friday, March 01, 2002 7:54 AM
> Subject: Re: [boost] Re: Serialization (Persistence) library draft
> submission
>
>
> > From: "Vladimir Prus" <ghost_at_c...>
> > > I don't think there's consensus on describe vs. load/save
question.
> Having
> > > recorded this, I suggest that we postpone this question until
other
> issues
> > > are resolved.
> >
> > A single describe() method doesn't work for the following
reasons:
> >
> > 1. const correctness.
> > 2. read/write assymetry.
> > 2a. sequence serialization:
> >
> > template<class R, class T, class A> void read(R & r,
std::vector<T, A> &
> v,
> > int)
> > {
> > int m = begin_sequence(r);
> > v.resize(m);
> > if(m > 0) read_sequence(r, &v[0], m, 0);
> > end_sequence(r);
> > }
> >
> > vs
> >
> > template<class W, class T, class A> void write(W & w,
std::vector<T, A>
> > const & v, int)
> > {
> > int m = v.size();
> > begin_sequence(w, m);
> > if(m > 0) write_sequence(w, &v[0], m, 0);
> > end_sequence(w, m);
> > }
> >
> > 2b. versioning. When Complex version 1 is serialized as polar
coordinates
> > but version 2 is cartesian, read/write are assymetric.
> >
> > There probably is a solution to these problems but I haven't
found it yet
> > ('cause I didn't look that hard.)
> >
> >
> >
> > Info: http://www.boost.org Send unsubscribe requests to:
> <mailto:boost-unsubscribe_at_y...>
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
> >
> >
> >


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