rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWCompressedStreamBuffer< Compressor > Class Template Reference
[Virtual Streams]

Derived stream buffer that reads and writes compressed data to an associated std::streambuf. More...

#include <rw/tools/cmpstreambuf.h>

List of all members.

Public Member Functions

 RWCompressedStreamBuffer (const Compressor &compressor=Compressor())
 RWCompressedStreamBuffer (std::streambuf *stream_buffer, std::ios_base::openmode mode, rwuint32 block_size, const Compressor &compressor=Compressor())
virtual ~RWCompressedStreamBuffer ()
RWCompressedStreamBufferopen (std::streambuf *stream_buffer, std::ios_base::openmode mode, rwuint32 block_size)
RWCompressedStreamBufferclose ()
bool is_open () const
const Compressor & get_compressor () const

Detailed Description

template<class Compressor>
class RWCompressedStreamBuffer< Compressor >

Derived stream buffer that reads and writes compressed data to an associated std::streambuf using the provided compressor type.

The compressor must be copy constructable, and if an instance isn't provided to the constructor, it must be default constructable. It is also expected to support the following interface methods.

The parameter dst_len initially describes the length of the output buffer dst, and src_len describes the length of the input buffer src. This function compresses src_len bytes of data from src into dst and puts the number of bytes written to dst into dst_len. Must return 0 on success, or a negative value on error.

The parameter dst_len initially describes the length of the output buffer dst, and src_len describes the length of the input buffer src. This function decompresses src_len bytes of data from src into dst and puts the number of bytes written to dst into dst_len. Must return 0 on success, or a negative value on error.

The parameter src_len is the length of an uncompressed data buffer. This function writes the worst case compressed size of that data to dst_len. Must return 0 on success, or a negative value on error.

Note:
This class is only able to read compressed data that was generated by a similar stream buffer. It cannnot read compressed data that was generated with other tools or with data compressed using a different compressor type.

Constructor & Destructor Documentation

template<class Compressor >
RWCompressedStreamBuffer< Compressor >::RWCompressedStreamBuffer ( const Compressor &  compressor = Compressor()  ) 

Constructor initializes a stream buffer that uses compressor to compress or decompress data. A successfull call to open() is required before this stream buffer can be used.

template<class Compressor >
RWCompressedStreamBuffer< Compressor >::RWCompressedStreamBuffer ( std::streambuf *  stream_buffer,
std::ios_base::openmode  mode,
rwuint32  block_size,
const Compressor &  compressor = Compressor() 
)

Constructor initializes a stream buffer that reads compressed data from or writes compressed data to stream_buffer in buffers of up to block_size bytes, and uses compressor to compress or decompress data as necessary. The mode parameter controls how this stream buffer may be used.

Note:
If mode indicates that the underlying stream buffer is to be used for output, block_size should be non-zero. Typically larger values result in better compression levels.
template<class Compressor >
virtual RWCompressedStreamBuffer< Compressor >::~RWCompressedStreamBuffer (  )  [virtual]

Destructor.


Member Function Documentation

template<class Compressor >
RWCompressedStreamBuffer* RWCompressedStreamBuffer< Compressor >::close (  ) 

Closes this stream buffer, flushes all pending data, and disassociates it from the underlying std::streambuf. After calling this method, this stream buffer cannot be used for input or output until it has been reopened with a successful call to open().

Returns NULL on error, otherwise returns a pointer to self.

template<class Compressor >
const Compressor& RWCompressedStreamBuffer< Compressor >::get_compressor (  )  const [inline]

Returns a reference to the underlying compressor.

template<class Compressor >
bool RWCompressedStreamBuffer< Compressor >::is_open (  )  const [inline]

Returns true if this stream buffer is open and is ready for use, otherwise returns false.

template<class Compressor >
RWCompressedStreamBuffer* RWCompressedStreamBuffer< Compressor >::open ( std::streambuf *  stream_buffer,
std::ios_base::openmode  mode,
rwuint32  block_size 
)

Opens this stream buffer to read or write compressed data.

If mode indicates that this stream buffer is to be used for output, block_size specifies the number of bytes of uncompressed data to be buffered. When the buffer is overfilled or flushed, it will be compressed and written to stream_buffer.

If mode indicates that this stream buffer is to be used for input, data will be read from stream_buffer and decompressed into a local buffer. The size of this local buffer is not associated with block_size in any way.

Returns NULL when this stream buffer is already open or if there is some other error, otherwise returns a pointer to self.

Note:
If mode indicates that the underlying stream buffer is to be used for output, block_size should be non-zero. Typically larger values result in better compression levels.
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.