]> git.mxchange.org Git - simgear.git/blob - Lib/Misc/zfstream.hxx
Fixed an IRIX warning message where an inline function is referenced
[simgear.git] / Lib / 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
24 #ifndef _zfstream_hxx
25 #define _zfstream_hxx
26
27 #include "zlib/zlib.h"
28 #include "Include/compiler.h"
29
30 #ifdef FG_HAVE_STD_INCLUDES
31
32 #  include <streambuf>
33 #  include <istream>
34
35 #  define ios_openmode ios_base::openmode
36 #  define ios_in       ios_base::in
37 #  define ios_out      ios_base::out
38 #  define ios_app      ios_base::app
39 #  define ios_binary   ios_base::binary
40
41 #  define ios_seekdir  ios_base::seekdir
42
43 #  define ios_badbit   ios_base::badbit
44 #  define ios_failbit  ios_base::failbit
45
46 FG_USING_STD(streambuf);
47 FG_USING_STD(ios_base);
48 FG_USING_STD(streampos);
49 FG_USING_STD(streamoff);
50
51 #else
52
53 #  ifdef FG_HAVE_STREAMBUF
54 #    include <streambuf.h>
55 #    include <istream.h>
56 #  else
57 #    include <iostream.h>
58 #  endif
59
60 //#  define ios_openmode ios::open_mode
61 #  define ios_openmode int
62 #  define ios_in       ios::in
63 #  define ios_out      ios::out
64 #  define ios_app      ios::app
65
66 #if defined(__GNUC__) && __GNUC_MINOR__ < 8
67 #  define ios_binary   ios::bin
68 #elif defined( FG_HAVE_NATIVE_SGI_COMPILERS )
69 #  define ios_binary   0
70 #else
71 #  define ios_binary   ios::binary
72 #endif
73
74 #  define ios_seekdir  ios::seek_dir
75
76 #  define ios_badbit   ios::badbit
77 #  define ios_failbit  ios::failbit
78
79 #  include "Include/fg_traits.hxx"
80
81 #endif // FG_HAVE_STD_INCLUDES
82
83 //-----------------------------------------------------------------------------
84 //
85 //
86 //
87 class gzfilebuf : public streambuf
88 {
89 public:
90
91 #ifndef FG_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;
96 #endif
97
98     gzfilebuf();
99     virtual ~gzfilebuf();
100
101     gzfilebuf* open( const char* name, ios_openmode io_mode );
102     gzfilebuf* attach( int file_descriptor, ios_openmode io_mode );
103     gzfilebuf* close();
104
105 //     int setcompressionlevel( int comp_level );
106 //     int setcompressionstrategy( int comp_strategy );
107     bool is_open() const { return (file != NULL); }
108     virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
109     virtual int sync();
110
111 protected:
112
113     virtual int_type underflow();
114     virtual int_type overflow( int_type c = traits_type::eof() );
115
116 private:
117
118     int_type flushbuf();
119     int fillbuf();
120
121     // Convert io_mode to "rwab" string.
122     void cvt_iomode( char* mode_str, ios_openmode io_mode );
123
124 private:
125
126     gzFile file;
127     ios_openmode mode;
128     bool own_file_descriptor;
129
130     // Get (input) buffer.
131     int ibuf_size;
132     char* ibuffer;
133
134     enum { page_size = 4096 };
135
136 private:
137     // Not defined
138     gzfilebuf( const gzfilebuf& );
139     void operator= ( const gzfilebuf& );
140 };
141
142 //-----------------------------------------------------------------------------
143 //
144 // 
145 //
146 struct gzifstream_base
147 {
148     gzifstream_base() {}
149
150     gzfilebuf gzbuf;
151 };
152
153 #endif // _zfstream_hxx
154