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