Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-10-30 17:27:23


Vladimir Prus wrote:

>I have one more comment about the serialization library.

>I have a class with three member variables;

> unsigned resource_count;
> unsigned content_size;
> int* content;

>I started writing 'serialize' method

> void serialize(Archive& ar, unsigned int version)
> {
> ar & resource_count & content_size;
> ar.write_binary(content, content_size);
> }

>and realized that it won't work for input archives -- so I need to split
>serialization. This looks like overkill for such a simple class. Maybe, a
>better solution would be to introduce 'array' method which
>- takes a pointer and the size of elements
>- is defined for both input and output archieves.

> void serialize(Archive& ar, unsigned int version)
> {
> ar & resource_count & content_size;
> ar.array(content, content_size);
> }

>and it will work for both input and output. (For input, the pointer need to be
>created). Another solution, which is probably clearer, it to define a wrapper
>class c_array, which takes pointer and a size and does the right thing. I'd
>write:

> ar & c_array(content, content_size);

>Surely, it's not 100% required, but would be nice.

There a several possibilities here that might suggested.

a) you idea above

b) arrays are already addressed so that the follownig might work
if count is known at compile time

ar & static_cast<int[size_t] &](*content)

c) override serialize for an int *

....

d) replace read_binary and write_binary with
serialize_binary(Archive ar, void * & t, unsigned int size)

and define an optional splitter for this - I like this idea the best

I'v put off any work with read/write archive for now as I want to
get all the pending stuff absolutly done before I add any more
features. As this is now only implemented for binary archives
its still a little up in the air as to its final form. I was going
to do it sooner but I need some iteratator adaptros for
changing data to base64 and escaped ascii etc. Then I
wanted to convert my old home-made iterator adaptors
to the recently introdude MOAIA* . I finally got that about
done when the load_construct question arose, then the jam
build/test got "fixed" when I wasn't looking so the stack
got deeper faster than I could pop it off. Anyway, I'm
just getting back to a fixed point but a read_binary/write
binary are still unaddressed.

Robert Ramey

*Mother Of All Iterator Adaptors


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