Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Public Member Functions | Protected Member Functions | List of all members
gzfilebuf Class Reference

Gzipped file stream buffer class. More...

#include <zfstream.h>

+ Inheritance diagram for gzfilebuf:

Public Member Functions

 gzfilebuf ()
 
virtual ~gzfilebuf ()
 
gzfilebufopen (const char *name, int io_mode)
 
gzfilebufattach (int file_descriptor, int io_mode)
 
gzfilebufclose ()
 
int setcompressionlevel (int comp_level)
 
int setcompressionstrategy (int comp_strategy)
 
int is_open () const
 
virtual streampos seekoff (streamoff, ios::seek_dir, int)
 
virtual int sync ()
 
 gzfilebuf ()
 
virtual ~gzfilebuf ()
 
int setcompression (int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY)
 Set compression level and strategy on the fly. More...
 
bool is_open () const
 Check if file is open. More...
 
gzfilebufopen (const char *name, std::ios_base::openmode mode)
 Open gzipped file. More...
 
gzfilebufattach (int fd, std::ios_base::openmode mode)
 Attach to already open gzipped file. More...
 
gzfilebufclose ()
 Close gzipped file. More...
 

Protected Member Functions

virtual int underflow ()
 
virtual int overflow (int=EOF)
 
bool open_mode (std::ios_base::openmode mode, char *c_mode) const
 Convert ios open mode int to mode string used by zlib. More...
 
virtual std::streamsize showmanyc ()
 Number of characters available in stream buffer. More...
 
virtual int_type underflow ()
 Fill get area from gzipped file. More...
 
virtual int_type overflow (int_type c=traits_type::eof())
 Write put area to gzipped file. More...
 
virtual std::streambuf * setbuf (char_type *p, std::streamsize n)
 Installs external stream buffer. More...
 
virtual int sync ()
 Flush stream buffer to file. More...
 

Detailed Description

Gzipped file stream buffer class.

This class implements basic_filebuf for gzipped files. It doesn't yet support seeking (allowed by zlib but slow/limited), putback and read/write access (tricky). Otherwise, it attempts to be a drop-in replacement for the standard file streambuf.

Definition at line 8 of file zfstream.h.

Constructor & Destructor Documentation

◆ gzfilebuf() [1/2]

gzfilebuf::gzfilebuf ( )

Definition at line 4 of file zfstream.cpp.

◆ ~gzfilebuf() [1/2]

gzfilebuf::~gzfilebuf ( )
virtual

Definition at line 10 of file zfstream.cpp.

References close(), and sync().

◆ gzfilebuf() [2/2]

gzfilebuf::gzfilebuf ( )

◆ ~gzfilebuf() [2/2]

virtual gzfilebuf::~gzfilebuf ( )
virtual

Member Function Documentation

◆ attach() [1/2]

gzfilebuf * gzfilebuf::attach ( int  file_descriptor,
int  io_mode 
)

◆ attach() [2/2]

gzfilebuf * gzfilebuf::attach ( int  fd,
std::ios_base::openmode  mode 
)

Attach to already open gzipped file.

Parameters
fdFile descriptor.
modeOpen mode flags.
Returns
this on success, NULL on failure.

Definition at line 79 of file zfstream.cc.

References close(), gzclose(), gzdopen(), is_open(), NULL, open_mode(), out(), and sync().

◆ close() [1/2]

gzfilebuf * gzfilebuf::close ( )

◆ close() [2/2]

gzfilebuf* gzfilebuf::close ( )

Close gzipped file.

Returns
this on success, NULL on failure.

◆ is_open() [1/2]

int gzfilebuf::is_open ( ) const
inline

Definition at line 22 of file zfstream.h.

References EOF, NULL, overflow(), seekoff(), sync(), and underflow().

Referenced by attach(), close(), open(), overflow(), showmanyc(), sync(), and underflow().

◆ is_open() [2/2]

bool gzfilebuf::is_open ( ) const
inline

Check if file is open.

Returns
True if file is open.

Definition at line 57 of file zfstream.h.

References attach(), close(), NULL, open(), open_mode(), overflow(), setbuf(), showmanyc(), sync(), and underflow().

◆ open() [1/2]

gzfilebuf * gzfilebuf::open ( const char *  name,
int  io_mode 
)

◆ open() [2/2]

gzfilebuf * gzfilebuf::open ( const char *  name,
std::ios_base::openmode  mode 
)

Open gzipped file.

Parameters
nameFile name.
modeOpen mode flags.
Returns
this on success, NULL on failure.

Definition at line 51 of file zfstream.cc.

References gzopen(), is_open(), NULL, open_mode(), and out().

◆ open_mode()

bool gzfilebuf::open_mode ( std::ios_base::openmode  mode,
char *  c_mode 
) const
protected

Convert ios open mode int to mode string used by zlib.

Returns
True if valid mode flag combination.

Definition at line 131 of file zfstream.cc.

References out(), and vl::trunc().

Referenced by attach(), is_open(), and open().

◆ overflow() [1/2]

int gzfilebuf::overflow ( int  c = EOF)
protectedvirtual

Definition at line 173 of file zfstream.cpp.

References EOF, is_open(), and out().

Referenced by is_open(), and setbuf().

◆ overflow() [2/2]

gzfilebuf::int_type gzfilebuf::overflow ( int_type  c = traits_type::eof())
protectedvirtual

Write put area to gzipped file.

Parameters
cExtra character to add to buffer contents.
Returns
Non-EOF on success, EOF on error.

This actually writes characters in stream buffer to gzipped file. With unbuffered output this is done one character at a time.

Definition at line 214 of file zfstream.cc.

References gzwrite(), is_open(), and out().

◆ seekoff()

streampos gzfilebuf::seekoff ( streamoff  off,
ios::seek_dir  dir,
int  which 
)
virtual

Definition at line 129 of file zfstream.cpp.

References EOF.

Referenced by is_open().

◆ setbuf()

std::streambuf * gzfilebuf::setbuf ( char_type *  p,
std::streamsize  n 
)
protectedvirtual

Installs external stream buffer.

Parameters
pPointer to char buffer.
nSize of external buffer.
Returns
this on success, NULL on failure.

Call setbuf(0,0) to enable unbuffered output.

Definition at line 266 of file zfstream.cc.

References gzifstream::gzifstream(), NULL, overflow(), SMALLBUFSIZE, and sync().

Referenced by is_open().

◆ setcompression()

int gzfilebuf::setcompression ( int  comp_level,
int  comp_strategy = Z_DEFAULT_STRATEGY 
)

Set compression level and strategy on the fly.

Parameters
comp_levelCompression level (see zlib.h for allowed values)
comp_strategyCompression strategy (see zlib.h for allowed values)
Returns
Z_OK on success, Z_STREAM_ERROR otherwise.

Unfortunately, these parameters cannot be modified separately, as the previous zfstream version assumed. Since the strategy is seldom changed, it can default and setcompression(level) then becomes like the old setcompressionlevel(level).

Definition at line 43 of file zfstream.cc.

References gzsetparams().

Referenced by setcompression().

◆ setcompressionlevel()

int gzfilebuf::setcompressionlevel ( int  comp_level)

Definition at line 116 of file zfstream.cpp.

References gzsetparams().

Referenced by setcompressionlevel().

◆ setcompressionstrategy()

int gzfilebuf::setcompressionstrategy ( int  comp_strategy)

Definition at line 122 of file zfstream.cpp.

References gzsetparams().

Referenced by setcompressionstrategy().

◆ showmanyc()

std::streamsize gzfilebuf::showmanyc ( )
protectedvirtual

Number of characters available in stream buffer.

Returns
Number of characters.

This indicates number of characters in get area of stream buffer. These characters can be read without accessing the gzipped file.

Definition at line 169 of file zfstream.cc.

References gzread(), is_open(), and underflow().

Referenced by is_open().

◆ sync() [1/2]

int gzfilebuf::sync ( )
virtual

Definition at line 206 of file zfstream.cpp.

References EOF, gzread(), gzwrite(), and is_open().

Referenced by attach(), close(), is_open(), setbuf(), and ~gzfilebuf().

◆ sync() [2/2]

virtual int gzfilebuf::sync ( )
protectedvirtual

Flush stream buffer to file.

Returns
0 on success, -1 on error.

This calls underflow(EOF) to do the job.

◆ underflow() [1/2]

gzfilebuf::int_type gzfilebuf::underflow ( )
protectedvirtual

Definition at line 135 of file zfstream.cpp.

References EOF, and is_open().

Referenced by is_open(), and showmanyc().

◆ underflow() [2/2]

virtual int_type gzfilebuf::underflow ( )
protectedvirtual

Fill get area from gzipped file.

Returns
First character in get area on success, EOF on error.

This actually reads characters from gzipped file to stream buffer. Always buffered.


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