Ruby: ext/zlib/zlib-1.2.13/contrib/iostream/zfstream.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

zfstream.h
Go to the documentation of this file.
1
2#ifndef zfstream_h
3#define zfstream_h
4
5#include <fstream.h>
6#include "zlib.h"
7
8 class gzfilebuf : public streambuf {
9
10public:
11
12 gzfilebuf( );
13 virtual ~gzfilebuf();
14
15 gzfilebuf *open( const char *name, int io_mode );
16 gzfilebuf *attach( int file_descriptor, int io_mode );
17 gzfilebuf *close();
18
19 int setcompressionlevel( int comp_level );
20 int setcompressionstrategy( int comp_strategy );
21
22 inline int is_open() const { return (file !=NULL); }
23
24 virtual streampos seekoff( streamoff, ios::seek_dir, int );
25
26 virtual int sync();
27
28protected:
29
30 virtual int underflow();
31 virtual int overflow( int = EOF );
32
33private:
34
35 gzFile file;
36 short mode;
37 short own_file_descriptor;
38
39 int flushbuf();
40 int fillbuf();
41
42};
43
44 class gzfilestream_common : virtual public ios {
45
46 friend class gzifstream;
47 friend class gzofstream;
48 friend gzofstream &setcompressionlevel( gzofstream &, int );
49 friend gzofstream &setcompressionstrategy( gzofstream &, int );
50
51public:
52 virtual ~gzfilestream_common();
53
54 void attach( int fd, int io_mode );
55 void open( const char *name, int io_mode );
56 void close();
57
58protected:
59 gzfilestream_common();
60
61private:
62 gzfilebuf *rdbuf();
63
64 gzfilebuf buffer;
65
66};
67
68 class gzifstream : public gzfilestream_common, public istream {
69
70public:
71
72 gzifstream();
73 gzifstream( const char *name, int io_mode = ios::in );
74 gzifstream( int fd, int io_mode = ios::in );
75
76 virtual ~gzifstream();
77
78};
79
80 class gzofstream : public gzfilestream_common, public ostream {
81
82public:
83
84 gzofstream();
85 gzofstream( const char *name, int io_mode = ios::out );
86 gzofstream( int fd, int io_mode = ios::out );
87
88 virtual ~gzofstream();
89
90};
91
92 template<class T> class gzomanip {
93 friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &);
94public:
95 gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { }
96private:
97 gzofstream &(*func)(gzofstream &, T);
98 T val;
99};
100
101 template<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m)
102{
103 return (*m.func)(s, m.val);
104}
105
106 inline gzofstream &setcompressionlevel( gzofstream &s, int l )
107{
108 (s.rdbuf())->setcompressionlevel(l);
109 return s;
110}
111
112 inline gzofstream &setcompressionstrategy( gzofstream &s, int l )
113{
114 (s.rdbuf())->setcompressionstrategy(l);
115 return s;
116}
117
118 inline gzomanip<int> setcompressionlevel(int l)
119{
120 return gzomanip<int>(&setcompressionlevel,l);
121}
122
123 inline gzomanip<int> setcompressionstrategy(int l)
124{
125 return gzomanip<int>(&setcompressionstrategy,l);
126}
127
128#endif
gzfilebuf
Gzipped file stream buffer class.
Definition: zfstream.h:8
gzfilebuf::close
gzfilebuf * close()
gzfilebuf::seekoff
virtual streampos seekoff(streamoff, ios::seek_dir, int)
gzfilebuf::attach
gzfilebuf * attach(int file_descriptor, int io_mode)
gzfilebuf::setcompressionstrategy
int setcompressionstrategy(int comp_strategy)
gzfilebuf::setcompressionlevel
int setcompressionlevel(int comp_level)
gzfilebuf::sync
virtual int sync()
gzfilebuf::overflow
virtual int overflow(int=EOF)
gzfilebuf::gzfilebuf
gzfilebuf()
gzfilebuf::~gzfilebuf
virtual ~gzfilebuf()
gzfilebuf::underflow
virtual int underflow()
gzfilebuf::open
gzfilebuf * open(const char *name, int io_mode)
gzfilebuf::is_open
int is_open() const
Definition: zfstream.h:22
gzfilestream_common
Definition: zfstream.h:44
gzfilestream_common::setcompressionlevel
friend gzofstream & setcompressionlevel(gzofstream &, int)
Definition: zfstream.h:106
gzfilestream_common::attach
void attach(int fd, int io_mode)
gzfilestream_common::open
void open(const char *name, int io_mode)
gzfilestream_common::gzfilestream_common
gzfilestream_common()
gzfilestream_common::close
void close()
gzfilestream_common::~gzfilestream_common
virtual ~gzfilestream_common()
gzfilestream_common::setcompressionstrategy
friend gzofstream & setcompressionstrategy(gzofstream &, int)
Definition: zfstream.h:112
gzifstream
Gzipped file input stream class.
Definition: zfstream.h:68
gzifstream::~gzifstream
virtual ~gzifstream()
gzifstream::gzifstream
gzifstream(const char *name, int io_mode=ios::in)
gzifstream::gzifstream
gzifstream()
gzifstream::gzifstream
gzifstream(int fd, int io_mode=ios::in)
gzofstream
Gzipped file output stream class.
Definition: zfstream.h:80
gzofstream::rdbuf
gzfilebuf * rdbuf() const
Obtain underlying stream buffer.
Definition: zfstream.h:351
gzofstream::gzofstream
gzofstream(int fd, int io_mode=ios::out)
gzofstream::~gzofstream
virtual ~gzofstream()
gzofstream::gzofstream
gzofstream(const char *name, int io_mode=ios::out)
gzofstream::gzofstream
gzofstream()
gzomanip
Definition: zfstream.h:92
gzomanip::gzomanip
gzomanip(gzofstream &(*f)(gzofstream &, T), T v)
Definition: zfstream.h:95
gzomanip::operator<<
friend gzofstream & operator<<(gzofstream &, const gzomanip< T > &)
Definition: zfstream.h:101
T
unsigned char T
Definition: cls_uchar_va.c:10
mode
const char int mode
Definition: ioapi.h:137
setcompressionstrategy
gzofstream & setcompressionstrategy(gzofstream &s, int l)
Definition: zfstream.h:112
setcompressionlevel
gzofstream & setcompressionlevel(gzofstream &s, int l)
Definition: zfstream.h:106
operator<<
gzofstream & operator<<(gzofstream &s, const gzomanip< T > &m)
Definition: zfstream.h:101
name
const char * name
Definition: nkf.c:208
NULL
#define NULL
Definition: regenc.h:69
f
#define f
file
Definition: gzappend.c:170
gzFile_s
Definition: zlib.h:1834
EOF
#define EOF
Definition: vsnprintf.c:203
zlib.h