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