Rosetta  2020.37
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT > Class Template Reference

A zipper ostream. More...

#include <zipstream.hpp>

Inheritance diagram for zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >:
Inheritance graph
[legend]

Public Types

typedef basic_zip_ostreambase
< Elem, Tr, ElemA, ByteT,
ByteAT > 
zip_ostreambase_type
 
typedef std::basic_ostream
< Elem, Tr > 
ostream_type
 
typedef std::basic_ostream
< Elem, Tr > & 
ostream_reference
 
typedef Elem char_type
 
- Public Types inherited from zlib_stream::basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT >
typedef std::basic_ostream
< Elem, Tr > & 
ostream_reference
 
typedef basic_zip_streambuf
< Elem, Tr, ElemA, ByteT,
ByteAT > 
zip_streambuf_type
 

Public Member Functions

 basic_zip_ostream (ostream_reference ostream_, bool is_gzip_=false, size_t level_=Z_DEFAULT_COMPRESSION, EStrategy strategy_=DefaultStrategy, size_t window_size_=15, size_t memory_level_=8, size_t buffer_size_=default_buffer_size)
 Constructs a zipper ostream decorator. More...
 
 ~basic_zip_ostream () override
 
bool is_gzip () const
 returns true if it is a gzip More...
 
basic_zip_ostream< Elem, Tr > & zflush ()
 flush inner buffer and zipper buffer More...
 
basic_zip_ostream< Elem, Tr > & zflush_finalize ()
 flush inner and zipper buffers and finalize zip stream More...
 
template<typename T >
basic_zip_ostreamoperator<< (T const &t)
 stream output More...
 
basic_zip_ostreamput (char const c)
 write char More...
 
basic_zip_ostreamwrite (char const *str, std::streamsize const count)
 write a string More...
 
- Public Member Functions inherited from zlib_stream::basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT >
 basic_zip_ostreambase (ostream_reference ostream_, size_t level_, EStrategy strategy_, size_t window_size_, size_t memory_level_, size_t buffer_size_)
 Construct a zip stream. More...
 
zip_streambuf_typerdbuf ()
 returns the underlying zip ostream object More...
 
int get_zerr () const
 returns the zlib error state More...
 
uLong get_crc () const
 returns the uncompressed data crc More...
 
uLong get_out_size () const
 returns the compressed data size More...
 
uLong get_in_size () const
 returns the uncompressed data size More...
 

Private Member Functions

bool reset_zip_stream ()
 if end of stream, reset the zip stream and add header More...
 
void add_header ()
 
void add_footer ()
 

Static Private Member Functions

static void put_long_as_uint32 (ostream_reference out_, unsigned long x_)
 

Private Attributes

bool m_is_gzip
 
bool m_zip_stream_finalized
 tracks to see if zip stream was finalized More...
 

Detailed Description

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
class zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >

A zipper ostream.

Remarks

This class is a ostream decorator that behaves 'almost' like any other ostream.

At construction, it takes any ostream that shall be used to output of the compressed data.

When finished, you need to call the special method zflush or call the destructor to flush all the intermidiate streams.

Example:

// creating the target zip string, could be a fstream
ostringstream ostringstream_;
// creating the zip layer
zip_ostream zipper(ostringstream_);
// writing data
zipper<<f<<" "<<d<<" "<<ui<<" "<<ul<<" "<<us<<" "<<c<<" "<<dum;
// zip ostream needs special flushing...
zipper.zflush();

Member Typedef Documentation

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
typedef Elem zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::char_type
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
typedef std::basic_ostream< Elem, Tr >& zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::ostream_reference
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
typedef std::basic_ostream< Elem, Tr > zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::ostream_type
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
typedef basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT > zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zip_ostreambase_type

Constructor & Destructor Documentation

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::basic_zip_ostream ( ostream_reference  ostream_,
bool  is_gzip_ = false,
size_t  level_ = Z_DEFAULT_COMPRESSION,
EStrategy  strategy_ = DefaultStrategy,
size_t  window_size_ = 15,
size_t  memory_level_ = 8,
size_t  buffer_size_ = default_buffer_size 
)
inline

Constructs a zipper ostream decorator.

Parameters
ostream_ostream where the compressed output is written
is_gzip_true if gzip header and footer have to be added
level_level of compression 0, bad and fast, 9, good and slower,
strategy_compression strategy
window_size_see zlib doc
memory_level_see zlib doc
buffer_size_the buffer size used to zip data
Note
When is_gzip_ is true, a gzip header and footer is automatically added

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::add_header(), and zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::m_is_gzip.

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::~basic_zip_ostream ( )
inlineoverride

Member Function Documentation

template<typename Elem , typename Tr , typename ElemA , typename ByteT , typename ByteAT >
void zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::add_footer ( )
private
template<typename Elem , typename Tr , typename ElemA , typename ByteT , typename ByteAT >
void zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::add_header ( )
private
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
bool zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::is_gzip ( ) const
inline
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
template<typename T >
basic_zip_ostream& zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::operator<< ( T const &  t)
inline

stream output

if zip stream has been finalized, will reset

the stream and add header if necessary

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::reset_zip_stream(), and basic::options::OptionKeys::in::file::t.

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
basic_zip_ostream& zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::put ( char const  c)
inline

write char

if zip stream has been finalized, will reset

the stream and add header if necessary

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::reset_zip_stream().

Referenced by utility::io::ozstream::put().

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
void zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::put_long_as_uint32 ( ostream_reference  out_,
unsigned long  x_ 
)
staticprivate
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
bool zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::reset_zip_stream ( )
inlineprivate
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
basic_zip_ostream& zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::write ( char const *  str,
std::streamsize const  count 
)
inline

write a string

if zip stream has been finalized, will reset

the stream and add header if necessary

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::reset_zip_stream().

Referenced by zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::put_long_as_uint32(), and utility::io::ozstream::write().

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
basic_zip_ostream< Elem, Tr >& zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush ( )
inline
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
basic_zip_ostream< Elem, Tr >& zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize ( )
inline

Member Data Documentation

template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
bool zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::m_is_gzip
private
template<typename Elem, typename Tr = std::char_traits< Elem >, typename ElemA = std::allocator< Elem >, typename ByteT = unsigned char, typename ByteAT = std::allocator< ByteT >>
bool zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::m_zip_stream_finalized
private

The documentation for this class was generated from the following files: