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