SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWCompressedStreamBuffer< Compressor > Class Template Reference

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

#include <rw/tools/cmpstreambuf.h>

Inherits streambuf.

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 ()
 
RWCompressedStreamBufferclose ()
 
const Compressor & get_compressor () const
 
bool is_open () const
 
RWCompressedStreamBufferopen (std::streambuf *stream_buffer, std::ios_base::openmode mode, rwuint32 block_size)
 

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 constructible, and if an instance isn't provided to the constructor, it must be default constructible. 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 able to read only compressed data that was generated by a similar stream buffer. It cannot 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 successful 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.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.