3 * A C++ I/O streams interface to the zlib gz* functions.
6 // Written by Bernie Bright, 1998
7 // Based on zlib/contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
9 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Library General Public
13 // License as published by the Free Software Foundation; either
14 // version 2 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Library General Public License for more details.
21 // You should have received a copy of the GNU Library General Public
22 // License along with this library; if not, write to the
23 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 // Boston, MA 02111-1307, USA.
31 #include <simgear/compiler.h>
35 #ifdef SG_HAVE_STD_INCLUDES
40 # define ios_openmode ios_base::openmode
41 # define ios_in ios_base::in
42 # define ios_out ios_base::out
43 # define ios_app ios_base::app
44 # define ios_binary ios_base::binary
46 # define ios_seekdir ios_base::seekdir
48 # define ios_badbit ios_base::badbit
49 # define ios_failbit ios_base::failbit
51 SG_USING_STD(streambuf);
52 SG_USING_STD(ios_base);
53 SG_USING_STD(streampos);
54 SG_USING_STD(streamoff);
58 # ifdef SG_HAVE_STREAMBUF
59 # include <streambuf.h>
62 # include <iostream.h>
65 //# define ios_openmode ios::open_mode
66 # define ios_openmode int
67 # define ios_in ios::in
68 # define ios_out ios::out
69 # define ios_app ios::app
71 #if defined(__GNUC__) && __GNUC_MINOR__ < 8
72 # define ios_binary ios::bin
74 # define ios_binary ios::binary
77 # define ios_seekdir ios::seek_dir
79 # define ios_badbit ios::badbit
80 # define ios_failbit ios::failbit
82 # include <simgear/sg_traits.hxx>
84 #endif // SG_HAVE_STD_INCLUDES
87 * A C++ I/O streams interface to the zlib gz* functions.
89 #ifdef SG_NEED_STREAMBUF_HACK
90 class gzfilebuf : public __streambuf
92 class gzfilebuf : public streambuf
97 #ifndef SG_HAVE_STD_INCLUDES
98 typedef char_traits<char> traits_type;
99 typedef char_traits<char>::int_type int_type;
100 // typedef char_traits<char>::pos_type pos_type;
101 // typedef char_traits<char>::off_type off_type;
108 virtual ~gzfilebuf();
112 * @param name file name
113 * @param io_mode mdoe flags
114 * @return file stream
116 gzfilebuf* open( const char* name, ios_openmode io_mode );
119 * Attach to an existing file descriptor
120 * @param file_descriptor file descriptor
121 * @param io_mode mode flags
122 * @return file stream
124 gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
129 // int setcompressionlevel( int comp_level );
130 // int setcompressionstrategy( int comp_strategy );
132 /** @return true if open, false otherwise */
133 bool is_open() const { return (file != NULL); }
135 /** @return stream position */
136 virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
138 /** sync the stream */
143 virtual int_type underflow();
144 #ifndef SG_HAVE_STD_INCLUDES
145 virtual int_type overflow( int_type c = traits_type::eof() );
147 virtual int_type overflow( int_type c = streambuf::traits_type::eof() );
155 // Convert io_mode to "rwab" string.
156 void cvt_iomode( char* mode_str, ios_openmode io_mode );
162 bool own_file_descriptor;
164 // Get (input) buffer.
168 enum { page_size = 4096 };
172 gzfilebuf( const gzfilebuf& );
173 void operator= ( const gzfilebuf& );
179 struct gzifstream_base
186 #endif // _zfstream_hxx