kusano fc6ab3
kusano fc6ab3
#ifndef zfstream_h
kusano fc6ab3
#define zfstream_h
kusano fc6ab3
kusano fc6ab3
#include <fstream.h></fstream.h>
kusano fc6ab3
#include "zlib.h"
kusano fc6ab3
kusano fc6ab3
class gzfilebuf : public streambuf {
kusano fc6ab3
kusano fc6ab3
public:
kusano fc6ab3
kusano fc6ab3
  gzfilebuf( );
kusano fc6ab3
  virtual ~gzfilebuf();
kusano fc6ab3
kusano fc6ab3
  gzfilebuf *open( const char *name, int io_mode );
kusano fc6ab3
  gzfilebuf *attach( int file_descriptor, int io_mode );
kusano fc6ab3
  gzfilebuf *close();
kusano fc6ab3
kusano fc6ab3
  int setcompressionlevel( int comp_level );
kusano fc6ab3
  int setcompressionstrategy( int comp_strategy );
kusano fc6ab3
kusano fc6ab3
  inline int is_open() const { return (file !=NULL); }
kusano fc6ab3
kusano fc6ab3
  virtual streampos seekoff( streamoff, ios::seek_dir, int );
kusano fc6ab3
kusano fc6ab3
  virtual int sync();
kusano fc6ab3
kusano fc6ab3
protected:
kusano fc6ab3
kusano fc6ab3
  virtual int underflow();
kusano fc6ab3
  virtual int overflow( int = EOF );
kusano fc6ab3
kusano fc6ab3
private:
kusano fc6ab3
kusano fc6ab3
  gzFile file;
kusano fc6ab3
  short mode;
kusano fc6ab3
  short own_file_descriptor;
kusano fc6ab3
kusano fc6ab3
  int flushbuf();
kusano fc6ab3
  int fillbuf();
kusano fc6ab3
kusano fc6ab3
};
kusano fc6ab3
kusano fc6ab3
class gzfilestream_common : virtual public ios {
kusano fc6ab3
kusano fc6ab3
  friend class gzifstream;
kusano fc6ab3
  friend class gzofstream;
kusano fc6ab3
  friend gzofstream &setcompressionlevel( gzofstream &, int );
kusano fc6ab3
  friend gzofstream &setcompressionstrategy( gzofstream &, int );
kusano fc6ab3
kusano fc6ab3
public:
kusano fc6ab3
  virtual ~gzfilestream_common();
kusano fc6ab3
kusano fc6ab3
  void attach( int fd, int io_mode );
kusano fc6ab3
  void open( const char *name, int io_mode );
kusano fc6ab3
  void close();
kusano fc6ab3
kusano fc6ab3
protected:
kusano fc6ab3
  gzfilestream_common();
kusano fc6ab3
kusano fc6ab3
private:
kusano fc6ab3
  gzfilebuf *rdbuf();
kusano fc6ab3
kusano fc6ab3
  gzfilebuf buffer;
kusano fc6ab3
kusano fc6ab3
};
kusano fc6ab3
kusano fc6ab3
class gzifstream : public gzfilestream_common, public istream {
kusano fc6ab3
kusano fc6ab3
public:
kusano fc6ab3
kusano fc6ab3
  gzifstream();
kusano fc6ab3
  gzifstream( const char *name, int io_mode = ios::in );
kusano fc6ab3
  gzifstream( int fd, int io_mode = ios::in );
kusano fc6ab3
kusano fc6ab3
  virtual ~gzifstream();
kusano fc6ab3
kusano fc6ab3
};
kusano fc6ab3
kusano fc6ab3
class gzofstream : public gzfilestream_common, public ostream {
kusano fc6ab3
kusano fc6ab3
public:
kusano fc6ab3
kusano fc6ab3
  gzofstream();
kusano fc6ab3
  gzofstream( const char *name, int io_mode = ios::out );
kusano fc6ab3
  gzofstream( int fd, int io_mode = ios::out );
kusano fc6ab3
kusano fc6ab3
  virtual ~gzofstream();
kusano fc6ab3
kusano fc6ab3
};
kusano fc6ab3
kusano fc6ab3
template<class t=""> class gzomanip {</class>
kusano fc6ab3
  friend gzofstream &operator<<(gzofstream &, const gzomanip<t> &);</t>
kusano fc6ab3
public:
kusano fc6ab3
  gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { }
kusano fc6ab3
private:
kusano fc6ab3
  gzofstream &(*func)(gzofstream &, T);
kusano fc6ab3
  T val;
kusano fc6ab3
};
kusano fc6ab3
kusano fc6ab3
template<class t=""> gzofstream &operator<<(gzofstream &s, const gzomanip<t> &m)</t></class>
kusano fc6ab3
{
kusano fc6ab3
  return (*m.func)(s, m.val);
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
inline gzofstream &setcompressionlevel( gzofstream &s, int l )
kusano fc6ab3
{
kusano fc6ab3
  (s.rdbuf())->setcompressionlevel(l);
kusano fc6ab3
  return s;
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
inline gzofstream &setcompressionstrategy( gzofstream &s, int l )
kusano fc6ab3
{
kusano fc6ab3
  (s.rdbuf())->setcompressionstrategy(l);
kusano fc6ab3
  return s;
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
inline gzomanip<int> setcompressionlevel(int l)</int>
kusano fc6ab3
{
kusano fc6ab3
  return gzomanip<int>(&setcompressionlevel,l);</int>
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
inline gzomanip<int> setcompressionstrategy(int l)</int>
kusano fc6ab3
{
kusano fc6ab3
  return gzomanip<int>(&setcompressionstrategy,l);</int>
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
#endif