1 // ============================================================================
2 // gzstream, C++ iostream classes wrapping the zlib compression library.
3 // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // ============================================================================
21 // Revision : $Revision: 1.8 $
22 // Revision_date : $Date: 2005/11/09 13:53:50 $
23 // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
25 // Standard streambuf implementation following Nicolai Josuttis,
26 // "The Standard C++ Library".
27 // ============================================================================
32 // standard C++ with new header file names and std:: namespace
37 //#define GZSTREAM_NAMESPACE gzstream
39 #ifdef GZSTREAM_NAMESPACE
40 namespace GZSTREAM_NAMESPACE
{
43 // ----------------------------------------------------------------------------
44 // Internal classes to implement gzstream. See below for user classes.
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
52 : public std::streambuf
56 //------------------------------------
58 static const int bufferSize
= 47+256;
59 // totals 512 bytes under g++ for igzstream at the end.
61 //------------------------------------
63 char buffer
[bufferSize
];
68 //------------------------------------
74 //------------------------------------
79 setp( buffer
, buffer
+ (bufferSize
-1));
80 setg( buffer
+ 4, // beginning of putback area
81 buffer
+ 4, // read position
82 buffer
+ 4); // end position
83 // ASSERT: both input & output capabilities will not be used together
90 //------------------------------------
96 gzstreambuf
* open( const char* name
, int open_mode
);
98 virtual int overflow( int c
= EOF
);
99 virtual int underflow();
103 // ----------------------------------------------------------------------------
104 // class gzstreambase
105 // ----------------------------------------------------------------------------
108 : virtual public std::ios
112 //------------------------------------
118 //------------------------------------
124 gzstreambase( const char* _name
, int _open_mode
);
127 //------------------------------------
129 void open( const char* _name
, int _open_mode
);
137 // ----------------------------------------------------------------------------
138 // User classes. Use igzstream and ogzstream analogously to ifstream and
139 // ofstream respectively. They read and write files based on the gz*
140 // function interface of the zlib. Files are compatible with gzip compression.
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
148 : public std::istream
149 , public gzstreambase
153 //------------------------------------
156 : std::istream( &buf
)
158 igzstream( const char* _name
,
159 int _open_mode
= std::ios::in
)
160 : std::istream( &buf
)
161 , gzstreambase( _name
, _open_mode
)
164 //------------------------------------
168 return gzstreambase::rdbuf();
170 void open( const char* _name
,
171 int _open_mode
= std::ios::in
)
173 gzstreambase::open( _name
, _open_mode
);
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
182 : public gzstreambase
183 , public std::ostream
187 //------------------------------------
190 : std::ostream( &buf
)
193 ogzstream( const char* _name
,
194 int _open_mode
= std::ios::out
)
195 : gzstreambase( _name
, _open_mode
)
196 , std::ostream( &buf
)
199 //------------------------------------
203 return gzstreambase::rdbuf();
205 void open( const char* _name
,
206 int _open_mode
= std::ios::out
)
208 gzstreambase::open( _name
, _open_mode
);
212 #ifdef GZSTREAM_NAMESPACE
213 } // namespace GZSTREAM_NAMESPACE
217 // ============================================================================