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 
37 namespace Pt {
38 
41 class ZIStream : public BasicIStream<char>
42 {
43  public:
47  : BasicIStream<char>(0)
48  {
49  this->setBuffer(&_buffer);
50  }
51 
54  explicit ZIStream(std::istream& is)
55  : BasicIStream<char>(0)
56  , _buffer(is)
57  {
58  this->setBuffer(&_buffer);
59  }
60 
63  {}
64 
68  { return _buffer; }
69 
72  void attach(std::istream& is)
73  {
74  _buffer.attach(is);
75  }
76 
79  void detach()
80  {
81  _buffer.detach();
82  }
83 
86  void reset()
87  {
88  _buffer.reset();
89  }
90 
93  void reset(std::istream& is)
94  {
95  _buffer.reset(is);
96  }
97 
100  void finish()
101  {
102  _buffer.finish();
103  }
104 
105  private:
106  ZBuffer _buffer;
107 };
108 
111 class ZOStream : public BasicOStream<char>
112 {
113  public:
117  : BasicOStream<char>(0)
118  {
119  this->setBuffer(&_buffer);
120  }
121 
124  explicit ZOStream(std::ostream& os)
125  : BasicOStream<char>(0)
126  , _buffer(os)
127  {
128  this->setBuffer(&_buffer);
129  }
130 
133  {}
134 
138  { return _buffer; }
139 
142  void attach(std::ostream& os)
143  {
144  _buffer.attach(os);
145  }
146 
149  void detach()
150  {
151  _buffer.detach();
152  }
153 
156  void reset()
157  {
158  _buffer.reset();
159  }
160 
163  void reset(std::ostream& os)
164  {
165  _buffer.reset(os);
166  }
167 
170  void finish()
171  {
172  _buffer.finish();
173  }
174 
175  private:
176  ZBuffer _buffer;
177 };
178 
181 class ZIOStream : public BasicIOStream<char>
182 {
183  public:
187  : BasicIOStream<char>(0)
188  {
189  this->setBuffer(&_buffer);
190  }
191 
194  explicit ZIOStream(std::iostream& ios)
195  : BasicIOStream<char>(0)
196  , _buffer(ios)
197  {
198  this->setBuffer(&_buffer);
199  }
200 
203  {}
204 
208  { return _buffer; }
209 
212  void attach(std::iostream& ios)
213  {
214  _buffer.attach(ios);
215  }
216 
219  void detach()
220  {
221  _buffer.detach();
222  }
223 
226  void reset()
227  {
228  _buffer.reset();
229  }
230 
233  void reset(std::iostream& ios)
234  {
235  _buffer.reset(ios);
236  }
237 
240  void finish()
241  {
242  _buffer.finish();
243  }
244 
245  private:
246  ZBuffer _buffer;
247 };
248 
249 } // namespace Pt
250 
251 #endif // Pt_ZStream_h
void setBuffer(BasicStreamBuffer< char > *sb)
Sets the buffer.
Definition: IOStream.h:127
Input stream for zlib compression.
Definition: ZStream.h:41
void setBuffer(BasicStreamBuffer< char > *sb)
Sets the buffer.
Definition: IOStream.h:175
void detach()
Detach from target stream.
ZIStream()
Construct with target stream.
Definition: ZStream.h:46
void detach()
Detach from target stream.
Definition: ZStream.h:149
void reset()
Reset to begin new compression/decompression.
Definition: ZStream.h:226
~ZIOStream()
Destructor.
Definition: ZStream.h:202
ZBuffer & zBuffer()
Returns the compression buffer.
Definition: ZStream.h:137
void reset()
Reset to begin new compression/decompression.
Definition: ZStream.h:156
ZIStream(std::istream &is)
Construct with target stream.
Definition: ZStream.h:54
void finish()
Finish and flush remaining data to the target stream.
Definition: ZStream.h:170
void reset(std::iostream &ios)
Reset to begin new compression/decompression.
Definition: ZStream.h:233
Input stream.
Definition: IOStream.h:57
I/O stream for zlib compression.
Definition: ZStream.h:181
void finish()
Finish and flush remaining data to the target stream.
Input/Output stream.
Definition: IOStream.h:141
void finish()
Finish and flush remaining data to the target stream.
Definition: ZStream.h:240
Stream buffer for zlib compression.
Definition: ZBuffer.h:43
ZBuffer & zBuffer()
Returns the compression buffer.
Definition: ZStream.h:207
~ZIStream()
Destructor.
Definition: ZStream.h:62
void attach(std::ios &target)
Attach to target stream.
void attach(std::istream &is)
Attach to target stream.
Definition: ZStream.h:72
ZOStream(std::ostream &os)
Construct with target stream.
Definition: ZStream.h:124
void reset()
Reset to begin new compression/decompression.
Definition: ZStream.h:86
ZBuffer & zBuffer()
Returns the compression buffer.
Definition: ZStream.h:67
void attach(std::iostream &ios)
Attach to target stream.
Definition: ZStream.h:212
void reset()
Detach from target stream, discard the buffer and reset the state.
Output stream.
Definition: IOStream.h:101
void detach()
Detach from target stream.
Definition: ZStream.h:79
void finish()
Finish and flush remaining data to the target stream.
Definition: ZStream.h:100
void attach(std::ostream &os)
Attach to target stream.
Definition: ZStream.h:142
~ZOStream()
Destructor.
Definition: ZStream.h:132
ZIOStream()
Construct with target stream.
Definition: ZStream.h:186
Output stream for zlib compression.
Definition: ZStream.h:111
ZIOStream(std::iostream &ios)
Construct with target stream.
Definition: ZStream.h:194
void setBuffer(BasicStreamBuffer< char > *sb)
Sets the buffer.
Definition: IOStream.h:87
void reset(std::ostream &os)
Reset to begin new compression/decompression.
Definition: ZStream.h:163
void reset(std::istream &is)
Reset to begin new compression/decompression.
Definition: ZStream.h:93
ZOStream()
Construct with target stream.
Definition: ZStream.h:116
void detach()
Detach from target stream.
Definition: ZStream.h:219