1 // A C++ I/O streams interface to the zlib gz* functions
3 // Written by Bernie Bright, 1998
4 // Based on zlib/contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
6 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the
20 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 // Boston, MA 02111-1307, USA.
32 #include <simgear/compiler.h>
37 # include <simgear/zlib/zlib.h>
40 // At least Irix needs this
41 #ifdef SG_HAVE_NATIVE_SGI_COMPILERS
42 #include <char_traits.h>
43 SG_USING_STD(char_traits);
46 #ifdef SG_HAVE_STD_INCLUDES
51 # define ios_openmode ios_base::openmode
52 # define ios_in ios_base::in
53 # define ios_out ios_base::out
54 # define ios_app ios_base::app
55 # define ios_binary ios_base::binary
57 # define ios_seekdir ios_base::seekdir
59 # define ios_badbit ios_base::badbit
60 # define ios_failbit ios_base::failbit
62 SG_USING_STD(streambuf);
63 SG_USING_STD(ios_base);
64 SG_USING_STD(streampos);
65 SG_USING_STD(streamoff);
69 # ifdef SG_HAVE_STREAMBUF
70 # include <streambuf.h>
73 # include <iostream.h>
76 //# define ios_openmode ios::open_mode
77 # define ios_openmode int
78 # define ios_in ios::in
79 # define ios_out ios::out
80 # define ios_app ios::app
82 #if defined(__GNUC__) && __GNUC_MINOR__ < 8
83 # define ios_binary ios::bin
84 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
87 # define ios_binary ios::binary
90 # define ios_seekdir ios::seek_dir
92 # define ios_badbit ios::badbit
93 # define ios_failbit ios::failbit
95 # include <simgear/sg_traits.hxx>
97 #endif // SG_HAVE_STD_INCLUDES
99 //-----------------------------------------------------------------------------
103 class gzfilebuf : public streambuf
107 #ifndef SG_HAVE_STD_INCLUDES
108 typedef char_traits<char> traits_type;
109 typedef char_traits<char>::int_type int_type;
110 // typedef char_traits<char>::pos_type pos_type;
111 // typedef char_traits<char>::off_type off_type;
115 virtual ~gzfilebuf();
117 gzfilebuf* open( const char* name, ios_openmode io_mode );
118 gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
121 // int setcompressionlevel( int comp_level );
122 // int setcompressionstrategy( int comp_strategy );
123 bool is_open() const { return (file != NULL); }
124 virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
129 virtual int_type underflow();
130 virtual int_type overflow( int_type c = traits_type::eof() );
137 // Convert io_mode to "rwab" string.
138 void cvt_iomode( char* mode_str, ios_openmode io_mode );
144 bool own_file_descriptor;
146 // Get (input) buffer.
150 enum { page_size = 4096 };
154 gzfilebuf( const gzfilebuf& );
155 void operator= ( const gzfilebuf& );
158 //-----------------------------------------------------------------------------
162 struct gzifstream_base
169 #endif // _zfstream_hxx