SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWCompressedIOStream< Compressor > Class Template Reference

Compresses and serializes data to or deserializes and decompresses data from an associated std::streambuf. More...

#include <rw/tools/cmpstream.h>

Inherits std::iostream.

Public Member Functions

 RWCompressedIOStream (std::iostream &stream, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out, rwuint32 block_size=2048U, const Compressor &compressor=Compressor())
 
 RWCompressedIOStream (std::streambuf *stream_buffer, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out, rwuint32 block_size=2048U, const Compressor &compressor=Compressor())
 
void close ()
 
const Compressor & get_compressor () const
 
bool is_open () const
 
void open (std::streambuf *stream_buffer, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out, rwuint32 block_size=2048U)
 
RWCompressedStreamBuffer< Compressor > * rdbuf () const
 

Detailed Description

template<class Compressor>
class RWCompressedIOStream< Compressor >

Class RWCompressedIOStream compresses and serializes data to or deserializes and decompresses data from an associated std::streambuf. Data read from the associated streambuf must have been serialized with RWCompressedOStream or RWCompressedIOStream, and any data written to the associated streambuf can be deserialized with RWCompressedIStream or RWCompressedIOStream.

See also
RWCompressedStreamBuffer
Note
RWCompressedIOStream can be interrogated as to the stream state using member functions std::ios::good(), std::ios::bad(), std::ios::eof(), etc.
Synopsis
#include <rw/tools/cmpstream.h>
std::fstream f("output.fil");
// Construct an RWCompressedIOStream using f's streambuf
Compresses and serializes data to or deserializes and decompresses data from an associated std::strea...
Definition cmpstream.h:536
Persistence
None
Example
// for SourcePro Core Tools Module compressed streams
#include <rw/tools/cmpstream.h>
// for SourcePro Core Tools Module endian streams
#include <rw/estream.h>
// for SourcePro Core Tools Module strings
#include <rw/cstring.h>
// for SourcePro Core Snappy compressor
#include <rw/tools/snappy/RWSnappyCompressor.h>
// for C++ Standard Library file streams
#include <fstream>
int main() {
// open the file to write to and read from
std::fstream data_file("output.snap", std::ios_base::binary);
// layer a compressed stream on top of the file
RWCompressedIOStream<RWSnappyCompressor> compressed_stream(data_file);
{
// layer an endian stream on top of the compressed stream
RWeostream endian_stream(compressed_stream);
//
// Any data written to the endian stream is converted into
// an endian safe format by the endian stream, compressed by the
// compressed stream, and written to the file by the file stream.
//
RWCString data('a', 32);
endian_stream << data;
}
// Ensure data written to the associated stream buffer is written to
// the underlying stream buffer.
compressed_stream.flush();
{
// layer an endian stream on top of the compressed stream
RWeistream endian_stream(compressed_stream);
//
// Any data read from the endian stream is read from the file
// stream, decompressed by the compressed stream, and converted into
// an endian safe format into binary data by the endian stream.
//
RWCString data;
compressed_stream >> data;
std::cout << data;
}
return 0;
}
Offers powerful and convenient facilities for manipulating strings.
Definition stdcstring.h:826
Specializes the base class RWbistream to restore values previously stored by RWeostream.
Definition estream.h:380
Specializes the base class RWbostream to store values in a portable binary format.
Definition estream.h:84

Program output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Constructor & Destructor Documentation

◆ RWCompressedIOStream() [1/2]

template<class Compressor >
RWCompressedIOStream< Compressor >::RWCompressedIOStream ( std::streambuf * stream_buffer,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out,
rwuint32 block_size = 2048U,
const Compressor & compressor = Compressor() )
inline

Constructor initializes and opens the underlying stream buffer with the provided stream_buffer, mode, block_size, and compressor. If the open fails, failbit is set on this stream.

Note
The mode is always combined with the appropriate flags to allow the underlying stream buffer to be used for input and output.
See also
RWCompressedStreamBuffer::open()

◆ RWCompressedIOStream() [2/2]

template<class Compressor >
RWCompressedIOStream< Compressor >::RWCompressedIOStream ( std::iostream & stream,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out,
rwuint32 block_size = 2048U,
const Compressor & compressor = Compressor() )
inline

Constructor initializes and opens the underlying stream buffer with the provided mode, block_size, compressor, and the stream buffer associated with stream. If the open fails, failbit is set on this stream.

Note
The mode is always combined with the appropriate flags to allow the underlying stream buffer to be used for input and output.
See also
RWCompressedStreamBuffer::open()

Member Function Documentation

◆ close()

template<class Compressor >
void RWCompressedIOStream< Compressor >::close ( )
inline

Closes the underlying stream buffer. If the close fails, failbit is set on this stream. After this method has been called, this stream cannot be used for input or output until a successful call to open() has been made.

◆ get_compressor()

template<class Compressor >
const Compressor & RWCompressedIOStream< Compressor >::get_compressor ( ) const
inline

Returns a reference to the underlying stream buffer's compressor.

◆ is_open()

template<class Compressor >
bool RWCompressedIOStream< Compressor >::is_open ( ) const
inline

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

◆ open()

template<class Compressor >
void RWCompressedIOStream< Compressor >::open ( std::streambuf * stream_buffer,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out,
rwuint32 block_size = 2048U )
inline

Opens the underlying stream buffer with the provided stream_buffer, mode, and block_size. If the open fails, failbit is set on this stream.

Note
The mode is always combined with the appropriate flags to allow the underlying stream buffer to be used for input and output.
See also
RWCompressedStreamBuffer::open()

◆ rdbuf()

template<class Compressor >
RWCompressedStreamBuffer< Compressor > * RWCompressedIOStream< Compressor >::rdbuf ( ) const
inline

Returns a pointer to the underlying stream buffer.

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