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 #ifndef FILEOPS_H_
00029 #define FILEOPS_H_
00030
00031 #include <zlib.h>
00032 #include <string>
00033 #include "types.h"
00034
00035
00036 #ifndef SWIG
00037 using namespace std;
00038 #endif
00039
00040
00041
00042
00043
00044
00045 typedef enum { READ, WRITE } gz_type;
00046
00047
00048
00049
00050
00051
00052 class gz_file
00053 {
00054 public:
00055
00056
00057
00058
00059 gz_file ();
00060
00061 #ifndef SWIG
00062
00063
00064
00065
00066
00067
00068 gz_file (const string & fname, gz_type t);
00069 #endif
00070
00071
00072
00073
00074
00075 virtual ~gz_file ();
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 bool open (const string & fname, gz_type t);
00086
00087
00088
00089
00090
00091 void close ();
00092
00093
00094
00095
00096
00097
00098
00099 bool is_open () { return opened; }
00100
00101
00102
00103
00104
00105
00106
00107 bool eof ()
00108 {
00109 return gzeof (file);
00110 }
00111
00112 protected:
00113
00114
00115
00116
00117 gzFile file;
00118
00119 private:
00120
00121 gz_file (gz_file& src);
00122
00123
00124 bool opened;
00125 };
00126
00127
00128
00129
00130
00131 class igzstream : public gz_file
00132 {
00133 public:
00134
00135
00136
00137
00138 igzstream ();
00139
00140 #ifndef SWIG
00141
00142
00143
00144
00145
00146
00147 igzstream (const string & fname);
00148 #endif
00149
00150
00151
00152
00153
00154 ~igzstream ();
00155
00156
00157
00158
00159
00160
00161
00162
00163 bool open (const string & fname);
00164
00165
00166
00167
00168
00169
00170
00171 void get_block (void * to, u_int32 size);
00172
00173 #ifndef SWIG
00174
00175 friend bool& operator << (bool& n, igzstream& gfile);
00176
00177
00178 friend char& operator << (char& n, igzstream& gfile);
00179
00180
00181 friend u_int8& operator << (u_int8& n, igzstream& gfile);
00182
00183
00184 friend s_int8& operator << (s_int8& n, igzstream& gfile);
00185
00186
00187 friend u_int16& operator << (u_int16& n, igzstream& gfile);
00188
00189
00190 friend s_int16& operator << (s_int16& n, igzstream& gfile);
00191
00192
00193 friend u_int32& operator << (u_int32& n, igzstream& gfile);
00194
00195
00196 friend s_int32& operator << (s_int32& n, igzstream& gfile);
00197
00198
00199 friend string& operator << (string& s, igzstream& gfile);
00200
00201
00202 friend float& operator << (float& s, igzstream& gfile);
00203 #endif
00204
00205 bool get_bool ();
00206 u_int8 get_uint8 ();
00207 s_int8 get_sint8 ();
00208 u_int16 get_uint16 ();
00209 s_int16 get_sint16 ();
00210 u_int32 get_uint32 ();
00211 s_int32 get_sint32 ();
00212 string get_string ();
00213 float get_float ();
00214
00215 private:
00216
00217 igzstream (igzstream& src);
00218 };
00219
00220
00221
00222
00223 class ogzstream : public gz_file
00224 {
00225 public:
00226
00227
00228
00229
00230 ogzstream ();
00231
00232 #ifndef SWIG
00233
00234
00235
00236
00237
00238
00239 ogzstream (const string & fname);
00240 #endif
00241
00242
00243
00244
00245
00246 ~ogzstream ();
00247
00248
00249
00250
00251
00252
00253
00254
00255 bool open (const string & fname);
00256
00257
00258
00259
00260
00261
00262
00263 void put_block (void * to, u_int32 size);
00264
00265 #ifndef SWIG
00266
00267 friend const bool& operator >> (const bool& n, ogzstream& gfile);
00268
00269
00270 friend const char& operator >> (const char& n, ogzstream& gfile);
00271
00272
00273 friend const u_int8& operator >> (const u_int8& n, ogzstream& gfile);
00274
00275
00276 friend const s_int8& operator >> (const s_int8& n, ogzstream& gfile);
00277
00278
00279 friend const u_int16& operator >> (const u_int16& n, ogzstream& gfile);
00280
00281
00282 friend const s_int16& operator >> (const s_int16& n, ogzstream& gfile);
00283
00284
00285 friend const u_int32& operator >> (const u_int32& n, ogzstream& gfile);
00286
00287
00288 friend const s_int32& operator >> (const s_int32& n, ogzstream& gfile);
00289
00290
00291 friend string& operator >> (const string& s, ogzstream& gfile);
00292
00293
00294 friend const float& operator >> (const float& s, ogzstream& gfile);
00295 #endif
00296
00297 void put_bool (const bool &n) { n >> *this; }
00298 void put_uint8 (const u_int8 &n) { n >> *this; }
00299 void put_sint8 (const s_int8 &n) { n >> *this; }
00300 void put_uint16 (const u_int16 &n) { n >> *this; }
00301 void put_sint16 (const s_int16 &n) { n >> *this; }
00302 void put_uint32 (const u_int32 &n) { n >> *this; }
00303 void put_sint32 (const s_int32 &n) { n >> *this; }
00304 void put_string (const string& s) { s >> *this; }
00305 void put_float (const float &n) { n >> *this; }
00306
00307 private:
00308
00309 ogzstream (ogzstream& src);
00310 };
00311
00312
00313 class fileops
00314 {
00315 public:
00316
00317
00318
00319
00320
00321
00322 static void put_version (ogzstream& file, u_int16 version);
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 static bool get_version (igzstream& file, u_int16 min, u_int16 max, string name);
00335 };
00336
00337
00338 #endif // __FILEOPS_H__