ZStream.h
1/*
2 * Copyright (C) 2015 Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 * MA 02110-1301 USA
28 */
29
30#ifndef Pt_ZStream_h
31#define Pt_ZStream_h
32
33#include <Pt/Api.h>
34#include <Pt/IOStream.h>
35#include <Pt/ZBuffer.h>
36
37namespace Pt {
38
49class ZIStream : public BasicIStream<char>
50{
51 public:
55
58 ZIStream(Format fmt = Format::Zlib)
59 : BasicIStream<char>(0)
60 , _buffer(fmt)
61 {
62 this->setBuffer(&_buffer);
63 }
64
67 explicit ZIStream(std::istream& is, Format fmt = Format::Zlib)
68 : BasicIStream<char>(0)
69 , _buffer(is, fmt)
70 {
71 this->setBuffer(&_buffer);
72 }
73
76 {}
77
81 { return _buffer; }
82
85 void attach(std::istream& is)
86 {
87 _buffer.attach(is);
88 }
89
92 void detach()
93 {
94 _buffer.detach();
95 }
96
99 void reset()
100 {
101 _buffer.reset();
102 }
103
106 void reset(std::istream& is)
107 {
108 _buffer.reset(is);
109 }
110
113 void finish()
114 {
115 _buffer.finish();
116 }
117
120 std::size_t zcount() const
121 { return _buffer.zcount(); }
122
123 private:
124 ZBuffer _buffer;
125};
126
137class ZOStream : public BasicOStream<char>
138{
139 public:
143
146 ZOStream(Format fmt = Format::Zlib)
147 : BasicOStream<char>(0)
148 , _buffer(fmt)
149 {
150 this->setBuffer(&_buffer);
151 }
152
155 explicit ZOStream(std::ostream& os, Format fmt = Format::Zlib)
156 : BasicOStream<char>(0)
157 , _buffer(os, fmt)
158 {
159 this->setBuffer(&_buffer);
160 }
161
164 {}
165
169 { return _buffer; }
170
173 void attach(std::ostream& os)
174 {
175 _buffer.attach(os);
176 }
177
180 void detach()
181 {
182 _buffer.detach();
183 }
184
187 void reset()
188 {
189 _buffer.reset();
190 }
191
194 void reset(std::ostream& os)
195 {
196 _buffer.reset(os);
197 }
198
201 void finish()
202 {
203 _buffer.finish();
204 }
205
206 private:
207 ZBuffer _buffer;
208};
209
219class ZIOStream : public BasicIOStream<char>
220{
221 public:
225
229 : BasicIOStream<char>(0)
230 {
231 this->setBuffer(&_buffer);
232 }
233
236 explicit ZIOStream(std::iostream& ios)
237 : BasicIOStream<char>(0)
238 , _buffer(ios)
239 {
240 this->setBuffer(&_buffer);
241 }
242
245 {}
246
250 { return _buffer; }
251
254 void attach(std::iostream& ios)
255 {
256 _buffer.attach(ios);
257 }
258
261 void detach()
262 {
263 _buffer.detach();
264 }
265
268 void reset()
269 {
270 _buffer.reset();
271 }
272
275 void reset(std::iostream& ios)
276 {
277 _buffer.reset(ios);
278 }
279
282 void finish()
283 {
284 _buffer.finish();
285 }
286
289 std::size_t zcount() const
290 { return _buffer.zcount(); }
291
292 private:
293 ZBuffer _buffer;
294};
295
296} // namespace Pt
297
298#endif // Pt_ZStream_h
BasicIOStream(BasicStreamBuffer< char > *sb=0)
Definition IOStream.h:274
void setBuffer(BasicStreamBuffer< char > *sb)
Definition IOStream.h:213
void setBuffer(BasicStreamBuffer< char > *sb)
Definition IOStream.h:100
BasicIStream(BasicStreamBuffer< char > *sb=0)
Definition IOStream.h:225
BasicOStream(BasicStreamBuffer< char > *sb=0)
Definition IOStream.h:249
void setBuffer(BasicStreamBuffer< char > *sb)
Definition IOStream.h:152
Stream buffer that inflates on read and deflates on write.
Definition ZBuffer.h:62
Format
Compression/decompression format.
Definition ZBuffer.h:67
ZBuffer::Format Format
Compression/decompression format.
Definition ZStream.h:224
void reset(std::iostream &ios)
Reset to begin new compression/decompression.
Definition ZStream.h:275
void finish()
Finish and flush remaining data to the target stream.
Definition ZStream.h:282
ZBuffer & zBuffer()
Returns the compression buffer.
Definition ZStream.h:249
std::size_t zcount() const
Returns the total number of decompressed bytes produced so far.
Definition ZStream.h:289
ZIOStream()
Construct with target stream.
Definition ZStream.h:228
ZIOStream(std::iostream &ios)
Construct with target stream.
Definition ZStream.h:236
void attach(std::iostream &ios)
Attach to target stream.
Definition ZStream.h:254
void detach()
Detach from target stream.
Definition ZStream.h:261
void reset()
Reset to begin new compression/decompression.
Definition ZStream.h:268
~ZIOStream()
Destructor.
Definition ZStream.h:244
ZIStream(std::istream &is, Format fmt=Format::Zlib)
Construct with target stream.
Definition ZStream.h:67
void reset(std::istream &is)
Reset to begin new compression/decompression.
Definition ZStream.h:106
~ZIStream()
Destructor.
Definition ZStream.h:75
ZBuffer::Format Format
Compression/decompression format.
Definition ZStream.h:54
void finish()
Finish and flush remaining data to the target stream.
Definition ZStream.h:113
ZIStream(Format fmt=Format::Zlib)
Construct with format.
Definition ZStream.h:58
void attach(std::istream &is)
Attach to target stream.
Definition ZStream.h:85
ZBuffer & zBuffer()
Returns the compression buffer.
Definition ZStream.h:80
std::size_t zcount() const
Returns the total number of decompressed bytes produced so far.
Definition ZStream.h:120
void detach()
Detach from target stream.
Definition ZStream.h:92
void reset()
Reset to begin new compression/decompression.
Definition ZStream.h:99
ZBuffer::Format Format
Compression/decompression format.
Definition ZStream.h:142
ZOStream(std::ostream &os, Format fmt=Format::Zlib)
Construct with target stream.
Definition ZStream.h:155
void finish()
Finish and flush remaining data to the target stream.
Definition ZStream.h:201
void attach(std::ostream &os)
Attach to target stream.
Definition ZStream.h:173
ZBuffer & zBuffer()
Returns the compression buffer.
Definition ZStream.h:168
void detach()
Detach from target stream.
Definition ZStream.h:180
ZOStream(Format fmt=Format::Zlib)
Construct with format.
Definition ZStream.h:146
void reset()
Reset to begin new compression/decompression.
Definition ZStream.h:187
~ZOStream()
Destructor.
Definition ZStream.h:163
void reset(std::ostream &os)
Reset to begin new compression/decompression.
Definition ZStream.h:194
Core module.
Definition Allocator.h:33