Boost logo

Boost Users :

Subject: [Boost-users] [iostreams] [archive] [serialization] lexical_cast<string> with binary_archive vs. text_archive
From: Johann Goetz (jgoetz_at_[hidden])
Date: 2009-08-23 02:05:26


Consider the following serialization archive. I can serialize a
collection of variables (floats, ints, etc) through the series:
    numerics --> text_oarchive --> gzip --> output_file
The text_archive step is essentially a stringstream filter. This filter
gives the serialization the portability I (sometimes) need.

namespace io = boost::iostreams;
namespace ar = boost::archive;

io::filtering_ostream fos;
fis.push(io::gzip_compressor());
fis.push(io::file_sink("output.txt.gz"));
ar::text_oarchive oa(fos);

OK. Now what I wish to do is to create a binary_archive and to push the
stringstream filter to the filtering_ostream:
 numerics -> binary_archive -> lexical_cast<string> -> gzip -> out_file
This way I could turn this part (and the gzip) on or off at will (the
ol' speed vs portability thing):

io::filtering_ostream fos;
fis.push(/*stringstream_filter*/);
fis.push(io::gzip_compressor());
fis.push(io::file_sink("output.txt.gz"));
ar::binary_oarchive oa(fos);

I am not sure how to create such a filter, but I'm guessing such a
filter already exists. Perhaps the answer lies in lexical_cast<string>?
any help with this would be greatly appreciated, thanks!
Johann.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net