Remove building with NOCRYPTO option
[minix.git] / common / dist / zlib / contrib / iostream / zfstream.h
blobdf940e1ae0679f157801c20131cf9fa70ea60cde
1 /* $NetBSD: zfstream.h,v 1.1.1.1 2006/01/14 20:10:53 christos Exp $ */
4 #ifndef zfstream_h
5 #define zfstream_h
7 #include <fstream.h>
8 #include "zlib.h"
10 class gzfilebuf : public streambuf {
12 public:
14 gzfilebuf( );
15 virtual ~gzfilebuf();
17 gzfilebuf *open( const char *name, int io_mode );
18 gzfilebuf *attach( int file_descriptor, int io_mode );
19 gzfilebuf *close();
21 int setcompressionlevel( int comp_level );
22 int setcompressionstrategy( int comp_strategy );
24 inline int is_open() const { return (file !=NULL); }
26 virtual streampos seekoff( streamoff, ios::seek_dir, int );
28 virtual int sync();
30 protected:
32 virtual int underflow();
33 virtual int overflow( int = EOF );
35 private:
37 gzFile file;
38 short mode;
39 short own_file_descriptor;
41 int flushbuf();
42 int fillbuf();
46 class gzfilestream_common : virtual public ios {
48 friend class gzifstream;
49 friend class gzofstream;
50 friend gzofstream &setcompressionlevel( gzofstream &, int );
51 friend gzofstream &setcompressionstrategy( gzofstream &, int );
53 public:
54 virtual ~gzfilestream_common();
56 void attach( int fd, int io_mode );
57 void open( const char *name, int io_mode );
58 void close();
60 protected:
61 gzfilestream_common();
63 private:
64 gzfilebuf *rdbuf();
66 gzfilebuf buffer;
70 class gzifstream : public gzfilestream_common, public istream {
72 public:
74 gzifstream();
75 gzifstream( const char *name, int io_mode = ios::in );
76 gzifstream( int fd, int io_mode = ios::in );
78 virtual ~gzifstream();
82 class gzofstream : public gzfilestream_common, public ostream {
84 public:
86 gzofstream();
87 gzofstream( const char *name, int io_mode = ios::out );
88 gzofstream( int fd, int io_mode = ios::out );
90 virtual ~gzofstream();
94 template<class T> class gzomanip {
95 friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &);
96 public:
97 gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { }
98 private:
99 gzofstream &(*func)(gzofstream &, T);
100 T val;
103 template<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m)
105 return (*m.func)(s, m.val);
108 inline gzofstream &setcompressionlevel( gzofstream &s, int l )
110 (s.rdbuf())->setcompressionlevel(l);
111 return s;
114 inline gzofstream &setcompressionstrategy( gzofstream &s, int l )
116 (s.rdbuf())->setcompressionstrategy(l);
117 return s;
120 inline gzomanip<int> setcompressionlevel(int l)
122 return gzomanip<int>(&setcompressionlevel,l);
125 inline gzomanip<int> setcompressionstrategy(int l)
127 return gzomanip<int>(&setcompressionstrategy,l);
130 #endif