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 General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/compiler.h>
34 #ifdef SG_HAVE_STD_INCLUDES
39 # define ios_openmode std::ios_base::openmode
40 # define ios_in std::ios_base::in
41 # define ios_out std::ios_base::out
42 # define ios_app std::ios_base::app
43 # define ios_binary std::ios_base::binary
45 # define ios_seekdir std::ios_base::seekdir
47 # define ios_badbit std::ios_base::badbit
48 # define ios_failbit std::ios_base::failbit
52 # ifdef SG_HAVE_STREAMBUF
53 # include <streambuf.h>
56 # include <iostream.h>
59 //# define ios_openmode ios::open_mode
60 # define ios_openmode int
61 # define ios_in ios::in
62 # define ios_out ios::out
63 # define ios_app ios::app
65 #if defined(__GNUC__) && __GNUC_MINOR__ < 8
66 # define ios_binary ios::bin
68 # define ios_binary ios::binary
71 # define ios_seekdir ios::seek_dir
73 # define ios_badbit ios::badbit
74 # define ios_failbit ios::failbit
76 # include <simgear/sg_traits.hxx>
78 #endif // SG_HAVE_STD_INCLUDES
81 * A C++ I/O streams interface to the zlib gz* functions.
83 #ifdef SG_NEED_STREAMBUF_HACK
84 class gzfilebuf : public __streambuf
86 class gzfilebuf : public std::streambuf
91 #ifndef SG_HAVE_STD_INCLUDES
92 typedef char_traits<char> traits_type;
93 typedef char_traits<char>::int_type int_type;
94 // typedef char_traits<char>::pos_type pos_type;
95 // typedef char_traits<char>::off_type off_type;
102 virtual ~gzfilebuf();
106 * @param name file name
107 * @param io_mode mdoe flags
108 * @return file stream
110 gzfilebuf* open( const char* name, ios_openmode io_mode );
113 * Attach to an existing file descriptor
114 * @param file_descriptor file descriptor
115 * @param io_mode mode flags
116 * @return file stream
118 gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
123 // int setcompressionlevel( int comp_level );
124 // int setcompressionstrategy( int comp_strategy );
126 /** @return true if open, false otherwise */
127 bool is_open() const { return (file != NULL); }
129 /** @return stream position */
130 virtual std::streampos seekoff( std::streamoff off, ios_seekdir way, int which );
132 /** sync the stream */
137 virtual int_type underflow();
138 #ifndef SG_HAVE_STD_INCLUDES
139 virtual int_type overflow( int_type c = traits_type::eof() );
141 virtual int_type overflow( int_type c = std::streambuf::traits_type::eof() );
149 // Convert io_mode to "rwab" string.
150 void cvt_iomode( char* mode_str, ios_openmode io_mode );
156 bool own_file_descriptor;
158 // Get (input) buffer.
162 enum { page_size = 4096 };
166 gzfilebuf( const gzfilebuf& );
167 void operator= ( const gzfilebuf& );
173 struct gzifstream_base
180 #endif // _zfstream_hxx