|
Boost : |
From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2003-12-03 00:23:02
I've been looking at the latest draft of the serialization library and I'm
wondering why the serialize member function is not static. By definition,
isn't the schema for serializing any particular data type a property of
the data type, and not a property of a particular instance of the data
type? A static serialize() would give the Archive member data pointers
instead of actual pointers; if nothing else, this would prevent users from
passing temporary variables to the Archive (unless there is a use case for
this?).
Some context: I'm looking at a more natural interface to XML[*] than
SAX/DOM/etc., and of course XML is all about serialization. I'd like to
reuse, if possible, the serialize() member function so that users can
specify their serializable data members in one place and it will work for
both libraries (should the XML library ever actually exist <g>). But, I
need data member pointers for several reasons:
1) Ability to generate a DTD (or some other XML schema) for a
particular data type (and all children) given only the information in the
serialize() member function (no instances, anywhere).
2) Ability to check an XML document against the above implicit DTD
without attempting to deserialize any objects in the document.
3) Ability to construct an XML "view" into a live object, such
that modifications to the XML view and show up in the object and
vice-versa. This is the most important aspect of said XML library.
4) I think I need to tell the difference between a reference data
member and a non-reference data member. The former isn't serializable, but
with the current serialize() interface we can't tell that.
I think my ideal interface would have serialize functions looking like
this:
class Foo : public Bar {
template<typename Archive>
static void serialize(Archive& ar, unsigned int version)
{
ar("Foo")
.template base<Bar>()
.member("x", &Foo::x)
.member("y", &Foo::y)
;
}
int x;
float* y;
};
It's a little more verbose, but (after sorting out some base-class issues)
I can turn that into a reasonable DTD.
Doug
[*] Looking at, but not seriously implementing until I find some serious
free time.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk