BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / IOstreams / gzstream / gzstream.h
blob179fd05cc533e3691e7ef144d06c49eecd670fba
1 // ============================================================================
2 // gzstream, C++ iostream classes wrapping the zlib compression library.
3 // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
4 //
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.
9 //
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 // ============================================================================
20 // File : gzstream.h
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 // ============================================================================
29 #ifndef GZSTREAM_H
30 #define GZSTREAM_H 1
32 // standard C++ with new header file names and std:: namespace
33 #include <iostream>
34 #include <fstream>
35 #include <zlib.h>
37 //#define GZSTREAM_NAMESPACE gzstream
39 #ifdef GZSTREAM_NAMESPACE
40 namespace GZSTREAM_NAMESPACE {
41 #endif
43 // ----------------------------------------------------------------------------
44 // Internal classes to implement gzstream. See below for user classes.
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
48 // class gzstreambuf
49 // ----------------------------------------------------------------------------
51 class gzstreambuf
52 : public std::streambuf
54 private:
56 //------------------------------------
58 static const int bufferSize = 47+256;
59 // totals 512 bytes under g++ for igzstream at the end.
61 //------------------------------------
62 gzFile file;
63 char buffer[bufferSize];
64 char opened;
65 int mode;
68 //------------------------------------
70 int flush_buffer();
72 public:
74 //------------------------------------
76 gzstreambuf()
77 : opened(0)
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
85 ~gzstreambuf()
87 close();
90 //------------------------------------
92 int is_open()
94 return opened;
96 gzstreambuf* open( const char* name, int open_mode );
97 gzstreambuf* close();
98 virtual int overflow( int c = EOF );
99 virtual int underflow();
100 virtual int sync();
103 // ----------------------------------------------------------------------------
104 // class gzstreambase
105 // ----------------------------------------------------------------------------
107 class gzstreambase
108 : virtual public std::ios
110 protected:
112 //------------------------------------
114 gzstreambuf buf;
116 public:
118 //------------------------------------
120 gzstreambase()
122 init(&buf);
124 gzstreambase( const char* _name, int _open_mode );
125 ~gzstreambase();
127 //------------------------------------
129 void open( const char* _name, int _open_mode );
130 void close();
131 gzstreambuf* rdbuf()
133 return &buf;
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 // ----------------------------------------------------------------------------
144 // class igzstream
145 // ----------------------------------------------------------------------------
147 class igzstream
148 : public std::istream
149 , public gzstreambase
151 public:
153 //------------------------------------
155 igzstream()
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 //------------------------------------
166 gzstreambuf* rdbuf()
168 return gzstreambase::rdbuf();
170 void open( const char* _name,
171 int _open_mode = std::ios::in )
173 gzstreambase::open( _name, _open_mode );
177 // ----------------------------------------------------------------------------
178 // class ogzstream
179 // ----------------------------------------------------------------------------
181 class ogzstream
182 : public gzstreambase
183 , public std::ostream
185 public:
187 //------------------------------------
189 ogzstream()
190 : std::ostream( &buf)
192 explicit
193 ogzstream( const char* _name,
194 int _open_mode = std::ios::out )
195 : gzstreambase( _name, _open_mode )
196 , std::ostream( &buf)
199 //------------------------------------
201 gzstreambuf* rdbuf()
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
214 #endif
216 #endif // GZSTREAM_H
217 // ============================================================================
218 // EOF //