]>
Commit | Line | Data |
---|---|---|
32fc4afb | 1 | ///////////////////////////////////////////////////////////////////////////// |
49e399d8 | 2 | // Name: wx/stream.h |
2b5f62a0 VZ |
3 | // Purpose: stream classes |
4 | // Author: Guilhem Lavaux, Guillermo Rodriguez Garcia, Vadim Zeitlin | |
32fc4afb GL |
5 | // Modified by: |
6 | // Created: 11/07/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
65571936 | 9 | // Licence: wxWindows licence |
32fc4afb GL |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_WXSTREAM_H__ |
13 | #define _WX_WXSTREAM_H__ | |
32fc4afb | 14 | |
ce4169a4 RR |
15 | #include "wx/defs.h" |
16 | ||
17 | #if wxUSE_STREAMS | |
18 | ||
32fc4afb | 19 | #include <stdio.h> |
45ea509a VZ |
20 | #include "wx/object.h" |
21 | #include "wx/string.h" | |
30984dea | 22 | #include "wx/filefn.h" // for wxFileOffset, wxInvalidOffset and wxSeekMode |
1678ad78 | 23 | |
bddd7a8d VZ |
24 | class WXDLLIMPEXP_BASE wxStreamBase; |
25 | class WXDLLIMPEXP_BASE wxInputStream; | |
26 | class WXDLLIMPEXP_BASE wxOutputStream; | |
1678ad78 GL |
27 | |
28 | typedef wxInputStream& (*__wxInputManip)(wxInputStream&); | |
29 | typedef wxOutputStream& (*__wxOutputManip)(wxOutputStream&); | |
30 | ||
bddd7a8d | 31 | WXDLLIMPEXP_BASE wxOutputStream& wxEndL(wxOutputStream& o_stream); |
1678ad78 | 32 | |
2b5f62a0 VZ |
33 | // ---------------------------------------------------------------------------- |
34 | // constants | |
35 | // ---------------------------------------------------------------------------- | |
f4ada568 | 36 | |
49e399d8 | 37 | enum wxStreamError |
cd6ce4a9 | 38 | { |
2b5f62a0 VZ |
39 | wxSTREAM_NO_ERROR = 0, // stream is in good state |
40 | wxSTREAM_EOF, // EOF reached in Read() or similar | |
41 | wxSTREAM_WRITE_ERROR, // generic write error | |
42 | wxSTREAM_READ_ERROR // generic read error | |
49e399d8 | 43 | }; |
75ed1d15 | 44 | |
cd6ce4a9 | 45 | // compatibility |
2b5f62a0 VZ |
46 | #if WXWIN_COMPATIBILITY_2_2 |
47 | #define wxStream_NOERROR wxSTREAM_NOERROR | |
48 | #define wxStream_EOF wxSTREAM_EOF | |
49 | #define wxStream_WRITE_ERR wxSTREAM_WRITE_ERROR | |
50 | #define wxStream_READ_ERR wxSTREAM_READ_ERROR | |
51 | ||
52 | #define wxSTREAM_NO_ERR wxSTREAM_NO_ERROR | |
53 | #define wxSTREAM_NOERROR wxSTREAM_NO_ERROR | |
54 | #define wxSTREAM_WRITE_ERR wxSTREAM_WRITE_ERROR | |
55 | #define wxSTREAM_READ_ERR wxSTREAM_READ_ERROR | |
56 | #endif // WXWIN_COMPATIBILITY_2_2 | |
57 | ||
58 | // ============================================================================ | |
59 | // base stream classes: wxInputStream and wxOutputStream | |
60 | // ============================================================================ | |
61 | ||
62 | // --------------------------------------------------------------------------- | |
63 | // wxStreamBase: common (but non virtual!) base for all stream classes | |
64 | // --------------------------------------------------------------------------- | |
cd6ce4a9 | 65 | |
bddd7a8d | 66 | class WXDLLIMPEXP_BASE wxStreamBase |
c7a9fa36 RR |
67 | { |
68 | public: | |
69 | wxStreamBase(); | |
70 | virtual ~wxStreamBase(); | |
75ed1d15 | 71 | |
cd6ce4a9 | 72 | // error testing |
cd6ce4a9 | 73 | wxStreamError GetLastError() const { return m_lasterror; } |
2b5f62a0 VZ |
74 | bool IsOk() const { return GetLastError() == wxSTREAM_NO_ERROR; } |
75 | bool operator!() const { return !IsOk(); } | |
cd6ce4a9 | 76 | |
2b5f62a0 VZ |
77 | // reset the stream state |
78 | void Reset() { m_lasterror = wxSTREAM_NO_ERROR; } | |
79 | ||
f6e7cd0a | 80 | // this doesn't make sense for all streams, always test its return value |
588066b7 VZ |
81 | virtual size_t GetSize() const; |
82 | virtual wxFileOffset GetLength() const { return wxInvalidOffset; } | |
47fc03d2 | 83 | |
3c70014d MW |
84 | // returns true if the streams supports seeking to arbitrary offsets |
85 | virtual bool IsSeekable() const { return false; } | |
86 | ||
2b5f62a0 | 87 | #if WXWIN_COMPATIBILITY_2_2 |
47fc03d2 | 88 | // deprecated, for compatibility only |
2d67974d WS |
89 | wxDEPRECATED( wxStreamError LastError() const ); |
90 | wxDEPRECATED( size_t StreamSize() const ); | |
2b5f62a0 | 91 | #endif // WXWIN_COMPATIBILITY_2_2 |
75ed1d15 | 92 | |
48710795 RR |
93 | |
94 | // Reserved for future use | |
95 | virtual void ReservedStreamFunc1() {} | |
96 | virtual void ReservedStreamFunc2() {} | |
97 | virtual void ReservedStreamFunc3() {} | |
98 | virtual void ReservedStreamFunc4() {} | |
99 | virtual void ReservedStreamFunc5() {} | |
100 | virtual void ReservedStreamFunc6() {} | |
101 | virtual void ReservedStreamFunc7() {} | |
102 | virtual void ReservedStreamFunc8() {} | |
103 | virtual void ReservedStreamFunc9() {} | |
104 | ||
c7a9fa36 | 105 | protected: |
4004775e RL |
106 | virtual wxFileOffset OnSysSeek(wxFileOffset seek, wxSeekMode mode); |
107 | virtual wxFileOffset OnSysTell() const; | |
75ed1d15 | 108 | |
c7a9fa36 RR |
109 | size_t m_lastcount; |
110 | wxStreamError m_lasterror; | |
2b5f62a0 VZ |
111 | |
112 | friend class wxStreamBuffer; | |
22f3361e | 113 | |
00e7a427 | 114 | DECLARE_NO_COPY_CLASS(wxStreamBase) |
75ed1d15 GL |
115 | }; |
116 | ||
2b5f62a0 VZ |
117 | // ---------------------------------------------------------------------------- |
118 | // wxInputStream: base class for the input streams | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
bddd7a8d | 121 | class WXDLLIMPEXP_BASE wxInputStream : public wxStreamBase |
c7a9fa36 RR |
122 | { |
123 | public: | |
2b5f62a0 | 124 | // ctor and dtor, nothing exciting |
c7a9fa36 RR |
125 | wxInputStream(); |
126 | virtual ~wxInputStream(); | |
32fc4afb | 127 | |
cd6ce4a9 | 128 | |
c7a9fa36 | 129 | // IO functions |
2b5f62a0 VZ |
130 | // ------------ |
131 | ||
132 | // return a character from the stream without removing it, i.e. it will | |
133 | // still be returned by the next call to GetC() | |
134 | // | |
135 | // blocks until something appears in the stream if necessary, if nothing | |
136 | // ever does (i.e. EOF) LastRead() will return 0 (and the return value is | |
137 | // undefined), otherwise 1 | |
c7a9fa36 | 138 | virtual char Peek(); |
2b5f62a0 VZ |
139 | |
140 | // return one character from the stream, blocking until it appears if | |
141 | // necessary | |
142 | // | |
143 | // if EOF, return value is undefined and LastRead() will return 0 and not 1 | |
c7a9fa36 | 144 | char GetC(); |
2b5f62a0 VZ |
145 | |
146 | // read at most the given number of bytes from the stream | |
147 | // | |
148 | // there are 2 possible situations here: either there is nothing at all in | |
149 | // the stream right now in which case Read() blocks until something appears | |
150 | // (use CanRead() to avoid this) or there is already some data available in | |
151 | // the stream and then Read() doesn't block but returns just the data it | |
152 | // can read without waiting for more | |
153 | // | |
154 | // in any case, if there are not enough bytes in the stream right now, | |
155 | // LastRead() value will be less than size but greater than 0. If it is 0, | |
156 | // it means that EOF has been reached. | |
c7a9fa36 | 157 | virtual wxInputStream& Read(void *buffer, size_t size); |
32fc4afb | 158 | |
2b5f62a0 VZ |
159 | // copy the entire contents of this stream into streamOut, stopping only |
160 | // when EOF is reached or an error occurs | |
161 | wxInputStream& Read(wxOutputStream& streamOut); | |
162 | ||
163 | ||
164 | // status functions | |
165 | // ---------------- | |
166 | ||
167 | // returns the number of bytes read by the last call to Read(), GetC() or | |
168 | // Peek() | |
169 | // | |
170 | // this should be used to discover whether that call succeeded in reading | |
171 | // all the requested data or not | |
172 | virtual size_t LastRead() const { return wxStreamBase::m_lastcount; } | |
173 | ||
d775fa82 | 174 | // returns true if some data is available in the stream right now, so that |
2b5f62a0 VZ |
175 | // calling Read() wouldn't block |
176 | virtual bool CanRead() const; | |
32fc4afb | 177 | |
2b5f62a0 VZ |
178 | // is the stream at EOF? |
179 | // | |
180 | // note that this cannot be really implemented for all streams and | |
181 | // CanRead() is more reliable than Eof() | |
182 | virtual bool Eof() const; | |
183 | ||
184 | ||
185 | // write back buffer | |
186 | // ----------------- | |
fae05df5 | 187 | |
2b5f62a0 VZ |
188 | // put back the specified number of bytes into the stream, they will be |
189 | // fetched by the next call to the read functions | |
190 | // | |
191 | // returns the number of bytes really stuffed back | |
c7a9fa36 | 192 | size_t Ungetch(const void *buffer, size_t size); |
2b5f62a0 VZ |
193 | |
194 | // put back the specified character in the stream | |
195 | // | |
d775fa82 | 196 | // returns true if ok, false on error |
c7a9fa36 | 197 | bool Ungetch(char c); |
0cd9bfe8 | 198 | |
2b5f62a0 VZ |
199 | |
200 | // position functions | |
201 | // ------------------ | |
202 | ||
203 | // move the stream pointer to the given position (if the stream supports | |
204 | // it) | |
205 | // | |
206 | // returns wxInvalidOffset on error | |
4004775e | 207 | virtual wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart); |
2b5f62a0 VZ |
208 | |
209 | // return the current position of the stream pointer or wxInvalidOffset | |
4004775e | 210 | virtual wxFileOffset TellI() const; |
2b5f62a0 VZ |
211 | |
212 | ||
213 | // stream-like operators | |
214 | // --------------------- | |
215 | ||
c7a9fa36 | 216 | wxInputStream& operator>>(wxOutputStream& out) { return Read(out); } |
2b5f62a0 | 217 | wxInputStream& operator>>(__wxInputManip func) { return func(*this); } |
fae05df5 | 218 | |
c7a9fa36 | 219 | protected: |
2b5f62a0 VZ |
220 | // do read up to size bytes of data into the provided buffer |
221 | // | |
3103e8a9 | 222 | // this method should return 0 if EOF has been reached or an error occurred |
2b5f62a0 VZ |
223 | // (m_lasterror should be set accordingly as well) or the number of bytes |
224 | // read | |
225 | virtual size_t OnSysRead(void *buffer, size_t size) = 0; | |
226 | ||
227 | // write-back buffer support | |
228 | // ------------------------- | |
229 | ||
230 | // return the pointer to a buffer big enough to hold sizeNeeded bytes | |
231 | char *AllocSpaceWBack(size_t sizeNeeded); | |
232 | ||
233 | // read up to size data from the write back buffer, return the number of | |
234 | // bytes read | |
235 | size_t GetWBack(void *buf, size_t size); | |
47fc03d2 | 236 | |
2b5f62a0 | 237 | // write back buffer or NULL if none |
c7a9fa36 | 238 | char *m_wback; |
2b5f62a0 VZ |
239 | |
240 | // the size of the buffer | |
c7a9fa36 | 241 | size_t m_wbacksize; |
fae05df5 | 242 | |
2b5f62a0 VZ |
243 | // the current position in the buffer |
244 | size_t m_wbackcur; | |
47fc03d2 VZ |
245 | |
246 | friend class wxStreamBuffer; | |
fc7a2a60 VZ |
247 | |
248 | DECLARE_NO_COPY_CLASS(wxInputStream) | |
32fc4afb GL |
249 | }; |
250 | ||
2b5f62a0 VZ |
251 | // ---------------------------------------------------------------------------- |
252 | // wxOutputStream: base for the output streams | |
253 | // ---------------------------------------------------------------------------- | |
254 | ||
bddd7a8d | 255 | class WXDLLIMPEXP_BASE wxOutputStream : public wxStreamBase |
c7a9fa36 RR |
256 | { |
257 | public: | |
258 | wxOutputStream(); | |
259 | virtual ~wxOutputStream(); | |
32fc4afb | 260 | |
c7a9fa36 RR |
261 | void PutC(char c); |
262 | virtual wxOutputStream& Write(const void *buffer, size_t size); | |
263 | wxOutputStream& Write(wxInputStream& stream_in); | |
32fc4afb | 264 | |
4004775e RL |
265 | virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart); |
266 | virtual wxFileOffset TellO() const; | |
1678ad78 | 267 | |
c7a9fa36 | 268 | virtual size_t LastWrite() const { return wxStreamBase::m_lastcount; } |
32fc4afb | 269 | |
c7a9fa36 | 270 | virtual void Sync(); |
8f0ff178 | 271 | virtual bool Close() { return true; } |
32fc4afb | 272 | |
c7a9fa36 | 273 | wxOutputStream& operator<<(wxInputStream& out) { return Write(out); } |
c7a9fa36 | 274 | wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); } |
47fc03d2 VZ |
275 | |
276 | protected: | |
277 | // to be implemented in the derived classes (it should have been pure | |
278 | // virtual) | |
279 | virtual size_t OnSysWrite(const void *buffer, size_t bufsize); | |
280 | ||
281 | friend class wxStreamBuffer; | |
fc7a2a60 VZ |
282 | |
283 | DECLARE_NO_COPY_CLASS(wxOutputStream) | |
32fc4afb GL |
284 | }; |
285 | ||
2b5f62a0 VZ |
286 | // ============================================================================ |
287 | // helper stream classes | |
288 | // ============================================================================ | |
289 | ||
e2acb9ae RR |
290 | // --------------------------------------------------------------------------- |
291 | // A stream for measuring streamed output | |
292 | // --------------------------------------------------------------------------- | |
293 | ||
bddd7a8d | 294 | class WXDLLIMPEXP_BASE wxCountingOutputStream : public wxOutputStream |
c7a9fa36 RR |
295 | { |
296 | public: | |
297 | wxCountingOutputStream(); | |
e2acb9ae | 298 | |
588066b7 | 299 | wxFileOffset GetLength() const; |
d775fa82 | 300 | bool Ok() const { return true; } |
e2acb9ae | 301 | |
c7a9fa36 | 302 | protected: |
47fc03d2 | 303 | virtual size_t OnSysWrite(const void *buffer, size_t size); |
4004775e RL |
304 | virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); |
305 | virtual wxFileOffset OnSysTell() const; | |
e2acb9ae | 306 | |
c7a9fa36 | 307 | size_t m_currentPos; |
fc7a2a60 VZ |
308 | |
309 | DECLARE_NO_COPY_CLASS(wxCountingOutputStream) | |
e2acb9ae RR |
310 | }; |
311 | ||
f4ada568 GL |
312 | // --------------------------------------------------------------------------- |
313 | // "Filter" streams | |
314 | // --------------------------------------------------------------------------- | |
32fc4afb | 315 | |
bddd7a8d | 316 | class WXDLLIMPEXP_BASE wxFilterInputStream : public wxInputStream |
c7a9fa36 RR |
317 | { |
318 | public: | |
319 | wxFilterInputStream(); | |
320 | wxFilterInputStream(wxInputStream& stream); | |
47fc03d2 | 321 | virtual ~wxFilterInputStream(); |
32fc4afb | 322 | |
c7a9fa36 | 323 | char Peek() { return m_parent_i_stream->Peek(); } |
32fc4afb | 324 | |
588066b7 | 325 | wxFileOffset GetLength() const { return m_parent_i_stream->GetLength(); } |
84b46c35 | 326 | |
47fc03d2 VZ |
327 | wxInputStream *GetFilterInputStream() const { return m_parent_i_stream; } |
328 | ||
c7a9fa36 RR |
329 | protected: |
330 | wxInputStream *m_parent_i_stream; | |
22f3361e VZ |
331 | |
332 | DECLARE_NO_COPY_CLASS(wxFilterInputStream) | |
32fc4afb GL |
333 | }; |
334 | ||
bddd7a8d | 335 | class WXDLLIMPEXP_BASE wxFilterOutputStream : public wxOutputStream |
c7a9fa36 RR |
336 | { |
337 | public: | |
338 | wxFilterOutputStream(); | |
339 | wxFilterOutputStream(wxOutputStream& stream); | |
47fc03d2 | 340 | virtual ~wxFilterOutputStream(); |
1678ad78 | 341 | |
588066b7 | 342 | wxFileOffset GetLength() const { return m_parent_o_stream->GetLength(); } |
84b46c35 | 343 | |
47fc03d2 VZ |
344 | wxOutputStream *GetFilterOutputStream() const { return m_parent_o_stream; } |
345 | ||
c7a9fa36 RR |
346 | protected: |
347 | wxOutputStream *m_parent_o_stream; | |
22f3361e VZ |
348 | |
349 | DECLARE_NO_COPY_CLASS(wxFilterOutputStream) | |
32fc4afb GL |
350 | }; |
351 | ||
2b5f62a0 VZ |
352 | // ============================================================================ |
353 | // buffered streams | |
354 | // ============================================================================ | |
355 | ||
fae05df5 | 356 | // --------------------------------------------------------------------------- |
47fc03d2 VZ |
357 | // Stream buffer: this class can be derived from and passed to |
358 | // wxBufferedStreams to implement custom buffering | |
fae05df5 GL |
359 | // --------------------------------------------------------------------------- |
360 | ||
bddd7a8d | 361 | class WXDLLIMPEXP_BASE wxStreamBuffer |
c7a9fa36 RR |
362 | { |
363 | public: | |
49e399d8 VZ |
364 | enum BufMode |
365 | { | |
366 | read, | |
367 | write, | |
368 | read_write | |
369 | }; | |
c7a9fa36 RR |
370 | |
371 | wxStreamBuffer(wxStreamBase& stream, BufMode mode); | |
c7a9fa36 | 372 | wxStreamBuffer(const wxStreamBuffer& buf); |
47fc03d2 | 373 | virtual ~wxStreamBuffer(); |
c7a9fa36 RR |
374 | |
375 | // Filtered IO | |
47fc03d2 | 376 | virtual size_t Read(void *buffer, size_t size); |
c7a9fa36 | 377 | size_t Read(wxStreamBuffer *buf); |
47fc03d2 | 378 | virtual size_t Write(const void *buffer, size_t size); |
c7a9fa36 RR |
379 | size_t Write(wxStreamBuffer *buf); |
380 | ||
47fc03d2 VZ |
381 | virtual char Peek(); |
382 | virtual char GetChar(); | |
383 | virtual void PutChar(char c); | |
4004775e RL |
384 | virtual wxFileOffset Tell() const; |
385 | virtual wxFileOffset Seek(wxFileOffset pos, wxSeekMode mode); | |
c7a9fa36 RR |
386 | |
387 | // Buffer control | |
388 | void ResetBuffer(); | |
49e399d8 VZ |
389 | |
390 | // NB: the buffer must always be allocated with malloc() if takeOwn is | |
d775fa82 WS |
391 | // true as it will be deallocated by free() |
392 | void SetBufferIO(void *start, void *end, bool takeOwnership = false); | |
393 | void SetBufferIO(void *start, size_t len, bool takeOwnership = false); | |
c7a9fa36 | 394 | void SetBufferIO(size_t bufsize); |
49e399d8 VZ |
395 | void *GetBufferStart() const { return m_buffer_start; } |
396 | void *GetBufferEnd() const { return m_buffer_end; } | |
397 | void *GetBufferPos() const { return m_buffer_pos; } | |
67c8c225 | 398 | size_t GetBufferSize() const { return m_buffer_size; } |
49e399d8 VZ |
399 | size_t GetIntPosition() const { return m_buffer_pos - m_buffer_start; } |
400 | void SetIntPosition(size_t pos) { m_buffer_pos = m_buffer_start + pos; } | |
401 | size_t GetLastAccess() const { return m_buffer_end - m_buffer_start; } | |
402 | size_t GetBytesLeft() const { return m_buffer_end - m_buffer_pos; } | |
c7a9fa36 RR |
403 | |
404 | void Fixed(bool fixed) { m_fixed = fixed; } | |
405 | void Flushable(bool f) { m_flushable = f; } | |
406 | ||
407 | bool FlushBuffer(); | |
408 | bool FillBuffer(); | |
409 | size_t GetDataLeft(); | |
410 | ||
49e399d8 VZ |
411 | // misc accessors |
412 | wxStreamBase *GetStream() const { return m_stream; } | |
413 | bool HasBuffer() const { return m_buffer_size != 0; } | |
414 | ||
415 | bool IsFixed() const { return m_fixed; } | |
416 | bool IsFlushable() const { return m_flushable; } | |
417 | ||
47fc03d2 VZ |
418 | // only for input/output buffers respectively, returns NULL otherwise |
419 | wxInputStream *GetInputStream() const; | |
420 | wxOutputStream *GetOutputStream() const; | |
421 | ||
49e399d8 | 422 | // deprecated, for compatibility only |
c7a9fa36 RR |
423 | wxStreamBase *Stream() { return m_stream; } |
424 | ||
2b5f62a0 VZ |
425 | // this constructs a dummy wxStreamBuffer, used by (and exists for) |
426 | // wxMemoryStreams only, don't use! | |
427 | wxStreamBuffer(BufMode mode); | |
428 | ||
c7a9fa36 RR |
429 | protected: |
430 | void GetFromBuffer(void *buffer, size_t size); | |
431 | void PutToBuffer(const void *buffer, size_t size); | |
432 | ||
49e399d8 VZ |
433 | // set the last error to the specified value if we didn't have it before |
434 | void SetError(wxStreamError err); | |
435 | ||
436 | // common part of several ctors | |
437 | void Init(); | |
c7a9fa36 | 438 | |
49e399d8 VZ |
439 | // init buffer variables to be empty |
440 | void InitBuffer(); | |
c7a9fa36 | 441 | |
49e399d8 VZ |
442 | // free the buffer (always safe to call) |
443 | void FreeBuffer(); | |
444 | ||
445 | // the buffer itself: the pointers to its start and end and the current | |
446 | // position in the buffer | |
447 | char *m_buffer_start, | |
448 | *m_buffer_end, | |
449 | *m_buffer_pos; | |
450 | ||
451 | // the buffer size | |
452 | // FIXME: isn't it the same as m_buffer_end - m_buffer_start? (VZ) | |
453 | size_t m_buffer_size; | |
454 | ||
455 | // the stream we're associated with | |
c7a9fa36 | 456 | wxStreamBase *m_stream; |
49e399d8 VZ |
457 | |
458 | // its mode | |
c7a9fa36 | 459 | BufMode m_mode; |
49e399d8 VZ |
460 | |
461 | // flags | |
462 | bool m_destroybuf, // deallocate buffer? | |
49e399d8 VZ |
463 | m_fixed, |
464 | m_flushable; | |
22f3361e VZ |
465 | |
466 | private: | |
467 | // Cannot use | |
468 | // DECLARE_NO_COPY_CLASS(wxStreamBuffer) | |
469 | // because copy constructor is explicitly declared above; | |
470 | // but no copy assignment operator is defined, so declare | |
471 | // it private to prevent the compiler from defining it: | |
472 | wxStreamBuffer& operator=(const wxStreamBuffer&); | |
fae05df5 GL |
473 | }; |
474 | ||
475 | // --------------------------------------------------------------------------- | |
2b5f62a0 | 476 | // wxBufferedInputStream |
fae05df5 GL |
477 | // --------------------------------------------------------------------------- |
478 | ||
bddd7a8d | 479 | class WXDLLIMPEXP_BASE wxBufferedInputStream : public wxFilterInputStream |
c7a9fa36 RR |
480 | { |
481 | public: | |
47fc03d2 VZ |
482 | // if a non NULL buffer is given to the stream, it will be deleted by it |
483 | wxBufferedInputStream(wxInputStream& stream, | |
484 | wxStreamBuffer *buffer = NULL); | |
485 | virtual ~wxBufferedInputStream(); | |
fae05df5 | 486 | |
c7a9fa36 RR |
487 | char Peek(); |
488 | wxInputStream& Read(void *buffer, size_t size); | |
657d2097 | 489 | |
c7a9fa36 | 490 | // Position functions |
4004775e RL |
491 | wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart); |
492 | wxFileOffset TellI() const; | |
3c70014d | 493 | bool IsSeekable() const { return m_parent_i_stream->IsSeekable(); } |
fae05df5 | 494 | |
47fc03d2 VZ |
495 | // the buffer given to the stream will be deleted by it |
496 | void SetInputStreamBuffer(wxStreamBuffer *buffer); | |
497 | wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; } | |
498 | ||
499 | // deprecated, for compatibility only | |
c7a9fa36 | 500 | wxStreamBuffer *InputStreamBuffer() const { return m_i_streambuf; } |
fae05df5 | 501 | |
c7a9fa36 | 502 | protected: |
47fc03d2 | 503 | virtual size_t OnSysRead(void *buffer, size_t bufsize); |
4004775e RL |
504 | virtual wxFileOffset OnSysSeek(wxFileOffset seek, wxSeekMode mode); |
505 | virtual wxFileOffset OnSysTell() const; | |
fae05df5 | 506 | |
c7a9fa36 | 507 | wxStreamBuffer *m_i_streambuf; |
22f3361e VZ |
508 | |
509 | DECLARE_NO_COPY_CLASS(wxBufferedInputStream) | |
fae05df5 GL |
510 | }; |
511 | ||
2b5f62a0 VZ |
512 | // ---------------------------------------------------------------------------- |
513 | // wxBufferedOutputStream | |
514 | // ---------------------------------------------------------------------------- | |
515 | ||
bddd7a8d | 516 | class WXDLLIMPEXP_BASE wxBufferedOutputStream : public wxFilterOutputStream |
c7a9fa36 RR |
517 | { |
518 | public: | |
47fc03d2 VZ |
519 | // if a non NULL buffer is given to the stream, it will be deleted by it |
520 | wxBufferedOutputStream(wxOutputStream& stream, | |
521 | wxStreamBuffer *buffer = NULL); | |
522 | virtual ~wxBufferedOutputStream(); | |
fae05df5 | 523 | |
c7a9fa36 | 524 | wxOutputStream& Write(const void *buffer, size_t size); |
657d2097 | 525 | |
c7a9fa36 | 526 | // Position functions |
4004775e RL |
527 | wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart); |
528 | wxFileOffset TellO() const; | |
3c70014d | 529 | bool IsSeekable() const { return m_parent_o_stream->IsSeekable(); } |
fae05df5 | 530 | |
c7a9fa36 | 531 | void Sync(); |
8f0ff178 | 532 | bool Close(); |
fae05df5 | 533 | |
588066b7 | 534 | wxFileOffset GetLength() const; |
657d2097 | 535 | |
47fc03d2 VZ |
536 | // the buffer given to the stream will be deleted by it |
537 | void SetOutputStreamBuffer(wxStreamBuffer *buffer); | |
538 | wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; } | |
539 | ||
540 | // deprecated, for compatibility only | |
c7a9fa36 | 541 | wxStreamBuffer *OutputStreamBuffer() const { return m_o_streambuf; } |
fae05df5 | 542 | |
c7a9fa36 | 543 | protected: |
47fc03d2 | 544 | virtual size_t OnSysWrite(const void *buffer, size_t bufsize); |
4004775e RL |
545 | virtual wxFileOffset OnSysSeek(wxFileOffset seek, wxSeekMode mode); |
546 | virtual wxFileOffset OnSysTell() const; | |
fae05df5 | 547 | |
c7a9fa36 | 548 | wxStreamBuffer *m_o_streambuf; |
22f3361e VZ |
549 | |
550 | DECLARE_NO_COPY_CLASS(wxBufferedOutputStream) | |
fae05df5 GL |
551 | }; |
552 | ||
47fc03d2 VZ |
553 | #endif // wxUSE_STREAMS |
554 | ||
555 | #endif // _WX_WXSTREAM_H__ | |
ce4169a4 | 556 |