Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] Postpone saving
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-07-18 11:45:38

Mailing Lists Controller wrote:
> Hi,
> I'm working with the Serialization library and in detail with the xml
> archives. In my code I have to serialize a lot of classes and I wish
> to save in the xml file only when I've done with the serialization of
> all clasess,

The best way to do this would be to use your own stream type.
a) make a new filebuf which just saves all it's data until it closes.
b) make a new stream type which uses your new file buf
c) use your new stream type when you create a serialization archive

Another way- not as good be perhaps simpler
a) serialize to a stringstream
b) when done, writhe the string stream to a file.

>also I would like to have more control when the
> Serialization saves the file (do it raise exceptions when it save
> files? Which ones?).

See the documentaton for list of exceptions which might be invoked.

> As far as I read from the tutorials when I use the operator<< in the
> xml_archive it save directly to the files.

It actually writes to a stream, the stream writes to filebuf, filebuf writes
to files.

> In my test I've seen that
> the archive have no problem to save many classes to the same archive
> however as I've wrote I would like to have more control (at least to
> know which errors appear during writing).

> Is it possible?

more than possible. It's easy. OK it does require careful study of
C++ streams and how to use them - but that's useful anyway.

Robert Ramey

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at