GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
|
Gzipped file stream buffer class. More...
#include "zfstream.h"
Public Member Functions | |
gzfilebuf () | |
virtual | ~gzfilebuf () |
gzfilebuf * | attach (int fd, std::ios_base::openmode mode) |
Attach to already open gzipped file. | |
gzfilebuf * | close () |
Close gzipped file. | |
bool | is_open () const |
Check if file is open. | |
gzfilebuf * | open (const char *name, std::ios_base::openmode mode) |
Open gzipped file. | |
int | setcompression (int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY) |
Set compression level and strategy on the fly. |
Protected Member Functions | |
bool | open_mode (std::ios_base::openmode mode, char *c_mode) const |
Convert ios open mode int to mode string used by zlib. | |
virtual int_type | overflow (int_type c=traits_type::eof()) |
Write put area to gzipped file. | |
virtual int_type | pbackfail (int_type c=traits_type::eof()) |
virtual pos_type | seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) |
Alters the stream positions. | |
virtual pos_type | seekpos (pos_type sp, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) |
Alters the stream positions. | |
virtual std::streambuf * | setbuf (char_type *p, std::streamsize n) |
Installs external stream buffer. | |
virtual std::streamsize | showmanyc () |
Number of characters available in stream buffer. | |
virtual int | sync () |
Flush stream buffer to file. | |
virtual int_type | underflow () |
Fill get area from gzipped file. |
Private Member Functions | |
gzfilebuf (const gzfilebuf &) | |
void | disable_buffer () |
Destroy internal buffer. | |
void | enable_buffer () |
Allocate internal buffer. | |
gzfilebuf & | operator= (const gzfilebuf &) |
Private Attributes | |
char_type * | buffer |
Stream buffer. | |
std::streamsize | buffer_size |
Stream buffer size. | |
gzFile | file |
Underlying file pointer. | |
std::ios_base::openmode | io_mode |
Mode in which file was opened. | |
bool | own_buffer |
True if this object owns stream buffer. | |
bool | own_fd |
True if this object owns file descriptor. |
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 52 of file zfstream.h.
gzfilebuf::gzfilebuf | ( | ) |
Definition at line 55 of file zfstream.cc.
References disable_buffer().
|
virtual |
Definition at line 64 of file zfstream.cc.
References close(), disable_buffer(), own_fd, and sync().
|
private |
Attach to already open gzipped file.
fd | File descriptor. |
mode | Open mode flags. |
this
on success, NULL on failure. Definition at line 111 of file zfstream.cc.
References enable_buffer(), file, io_mode, is_open(), open_mode(), and own_fd.
Referenced by gzifstream::attach(), and gzofstream::attach().
Close gzipped file.
this
on success, NULL on failure. Definition at line 138 of file zfstream.cc.
References disable_buffer(), file, is_open(), own_fd, and sync().
Referenced by gzifstream::close(), gzofstream::close(), and ~gzfilebuf().
|
private |
Destroy internal buffer.
This function is safe to call multiple times. It will ensure that the internal buffer is deallocated if it exists. In any case, it will also reset the buffer pointers.
Definition at line 434 of file zfstream.cc.
References buffer, buffer_size, and own_buffer.
Referenced by close(), gzfilebuf(), setbuf(), and ~gzfilebuf().
|
private |
Allocate internal buffer.
This function is safe to call multiple times. It will ensure that a proper internal buffer exists if it is required. If the buffer already exists or is external, the buffer pointers will be reset to their original state.
Definition at line 394 of file zfstream.cc.
References buffer, buffer_size, own_buffer, and SMALLBUFSIZE.
Referenced by attach(), open(), pbackfail(), seekoff(), seekpos(), and setbuf().
Check if file is open.
Definition at line 82 of file zfstream.h.
References file.
Referenced by attach(), close(), gzifstream::is_open(), gzofstream::is_open(), open(), overflow(), pbackfail(), seekoff(), seekpos(), showmanyc(), and underflow().
Open gzipped file.
name | File name. |
mode | Open mode flags. |
this
on success, NULL on failure. Definition at line 84 of file zfstream.cc.
References enable_buffer(), file, io_mode, is_open(), open_mode(), and own_fd.
Referenced by gzifstream::open(), and gzofstream::open().
Convert ios open mode int to mode string used by zlib.
Definition at line 162 of file zfstream.cc.
|
protectedvirtual |
Write put area to gzipped file.
c | Extra character to add to buffer contents. |
This actually writes characters in stream buffer to gzipped file. With unbuffered output this is done one character at a time.
Definition at line 299 of file zfstream.cc.
|
protectedvirtual |
Definition at line 218 of file zfstream.cc.
References buffer, buffer_size, enable_buffer(), file, is_open(), and SEEK_CUR.
|
protectedvirtual |
Alters the stream positions.
Each derived class provides its own appropriate behavior.
Definition at line 462 of file zfstream.cc.
References enable_buffer(), file, io_mode, is_open(), overflow(), SEEK_CUR, SEEK_END, and SEEK_SET.
|
protectedvirtual |
Alters the stream positions.
Each derived class provides its own appropriate behavior.
Definition at line 499 of file zfstream.cc.
References enable_buffer(), file, io_mode, is_open(), overflow(), and SEEK_SET.
|
protectedvirtual |
Installs external stream buffer.
p | Pointer to char buffer. |
n | Size of external buffer. |
this
on success, NULL on failure.Call setbuf(0,0) to enable unbuffered output.
Definition at line 351 of file zfstream.cc.
References buffer, buffer_size, disable_buffer(), enable_buffer(), own_buffer, and sync().
Set compression level and strategy on the fly.
comp_level | Compression level (see zlib.h for allowed values) |
comp_strategy | Compression strategy (see zlib.h for allowed values) |
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 77 of file zfstream.cc.
References file.
|
protectedvirtual |
Number of characters available in stream buffer.
This indicates number of characters in get area of stream buffer. These characters can be read without accessing the gzipped file.
Definition at line 201 of file zfstream.cc.
Flush stream buffer to file.
This calls underflow(EOF) to do the job.
Definition at line 384 of file zfstream.cc.
References overflow().
Referenced by close(), setbuf(), and ~gzfilebuf().
|
protectedvirtual |
Fill get area from gzipped file.
This actually reads characters from gzipped file to stream buffer. Always buffered.
Definition at line 256 of file zfstream.cc.
References buffer, buffer_size, file, io_mode, is_open(), and STASHED_CHARACTERS.
|
private |
Stream buffer.
For simplicity this remains allocated on the free store for the entire life span of the gzfilebuf object, unless replaced by setbuf.
Definition at line 254 of file zfstream.h.
Referenced by disable_buffer(), enable_buffer(), pbackfail(), setbuf(), and underflow().
|
private |
Stream buffer size.
Defaults to system default buffer size (typically 8192 bytes). Modified by setbuf.
Definition at line 262 of file zfstream.h.
Referenced by disable_buffer(), enable_buffer(), pbackfail(), setbuf(), and underflow().
|
private |
Underlying file pointer.
Definition at line 233 of file zfstream.h.
Referenced by attach(), close(), is_open(), open(), overflow(), pbackfail(), seekoff(), seekpos(), setcompression(), and underflow().
|
private |
Mode in which file was opened.
Definition at line 238 of file zfstream.h.
Referenced by attach(), open(), overflow(), seekoff(), seekpos(), showmanyc(), and underflow().
|
private |
True if this object owns stream buffer.
This makes the class responsible for deleting the buffer upon destruction.
Definition at line 270 of file zfstream.h.
Referenced by disable_buffer(), enable_buffer(), and setbuf().
|
private |
True if this object owns file descriptor.
This makes the class responsible for closing the file upon destruction.
Definition at line 246 of file zfstream.h.
Referenced by attach(), close(), open(), and ~gzfilebuf().