Boost logo

Boost :

From: Jonathan de Halleux (dehalleux_at_[hidden])
Date: 2003-10-09 09:13:42


As many of you (Ehsan Akhgari, Pavel Vozenilek , Jeff Garlan) suggested the
compressor streams should be policy based.
This is done in the latest file I've uploaded in the boost file section
(http://f6.grp.yahoofs.com/v1/4GmFPx08Dk78-mCwbsdmEsocMpYlDvaQXOOUN3-j-BLESjgdQHMJM7riceqfUm94t1iN9Q2N6EU0SdY6g84scRrmpyl_x2DtQjOVzg/zipstream/zipstream_policied.zip)
Right now, only the gzip library is wrapped but other like bzip2 and lzo
should straighforward. -> the new policized compressor class is
compressed_stream.hpp, .ipp and gzip_stream.hpp

How does it work: the user has to provider to a compressor and a
decompressor class that are used as template parameters (examples are given
below). Basically, you have to implement 3 methods by class: init,
read/write, finish.

Here's a snippet that uses the gzip library:

// any ostream
ostringstream out;
// creating a compressor
gzip_compressor gz ( /* various gzip specific options */ );
// creating a compressor stream
gzip_ostream gzipper(out, gz );

gzipper is ostream derived.

The compressor class is defined as follows
<pre>
class basic_compressor_actor
{
public:
     /// initialize the compressor
     /// ostream_ is the input buffer
     template<typename Elem, typename Tr>
     void initialize(std::basic_ostream<Elem,Tr>& ostream_);

     /// compress a buffer to an ostream
     /// ostream_, the output stream,
     /// buffer_, address of the byte buffer,
     /// buffer_size_, size in bytes of the buffer
     /// returns true if succesfull
     template<typename Elem, typename Tr>
         bool compress_to_stream(
         std::basic_ostream<Elem,Tr>& ostream_,
         Elem* buffer_,
         std::streamsize buffer_size_
         );

     /// flushes the buffer, the compressor and the output stream
     /// returns the written byte size
     template<typename Elem, typename Tr>
     std::streamsize flush(
         std::basic_ostream<Elem,Tr>& ostream_
         );

     /// finalizes compression and cleans memory
     /// ostream_ is the output buffer
     template<typename Elem, typename Tr>
     void finalize(std::basic_ostream<Elem,Tr>& ostream_);
};
</pre>

the decompressor class:
<pre>
class basic_decompressor_actor
{
public:
     /// initializes the decompressor
     /// istream_ is the input buffer
     template<typename Elem, typename Tr>
     void initialize(std::basic_istream<Elem,Tr>& istream_);

     /// decompress data from the input buffer and puts it in the buffer array
     /// istream_ is the input buffer
     /// buffer is a memory buffer to write to
     /// buffer_size_ is the buffer size ( in number of Elem )
     /// returns the number of Elem written
     template<typename Elem, typename Tr>
     std::streamsize decompress_from_stream(
         std::basic_istream<Elem,Tr> istream_,
         Elem* buffer_,
         std::streamsize buffer_size_
         );

     /// reads the footer if necessary
     /// istream_ is the input buffer
     template<typename Elem, typename Tr>
     void read_footer(std::basic_istream<Elem,Tr>& istream_);

     /// closes the compressor and cleans up
     /// istream_ is the input buffer
     template<typename Elem, typename Tr>
     void finalize(std::basic_istream<Elem,Tr>& istream_);
};
</pre>

Suggestions ?

_______________________________________________
>Unsubscribe & other changes:
>http://lists.boost.org/mailman/listinfo.cgi/boost

-----------------------------------------------------------------------------------
Jonathan de Halleux, Research Assistant
Center for Systems Engineering and Applied Mechanics (CESAME)
Universite catholique de Louvain
Batiment Euler , Av. Georges Lemaitre, 4 Tel : +32-10-47 2595
B-1348 Louvain-la-Neuve Belgium
E-mail : dehalleux_at_[hidden]
-----------------------------------------------------------------------------------


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