]> git.mxchange.org Git - simgear.git/blob - Misc/zfstream.hxx
Removed gpc from Libs since this is not "free ware" and the author has
[simgear.git] / Misc / zfstream.hxx
1 //  A C++ I/O streams interface to the zlib gz* functions
2 //
3 // Written by Bernie Bright, 1998
4 // Based on zlib/contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
5 //
6 // Copyright (C) 1998  Bernie Bright - bbright@c031.aone.net.au
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25 #ifndef _zfstream_hxx
26 #define _zfstream_hxx
27
28 #include "zlib/zlib.h"
29 #include "Include/compiler.h"
30
31 #ifdef FG_HAVE_STD_INCLUDES
32
33 #  include <streambuf>
34 #  include <istream>
35
36 #  define ios_openmode ios_base::openmode
37 #  define ios_in       ios_base::in
38 #  define ios_out      ios_base::out
39 #  define ios_app      ios_base::app
40 #  define ios_binary   ios_base::binary
41
42 #  define ios_seekdir  ios_base::seekdir
43
44 #  define ios_badbit   ios_base::badbit
45 #  define ios_failbit  ios_base::failbit
46
47 #else
48
49 #  ifdef FG_HAVE_STREAMBUF
50 #    include <streambuf.h>
51 #    include <istream.h>
52 #  else
53 #    include <iostream.h>
54 #  endif
55
56 //#  define ios_openmode ios::open_mode
57 #  define ios_openmode int
58 #  define ios_in       ios::in
59 #  define ios_out      ios::out
60 #  define ios_app      ios::app
61
62 #if defined(__GNUC__) && __GNUC_MINOR__ < 8
63 #  define ios_binary   ios::bin
64 #else
65 #  define ios_binary   ios::binary
66 #endif
67
68 #  define ios_seekdir  ios::seek_dir
69
70 #  define ios_badbit   ios::badbit
71 #  define ios_failbit  ios::failbit
72
73 #  include "Include/fg_traits.hxx"
74
75 #endif // FG_HAVE_STD_INCLUDES
76
77 //-----------------------------------------------------------------------------
78 //
79 //
80 //
81 class gzfilebuf : public streambuf
82 {
83 public:
84
85 #ifndef FG_HAVE_STD_INCLUDES
86     typedef char_traits<char>           traits_type;
87     typedef char_traits<char>::int_type int_type;
88     typedef char_traits<char>::pos_type pos_type;
89     typedef char_traits<char>::off_type off_type;
90 #endif
91
92     gzfilebuf();
93     virtual ~gzfilebuf();
94
95     gzfilebuf* open( const char* name, ios_openmode io_mode );
96     gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
97     gzfilebuf* close();
98
99 //     int setcompressionlevel( int comp_level );
100 //     int setcompressionstrategy( int comp_strategy );
101     bool is_open() const { return (file != NULL); }
102     virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
103     virtual int sync();
104
105 protected:
106
107     virtual int_type underflow();
108     virtual int_type overflow( int_type c = traits_type::eof() );
109
110 private:
111
112     int_type flushbuf();
113     int fillbuf();
114
115     // Convert io_mode to "rwab" string.
116     void cvt_iomode( char* mode_str, ios_openmode io_mode );
117
118 private:
119
120     gzFile file;
121     ios_openmode mode;
122     bool own_file_descriptor;
123
124     // Get (input) buffer.
125     int ibuf_size;
126     char* ibuffer;
127
128     static const int page_size = 4096;
129
130 private:
131     // Not defined
132     gzfilebuf( const gzfilebuf& );
133     void operator= ( const gzfilebuf& );
134 };
135
136 //-----------------------------------------------------------------------------
137 //
138 // 
139 //
140 struct gzifstream_base
141 {
142     gzifstream_base() {}
143
144     gzfilebuf gzbuf;
145 };
146
147 #endif // _zfstream_hxx
148
149 // $Log$
150 // Revision 1.6  1998/12/07 21:10:26  curt
151 // Portability improvements.
152 //
153 // Revision 1.5  1998/11/06 21:17:29  curt
154 // Converted to new logstream debugging facility.  This allows release
155 // builds with no messages at all (and no performance impact) by using
156 // the -DFG_NDEBUG flag.
157 //
158 // Revision 1.4  1998/11/06 14:05:16  curt
159 // More portability improvements by Bernie Bright.
160 //
161