gzstream.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef s11n_GZSTREAM_H_INCLUDED
00034 #define s11n_GZSTREAM_H_INCLUDED 1
00035
00036
00037
00038 #include <iostream>
00039 #include <fstream>
00040 #include <zlib.h>
00041
00042 #ifndef ZSTREAM_NAMESPACE
00043 #define ZSTREAM_NAMESPACE s11n
00044 #endif
00045
00046 #ifdef ZSTREAM_NAMESPACE
00047 namespace ZSTREAM_NAMESPACE
00048 {
00049 #endif
00050
00051
00052
00053
00054 class gzstreambuf:public std::streambuf
00055 {
00056 private:
00057 static const int bufferSize = 47 + 256;
00058
00059
00060 gzFile file;
00061 char buffer[bufferSize];
00062 char opened;
00063 int mode;
00064
00065 int flush_buffer();
00066 public:
00067 gzstreambuf():opened( 0 ), m_zlevel(-1)
00068 {
00069 setp( buffer, buffer + ( bufferSize - 1 ) );
00070 setg( buffer + 4,
00071 buffer + 4,
00072 buffer + 4 );
00073
00074 }
00075 int is_open()
00076 {
00077 return opened;
00078 }
00079 gzstreambuf *open( const char *name, int open_mode );
00080 gzstreambuf *close();
00081 ~gzstreambuf()
00082 {
00083 close();
00084 }
00085
00086 virtual int overflow( int c = EOF );
00087 virtual int underflow();
00088 virtual int sync();
00089
00090 void zlevel( int z ) { this->m_zlevel = ( z<0 ? -1 : (z>9?9:z) ) ; }
00091 int zlevel() const { return this->m_zlevel; }
00092 private:
00093 int m_zlevel;
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 class gzstreambase:virtual public std::ios
00105 {
00106 private:
00107 int m_zlevel;
00108 protected:
00109 gzstreambuf buf;
00110 public:
00111 gzstreambase()
00112 {
00113 init( &buf );
00114 }
00115 gzstreambase( const char *name, int open_mode );
00116 ~gzstreambase();
00117 void open( const char *name, int open_mode );
00118 void close();
00119
00120 void zlevel( int z ) { buf.zlevel(z); }
00121 int zlevel() const { return buf.zlevel(); }
00122
00123 gzstreambuf *rdbuf()
00124 {
00125 return &buf;
00126 }
00127 };
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 class igzstream:public gzstreambase, public std::istream
00139 {
00140 public:
00141 igzstream():std::istream( &buf )
00142 {
00143 }
00144 igzstream( const char *name, int open_mode = std::ios::in ):gzstreambase( name, open_mode ), std::istream( &buf )
00145 {
00146 }
00147 gzstreambuf *rdbuf()
00148 {
00149 return gzstreambase::rdbuf();
00150 }
00151 void open( const char *name, int open_mode = std::ios::in )
00152 {
00153 gzstreambase::open( name, open_mode );
00154 }
00155 };
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 class ogzstream:public gzstreambase, public std::ostream
00166 {
00167 public:
00168 ogzstream():std::ostream( &buf )
00169 {
00170 }
00171 ogzstream( const char *name, int mode = std::ios::out ):gzstreambase( name, mode ), std::ostream( &buf )
00172 {
00173 }
00174 gzstreambuf *rdbuf()
00175 {
00176 return gzstreambase::rdbuf();
00177 }
00178 void open( const char *name, int open_mode = std::ios::out )
00179 {
00180 gzstreambase::open( name, open_mode );
00181 }
00182 };
00183
00184 #ifdef ZSTREAM_NAMESPACE
00185 }
00186 #endif
00187
00188 #endif // s11n_GZSTREAM_H_INCLUDED
00189
00190
Generated on Wed Jul 28 16:04:14 2004 for s11n by
1.3.7