38 #ifdef MOOT_ZLIB_ENABLED 41 #define MOOT_DEFAULT_COMPRESSION Z_DEFAULT_COMPRESSION 74 virtual bool valid(
void) {
75 if (!zfile)
return false;
77 gzerror(zfile,&errnum);
78 return errnum == Z_OK;
82 virtual bool eof(
void) {
return !zfile || gzeof(zfile); };
85 virtual std::string
errmsg(
void) {
87 const char *zerrmsg = zfile ? gzerror(zfile,&errnum) :
"NULL gzFile";
88 return std::string(errnum == Z_OK
90 : (zerrmsg != NULL ? zerrmsg :
"unspecified zlib error"));
100 virtual bool reopen(
void) {
return true; };
103 virtual bool close(
void) { zfile=NULL;
return true; };
114 return zfile ? gzread(zfile, buf, n) : 0;
119 int c = zfile ? gzgetc(zfile) : -1;
120 return c==-1 ? EOF : c;
131 return zfile && gzflush(zfile, Z_SYNC_FLUSH) == Z_OK;
135 virtual bool write(
const char *buf,
size_t n) {
136 return zfile ? (gzwrite(zfile,buf,n) ==
static_cast<int>(n)) :
false;
140 virtual bool putbyte(
unsigned char c) {
141 return zfile ? (gzputc(zfile,c) != -1) :
false;
145 virtual bool puts(
const char *s) {
146 return zfile ? (gzputs(zfile,s) >= 0) :
false;
149 virtual bool puts(
const std::string &s) {
151 ? (gzwrite(zfile,s.data(),s.size()) == static_cast<int>(s.size()))
176 std::string default_mode;
191 const char *open_mode=NULL)
194 open(filename,open_mode);
208 inline bool open(
const char *filename,
const char *open_mode=NULL) {
210 if (open_mode) mode = open_mode;
215 inline bool open(
const std::string &filename,
const std::string &open_mode=
"") {
222 virtual bool reopen(
void) {
224 if (mode.empty()) mode = default_mode;
227 if (mode.find(
'w') != mode.npos) zfile = gzdopen(fileno(stdout), mode.c_str());
228 else zfile = gzdopen(fileno(stdin), mode.c_str());
230 zfile = gzopen(
name.c_str(), mode.c_str());
236 virtual bool close(
void) {
237 if (!zfile)
return true;
238 bool rc = gzclose(zfile) == Z_OK;
250 inline void setparams(
int level=Z_DEFAULT_COMPRESSION,
251 int strategy=Z_DEFAULT_STRATEGY)
253 if (level != Z_DEFAULT_COMPRESSION
254 && (level > Z_BEST_COMPRESSION || level < Z_NO_COMPRESSION))
256 level = Z_DEFAULT_COMPRESSION;
258 if (zfile) gzsetparams(zfile, level, strategy);
285 mizfstream(
const char *filename,
const char *mode=NULL)
292 mizfstream(
const std::string &filename,
const std::string &mode=
"")
324 mozfstream(
const char *filename,
const char *mode=NULL) {
330 mozfstream(
const std::string &filename,
const std::string &mode=
"") {
342 #else // _MOOT_ZLIB_ENABLED 346 #define MOOT_DEFAULT_COMPRESSION -1 357 #endif // _MOOT_ZLIB_ENABLED mzstream mizstream
Alias for gzFile input stream wrappers.
Definition: mootZIO.h:404
virtual bool flush(void)
Definition: mootZIO.h:156
virtual bool reopen(void)
Definition: mootZIO.h:110
virtual bool putbyte(unsigned char c)
Definition: mootZIO.h:170
mootio abstraction layer for C FILE*s
virtual int getbyte(void)
Definition: mootZIO.h:130
~mzstream(void)
Definition: mootZIO.h:67
Wrapper class for named file i/o using C FILE*s.
Definition: mootCIO.h:175
gzFile zfile
underlying gzFile
Definition: mootZIO.h:54
virtual bool puts(const char *s)
Definition: mootZIO.h:175
Wrapper class for named file input using C FILE*s.
Definition: mootCIO.h:286
Abstract base class for output stream wrappers.
Definition: mootIO.h:194
virtual ByteCount read(char *buf, size_t n)
Definition: mootZIO.h:125
mzstream mozstream
Alias for gzFile output stream wrappers.
Definition: mootZIO.h:405
std::string name
symbolic name of this stream
Definition: mootIO.h:82
Wrapper class for named file output using gzFile.
Definition: mootZIO.h:367
Wrapper class for named file input using gzFile.
Definition: mootZIO.h:326
Wrapper class for named file output using C FILE*s.
Definition: mootCIO.h:327
virtual bool eof(void)
Definition: mootZIO.h:86
Namespace for I/O stream wrappers.
Definition: mootBufferIO.h:45
virtual bool close(void)
Definition: mootZIO.h:113
generic I/O abstraction layer
virtual bool write(const char *buf, size_t n)
Definition: mootZIO.h:165
Wrapper class for C FILE* streams.
Definition: mootCIO.h:54
Wrapper class for C FILE* streams.
Definition: mootZIO.h:49
int ByteCount
typedef for byte counts (should be signed, for compatibility)
Definition: mootIO.h:52
virtual bool valid(void)
Definition: mootZIO.h:76
virtual std::string errmsg(void)
Definition: mootZIO.h:89
Wrapper class for named file i/o using gzFile.
Definition: mootZIO.h:203
Abstract base class for input stream wrappers.
Definition: mootIO.h:129
mzstream(gzFile zf=__null)
Definition: mootZIO.h:62