Fossil SCM

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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button