19e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
29e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project#ifndef zfstream_h
39e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project#define zfstream_h
49e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
59e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project#include <fstream.h>
69e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project#include "zlib.h"
79e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
89e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectclass gzfilebuf : public streambuf {
99e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
109e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectpublic:
119e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
129e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilebuf( );
139e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual ~gzfilebuf();
149e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
159e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilebuf *open( const char *name, int io_mode );
169e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilebuf *attach( int file_descriptor, int io_mode );
179e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilebuf *close();
189e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
199e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  int setcompressionlevel( int comp_level );
209e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  int setcompressionstrategy( int comp_strategy );
219e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
229e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  inline int is_open() const { return (file !=NULL); }
239e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
249e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual streampos seekoff( streamoff, ios::seek_dir, int );
259e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
269e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual int sync();
279e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
289e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectprotected:
299e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
309e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual int underflow();
319e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual int overflow( int = EOF );
329e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
339e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectprivate:
349e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
359e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzFile file;
369e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  short mode;
379e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  short own_file_descriptor;
389e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
399e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  int flushbuf();
409e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  int fillbuf();
419e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
429e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project};
439e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
449e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectclass gzfilestream_common : virtual public ios {
459e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
469e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  friend class gzifstream;
479e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  friend class gzofstream;
489e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  friend gzofstream &setcompressionlevel( gzofstream &, int );
499e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  friend gzofstream &setcompressionstrategy( gzofstream &, int );
509e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
519e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectpublic:
529e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual ~gzfilestream_common();
539e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
549e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  void attach( int fd, int io_mode );
559e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  void open( const char *name, int io_mode );
569e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  void close();
579e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
589e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectprotected:
599e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilestream_common();
609e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
619e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectprivate:
629e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilebuf *rdbuf();
639e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
649e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzfilebuf buffer;
659e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
669e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project};
679e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
689e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectclass gzifstream : public gzfilestream_common, public istream {
699e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
709e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectpublic:
719e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
729e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzifstream();
739e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzifstream( const char *name, int io_mode = ios::in );
749e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzifstream( int fd, int io_mode = ios::in );
759e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
769e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual ~gzifstream();
779e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
789e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project};
799e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
809e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectclass gzofstream : public gzfilestream_common, public ostream {
819e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
829e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectpublic:
839e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
849e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzofstream();
859e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzofstream( const char *name, int io_mode = ios::out );
869e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzofstream( int fd, int io_mode = ios::out );
879e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
889e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  virtual ~gzofstream();
899e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
909e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project};
919e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
929e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projecttemplate<class T> class gzomanip {
939e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &);
949e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectpublic:
959e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { }
969e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectprivate:
979e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  gzofstream &(*func)(gzofstream &, T);
989e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  T val;
999e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project};
1009e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
1019e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projecttemplate<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m)
1029e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project{
1039e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  return (*m.func)(s, m.val);
1049e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project}
1059e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
1069e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectinline gzofstream &setcompressionlevel( gzofstream &s, int l )
1079e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project{
1089e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  (s.rdbuf())->setcompressionlevel(l);
1099e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  return s;
1109e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project}
1119e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
1129e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectinline gzofstream &setcompressionstrategy( gzofstream &s, int l )
1139e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project{
1149e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  (s.rdbuf())->setcompressionstrategy(l);
1159e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  return s;
1169e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project}
1179e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
1189e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectinline gzomanip<int> setcompressionlevel(int l)
1199e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project{
1209e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  return gzomanip<int>(&setcompressionlevel,l);
1219e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project}
1229e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
1239e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Projectinline gzomanip<int> setcompressionstrategy(int l)
1249e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project{
1259e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project  return gzomanip<int>(&setcompressionstrategy,l);
1269e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project}
1279e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project
1289e38dfa2f95fce609707a0941f10af9a785288deThe Android Open Source Project#endif
129