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