]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/stream.h
Fixed wxPGMultiButton (event handling, FinalizePosition() -> Finalize(), no longer...
[wxWidgets.git] / interface / wx / stream.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: stream.h
c977fa84 3// Purpose: interface of wxStreamBase and its derived classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxCountingOutputStream
7c913512 11
23324ae1 12 wxCountingOutputStream is a specialized output stream which does not write any
c977fa84
FM
13 data anywhere, instead it counts how many bytes would get written if this were a
14 normal stream. This can sometimes be useful or required if some data gets
15 serialized to a stream or compressed by using stream compression and thus the
16 final size of the stream cannot be known other than pretending to write the stream.
17 One case where the resulting size would have to be known is if the data has
18 to be written to a piece of memory and the memory has to be allocated before
19 writing to it (which is probably always the case when writing to a memory stream).
7c913512 20
23324ae1
FM
21 @library{wxbase}
22 @category{streams}
23*/
24class wxCountingOutputStream : public wxOutputStream
25{
26public:
27 /**
28 Creates a wxCountingOutputStream object.
29 */
30 wxCountingOutputStream();
31
32 /**
33 Destructor.
34 */
adaaa686 35 virtual ~wxCountingOutputStream();
23324ae1
FM
36
37 /**
38 Returns the current size of the stream.
39 */
328f5751 40 size_t GetSize() const;
23324ae1
FM
41};
42
43
e54c96f1 44
23324ae1
FM
45/**
46 @class wxBufferedInputStream
7c913512 47
23324ae1 48 This stream acts as a cache. It caches the bytes read from the specified
c977fa84 49 input stream (see wxFilterInputStream).
23324ae1
FM
50 It uses wxStreamBuffer and sets the default in-buffer size to 1024 bytes.
51 This class may not be used without some other stream to read the data
52 from (such as a file stream or a memory stream).
7c913512 53
23324ae1
FM
54 @library{wxbase}
55 @category{streams}
7c913512 56
e54c96f1 57 @see wxStreamBuffer, wxInputStream, wxBufferedOutputStream
23324ae1
FM
58*/
59class wxBufferedInputStream : public wxFilterInputStream
60{
61public:
c977fa84
FM
62 /**
63 Constructor.
64 If a non @NULL buffer is given to the stream, it will be deleted by it.
65 */
66 wxBufferedInputStream(wxInputStream& stream,
67 wxStreamBuffer *buffer = NULL);
7c913512 68
c977fa84
FM
69 /**
70 Destructor.
71 */
72 virtual ~wxBufferedInputStream();
23324ae1
FM
73};
74
75
e54c96f1 76
23324ae1
FM
77/**
78 @class wxStreamBuffer
7c913512 79
c977fa84 80 @todo WRITE A DESCRIPTION
7c913512 81
23324ae1
FM
82 @library{wxbase}
83 @category{streams}
7c913512 84
e54c96f1 85 @see wxStreamBase
23324ae1 86*/
7c913512 87class wxStreamBuffer
23324ae1
FM
88{
89public:
c977fa84
FM
90
91 /**
92 Constructor, creates a new stream buffer using @a stream as a parent stream
93 and mode as the IO mode.
94
95 @param stream
96 The parent stream.
97 @param mode
98 Can be: wxStreamBuffer::read, wxStreamBuffer::write, wxStreamBuffer::read_write.
99
100 One stream can have many stream buffers but only one is used internally
101 to pass IO call (e.g. wxInputStream::Read() -> wxStreamBuffer::Read()),
102 but you can call directly wxStreamBuffer::Read without any problems.
103 Note that all errors and messages linked to the stream are stored in the
104 stream, not the stream buffers:
105
106 @code
107 streambuffer.Read(...);
108 streambuffer2.Read(...); // This call erases previous error messages set by 'streambuffer'
109 @endcode
110
111 @see SetBufferIO()
112 */
113 wxStreamBuffer(wxStreamBase& stream, BufMode mode);
114
115 /**
116 Constructor; creates a new empty stream buffer which won't flush any data
117 to a stream. mode specifies the type of the buffer (read, write, read_write).
118 This stream buffer has the advantage to be stream independent and to work
119 only on memory buffers but it is still compatible with the rest of the
120 wxStream classes. You can write, read to this special stream and it will
121 grow (if it is allowed by the user) its internal buffer.
122 Briefly, it has all functionality of a "normal" stream.
123
124 @warning
125 The "read_write" mode doesn't currently work for standalone stream buffers.
126
127 @see SetBufferIO()
128 */
129 wxStreamBuffer(BufMode mode);
130
23324ae1
FM
131 /**
132 Constructor. It initializes the stream buffer with the data of the specified
133 stream buffer. The new stream buffer has the same attributes, size, position
134 and they share the same buffer. This will cause problems if the stream to
135 which the stream buffer belong is destroyed and the newly cloned stream
136 buffer continues to be used, trying to call functions in the (destroyed)
137 stream. It is advised to use this feature only in very local area of the
138 program.
23324ae1 139 */
7c913512 140 wxStreamBuffer(const wxStreamBuffer& buffer);
23324ae1
FM
141
142 /**
c977fa84
FM
143 Destructor.
144 It finalizes all IO calls and frees all internal buffers if necessary.
23324ae1
FM
145 */
146 wxStreamBuffer();
147
148 /**
149 Fill the IO buffer.
150 */
151 bool FillBuffer();
152
153 /**
7c913512 154 Toggles the fixed flag. Usually this flag is toggled at the same time as
23324ae1 155 @e flushable. This flag allows (when it has the @false value) or forbids
c977fa84
FM
156 (when it has the @true value) the stream buffer to resize dynamically the
157 IO buffer.
3c4f71cc 158
4cc4bfaf 159 @see SetBufferIO()
23324ae1
FM
160 */
161 void Fixed(bool fixed);
162
163 /**
164 Flushes the IO buffer.
165 */
166 bool FlushBuffer();
167
168 /**
c977fa84
FM
169 Toggles the flushable flag.
170 If @a flushable is disabled, no data are sent to the parent stream.
23324ae1
FM
171 */
172 void Flushable(bool flushable);
173
174 /**
175 Returns a pointer on the end of the stream buffer.
176 */
328f5751 177 void* GetBufferEnd() const;
23324ae1
FM
178
179 /**
180 Returns a pointer on the current position of the stream buffer.
181 */
328f5751 182 void* GetBufferPos() const;
23324ae1
FM
183
184 /**
185 Returns the size of the buffer.
186 */
328f5751 187 size_t GetBufferSize() const;
23324ae1
FM
188
189 /**
190 Returns a pointer on the start of the stream buffer.
191 */
328f5751 192 void* GetBufferStart() const;
23324ae1
FM
193
194 /**
c977fa84
FM
195 Gets a single char from the stream buffer. It acts like the Read() call.
196
197 @warning
198 You aren't directly notified if an error occurred during the IO call.
3c4f71cc 199
4cc4bfaf 200 @see Read()
23324ae1 201 */
adaaa686 202 virtual char GetChar();
23324ae1
FM
203
204 /**
205 Returns the amount of available data in the buffer.
206 */
207 size_t GetDataLeft();
208
209 /**
210 Returns the current position (counted in bytes) in the stream buffer.
211 */
18e8e19b 212 wxFileOffset GetIntPosition() const;
23324ae1
FM
213
214 /**
215 Returns the amount of bytes read during the last IO call to the parent stream.
216 */
328f5751 217 size_t GetLastAccess() const;
23324ae1
FM
218
219 /**
220 Puts a single char to the stream buffer.
3c4f71cc 221
c977fa84
FM
222 @warning
223 You aren't directly notified if an error occurred during the IO call.
224
4cc4bfaf 225 @see Read()
23324ae1 226 */
adaaa686 227 virtual void PutChar(char c);
23324ae1 228
23324ae1 229 /**
c977fa84
FM
230 Reads a block of the specified size and stores the data in buffer.
231 This function tries to read from the buffer first and if more data has
232 been requested, reads more data from the associated stream and updates
233 the buffer accordingly until all requested data is read.
234
235 @return It returns the size of the data read. If the returned size is
236 different of the specified size, an error has occurred and
237 should be tested using GetLastError().
238 */
adaaa686 239 virtual size_t Read(void* buffer, size_t size);
c977fa84
FM
240
241 /**
242 Copies data to @a buffer.
243 The function returns when @a buffer is full or when there isn't
23324ae1 244 any more data in the current buffer.
3c4f71cc 245
4cc4bfaf 246 @see Write()
23324ae1 247 */
4cc4bfaf 248 Return value size_t Read(wxStreamBuffer* buffer);
23324ae1
FM
249
250 /**
251 Resets to the initial state variables concerning the buffer.
252 */
253 void ResetBuffer();
254
255 /**
256 Changes the current position.
c977fa84 257 Parameter @a mode may be one of the following:
3c4f71cc 258
c977fa84
FM
259 - @b wxFromStart: The position is counted from the start of the stream.
260 - @b wxFromCurrent: The position is counted from the current position of the stream.
261 - @b wxFromEnd: The position is counted from the end of the stream.
3c4f71cc 262
c977fa84
FM
263 @return Upon successful completion, it returns the new offset as
264 measured in bytes from the beginning of the stream.
265 Otherwise, it returns wxInvalidOffset.
266 */
18e8e19b 267 virtual wxFileOffset Seek(wxFileOffset pos, wxSeekMode mode);
3c4f71cc 268
c977fa84
FM
269 /**
270 Specifies which pointers to use for stream buffering.
271 You need to pass a pointer on the start of the buffer end and another
272 on the end. The object will use this buffer to cache stream data.
273 It may be used also as a source/destination buffer when you create an
274 empty stream buffer (See wxStreamBuffer::wxStreamBuffer).
3c4f71cc 275
c977fa84
FM
276 @remarks
277 When you use this function, you will have to destroy the IO buffers
278 yourself after the stream buffer is destroyed or don't use it anymore.
279 In the case you use it with an empty buffer, the stream buffer will not
280 resize it when it is full.
3c4f71cc 281
c977fa84 282 @see wxStreamBuffer(), Fixed(), Flushable()
23324ae1 283 */
c977fa84 284 void SetBufferIO(char* buffer_start, char* buffer_end);
23324ae1 285
23324ae1
FM
286 /**
287 Destroys or invalidates the previous IO buffer and allocates a new one of the
288 specified size.
3c4f71cc 289
c977fa84
FM
290 @warning
291 All previous pointers aren't valid anymore.
23324ae1 292
c977fa84
FM
293 @remarks
294 The created IO buffer is growable by the object.
23324ae1 295
c977fa84
FM
296 @see Fixed(), Flushable()
297 */
7c913512 298 void SetBufferIO(size_t bufsize);
23324ae1
FM
299
300 /**
301 Sets the current position (in bytes) in the stream buffer.
c977fa84
FM
302
303 @warning
304 Since it is a very low-level function, there is no check on the position:
305 specifying an invalid position can induce unexpected results.
23324ae1
FM
306 */
307 void SetIntPosition(size_t pos);
308
309 /**
310 Returns the parent stream of the stream buffer.
311 */
312 wxStreamBase* Stream();
313
314 /**
315 Gets the current position in the stream. This position is calculated from
316 the @e real position in the stream and from the internal buffer position: so
317 it gives you the position in the @e real stream counted from the start of
318 the stream.
3c4f71cc 319
d29a9a8a 320 @return Returns the current position in the stream if possible,
c977fa84 321 wxInvalidOffset in the other case.
23324ae1 322 */
18e8e19b 323 virtual wxFileOffset Tell() const;
23324ae1
FM
324
325 /**
326 Truncates the buffer to the current position.
c977fa84
FM
327
328 @note Truncate() cannot be used to enlarge the buffer. This is
329 usually not needed since the buffer expands automatically.
23324ae1
FM
330 */
331 void Truncate();
332
23324ae1 333 /**
c977fa84
FM
334 Writes a block of the specified size using data of buffer.
335 The data are cached in a buffer before being sent in one block to the stream.
23324ae1 336 */
adaaa686 337 virtual size_t Write(const void* buffer, size_t size);
c977fa84
FM
338
339 /**
340 See Read().
341 */
4cc4bfaf 342 size_t Write(wxStreamBuffer* buffer);
23324ae1
FM
343};
344
345
e54c96f1 346
23324ae1
FM
347/**
348 @class wxOutputStream
7c913512 349
23324ae1 350 wxOutputStream is an abstract base class which may not be used directly.
7c913512 351
23324ae1
FM
352 @library{wxbase}
353 @category{streams}
354*/
355class wxOutputStream : public wxStreamBase
356{
357public:
358 /**
359 Creates a dummy wxOutputStream object.
360 */
361 wxOutputStream();
362
363 /**
364 Destructor.
365 */
adaaa686 366 virtual ~wxOutputStream();
23324ae1
FM
367
368 /**
c977fa84
FM
369 Closes the stream, returning @false if an error occurs.
370 The stream is closed implicitly in the destructor if Close() is not
23324ae1 371 called explicitly.
c977fa84 372
23324ae1
FM
373 If this stream wraps another stream or some other resource such
374 as a file, then the underlying resource is closed too if it is owned
375 by this stream, or left open otherwise.
376 */
adaaa686 377 virtual bool Close();
23324ae1
FM
378
379 /**
c977fa84
FM
380 Returns the number of bytes written during the last Write().
381 It may return 0 even if there is no error on the stream if it is
382 only temporarily impossible to write to it.
23324ae1 383 */
adaaa686 384 virtual size_t LastWrite() const;
23324ae1
FM
385
386 /**
387 Puts the specified character in the output queue and increments the
388 stream position.
389 */
4cc4bfaf 390 void PutC(char c);
23324ae1
FM
391
392 /**
393 Changes the stream current position.
3c4f71cc 394
7c913512 395 @param pos
4cc4bfaf 396 Offset to seek to.
7c913512 397 @param mode
4cc4bfaf 398 One of wxFromStart, wxFromEnd, wxFromCurrent.
3c4f71cc 399
d29a9a8a 400 @return The new stream position or wxInvalidOffset on error.
23324ae1 401 */
18e8e19b 402 virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart);
23324ae1
FM
403
404 /**
405 Returns the current stream position.
406 */
18e8e19b 407 virtual wxFileOffset TellO() const;
23324ae1 408
c977fa84
FM
409 /**
410 Writes up to the specified amount of bytes using the data of buffer.
411 Note that not all data can always be written so you must check the number
412 of bytes really written to the stream using LastWrite() when this function
413 returns.
414
415 In some cases (for example a write end of a pipe which is currently full)
416 it is even possible that there is no errors and zero bytes have been written.
417 This function returns a reference on the current object, so the user can
418 test any states of the stream right away.
419 */
420 wxOutputStream Write(const void* buffer, size_t size);
421
23324ae1 422 /**
7c913512 423 Reads data from the specified input stream and stores them
23324ae1
FM
424 in the current stream. The data is read until an error is raised
425 by one of the two streams.
426 */
7c913512 427 wxOutputStream Write(wxInputStream& stream_in);
23324ae1
FM
428};
429
430
c977fa84
FM
431/**
432 Enumeration values used by wxFilterClassFactory.
433*/
434enum wxStreamProtocolType
435{
436 wxSTREAM_PROTOCOL, //!< wxFileSystem protocol (should be only one).
437 wxSTREAM_MIMETYPE, //!< MIME types the stream handles.
438 wxSTREAM_ENCODING, //!< The HTTP Content-Encodings the stream handles.
439 wxSTREAM_FILEEXT //!< File extensions the stream handles.
440};
441
e54c96f1 442
23324ae1
FM
443/**
444 @class wxFilterClassFactory
7c913512 445
23324ae1
FM
446 Allows the creation of filter streams to handle compression formats such
447 as gzip and bzip2.
7c913512 448
23324ae1
FM
449 For example, given a filename you can search for a factory that will
450 handle it and create a stream to decompress it:
7c913512 451
23324ae1
FM
452 @code
453 factory = wxFilterClassFactory::Find(filename, wxSTREAM_FILEEXT);
454 if (factory)
455 stream = factory-NewStream(new wxFFileInputStream(filename));
456 @endcode
7c913512 457
c977fa84
FM
458 wxFilterClassFactory::Find can also search for a factory by MIME type,
459 HTTP encoding or by wxFileSystem protocol.
460 The available factories can be enumerated using wxFilterClassFactory::GetFirst()
461 and wxFilterClassFactory::GetNext().
7c913512 462
23324ae1 463 @library{wxbase}
c977fa84 464 @category{streams}
7c913512 465
c977fa84
FM
466 @see wxFilterInputStream, wxFilterOutputStream, wxArchiveClassFactory,
467 @ref overview_archive
23324ae1
FM
468*/
469class wxFilterClassFactory : public wxObject
470{
471public:
472 /**
473 Returns @true if this factory can handle the given protocol, MIME type, HTTP
474 encoding or file extension.
c977fa84
FM
475
476 When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter
23324ae1
FM
477 can be a complete filename rather than just an extension.
478 */
479 bool CanHandle(const wxString& protocol,
328f5751 480 wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
23324ae1
FM
481
482 /**
483 A static member that finds a factory that can handle a given protocol, MIME
c977fa84
FM
484 type, HTTP encoding or file extension. Returns a pointer to the class
485 factory if found, or @NULL otherwise.
486 It does not give away ownership of the factory.
487
488 When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter
23324ae1
FM
489 can be a complete filename rather than just an extension.
490 */
491 static const wxFilterClassFactory* Find(const wxString& protocol,
492 wxStreamProtocolType type = wxSTREAM_PROTOCOL);
493
494 //@{
495 /**
496 GetFirst and GetNext can be used to enumerate the available factories.
23324ae1 497 For example, to list them:
3c4f71cc 498
c977fa84
FM
499 @code
500 wxString list;
501 const wxFilterClassFactory *factory = wxFilterClassFactory::GetFirst();
502
503 while (factory) {
504 list << factory->GetProtocol() << _T("\n");
505 factory = factory->GetNext();
506 }
507 @endcode
508
23324ae1
FM
509 GetFirst()/GetNext() return a pointer to a factory or @NULL if no more
510 are available. They do not give away ownership of the factory.
511 */
328f5751
FM
512 static const wxFilterClassFactory* GetFirst() const;
513 const wxFilterClassFactory* GetNext() const;
23324ae1
FM
514 //@}
515
516 /**
c977fa84
FM
517 Returns the wxFileSystem protocol supported by this factory.
518 Equivalent to @code wxString(*GetProtocols()) @endcode.
23324ae1 519 */
328f5751 520 wxString GetProtocol() const;
23324ae1
FM
521
522 /**
523 Returns the protocols, MIME types, HTTP encodings or file extensions
c977fa84
FM
524 supported by this factory, as an array of null terminated strings.
525 It does not give away ownership of the array or strings.
526
23324ae1 527 For example, to list the file extensions a factory supports:
c977fa84
FM
528
529 @code
530 wxString list;
531 const wxChar *const *p;
532
533 for (p = factory->GetProtocols(wxSTREAM_FILEEXT); *p; p++)
534 list << *p << _T("\n");
535 @endcode
23324ae1 536 */
328f5751 537 const wxChar* const* GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
23324ae1
FM
538
539 //@{
540 /**
541 Create a new input or output stream to decompress or compress a given stream.
c977fa84 542
23324ae1
FM
543 If the parent stream is passed as a pointer then the new filter stream
544 takes ownership of it. If it is passed by reference then it does not.
545 */
c977fa84
FM
546 wxFilterInputStream* NewStream(wxInputStream& stream) const;
547 wxFilterOutputStream* NewStream(wxOutputStream& stream) const;
548 wxFilterInputStream* NewStream(wxInputStream* stream) const;
549 wxFilterOutputStream* NewStream(wxOutputStream* stream) const;
23324ae1
FM
550 //@}
551
552 /**
4cc4bfaf 553 Remove the file extension of @a location if it is one of the file
23324ae1
FM
554 extensions handled by this factory.
555 */
328f5751 556 wxString PopExtension(const wxString& location) const;
23324ae1
FM
557
558 /**
c977fa84
FM
559 Adds this class factory to the list returned by GetFirst()/GetNext().
560
23324ae1 561 It is not necessary to do this to use the filter streams. It is usually
7c913512 562 used when implementing streams, typically the implementation will
23324ae1 563 add a static instance of its factory class.
c977fa84 564
23324ae1 565 It can also be used to change the order of a factory already in the list,
c977fa84
FM
566 bringing it to the front. This isn't a thread safe operation so can't be
567 done when other threads are running that will be using the list.
568
23324ae1
FM
569 The list does not take ownership of the factory.
570 */
571 void PushFront();
572
573 /**
c977fa84
FM
574 Removes this class factory from the list returned by GetFirst()/GetNext().
575 Removing from the list isn't a thread safe operation so can't be done
576 when other threads are running that will be using the list.
577
23324ae1
FM
578 The list does not own the factories, so removing a factory does not delete it.
579 */
580 void Remove();
581};
582
583
e54c96f1 584
23324ae1
FM
585/**
586 @class wxFilterOutputStream
7c913512 587
c977fa84
FM
588 A filter stream has the capability of a normal stream but it can be placed
589 on top of another stream. So, for example, it can compress, encrypt the data
590 which are passed to it and write them to another stream.
591
592 @note
593 The use of this class is exactly the same as of wxOutputStream.
594 Only a constructor differs and it is documented below.
7c913512 595
23324ae1
FM
596 @library{wxbase}
597 @category{streams}
7c913512 598
e54c96f1 599 @see wxFilterClassFactory, wxFilterInputStream
23324ae1
FM
600*/
601class wxFilterOutputStream : public wxOutputStream
602{
603public:
604 //@{
605 /**
606 Initializes a "filter" stream.
c977fa84 607
23324ae1
FM
608 If the parent stream is passed as a pointer then the new filter stream
609 takes ownership of it. If it is passed by reference then it does not.
610 */
611 wxFilterOutputStream(wxOutputStream& stream);
7c913512 612 wxFilterOutputStream(wxOutputStream* stream);
23324ae1
FM
613 //@}
614};
615
616
e54c96f1 617
23324ae1
FM
618/**
619 @class wxFilterInputStream
7c913512 620
23324ae1 621 A filter stream has the capability of a normal stream but it can be placed on
c977fa84
FM
622 top of another stream. So, for example, it can uncompress or decrypt the data which
623 are read from another stream and pass it to the requester.
624
625 @note
626 The interface of this class is the same as that of wxInputStream.
627 Only a constructor differs and it is documented below.
7c913512 628
23324ae1
FM
629 @library{wxbase}
630 @category{streams}
7c913512 631
e54c96f1 632 @see wxFilterClassFactory, wxFilterOutputStream
23324ae1
FM
633*/
634class wxFilterInputStream : public wxInputStream
635{
636public:
637 //@{
638 /**
639 Initializes a "filter" stream.
c977fa84 640
23324ae1
FM
641 If the parent stream is passed as a pointer then the new filter stream
642 takes ownership of it. If it is passed by reference then it does not.
643 */
644 wxFilterInputStream(wxInputStream& stream);
7c913512 645 wxFilterInputStream(wxInputStream* stream);
23324ae1
FM
646 //@}
647};
648
649
e54c96f1 650
23324ae1
FM
651/**
652 @class wxBufferedOutputStream
7c913512 653
23324ae1 654 This stream acts as a cache. It caches the bytes to be written to the specified
c977fa84
FM
655 output stream (See wxFilterOutputStream). The data is only written when the
656 cache is full, when the buffered stream is destroyed or when calling SeekO().
7c913512 657
23324ae1
FM
658 This class may not be used without some other stream to write the data
659 to (such as a file stream or a memory stream).
7c913512 660
23324ae1
FM
661 @library{wxbase}
662 @category{streams}
7c913512 663
e54c96f1 664 @see wxStreamBuffer, wxOutputStream
23324ae1
FM
665*/
666class wxBufferedOutputStream : public wxFilterOutputStream
667{
668public:
669 /**
98ccd545 670 @todo WRITE DESCRIPTION
23324ae1 671 */
98ccd545
FM
672 wxBufferedOutputStream(wxOutputStream& stream,
673 wxStreamBuffer *buffer = NULL);
23324ae1
FM
674 /**
675 Destructor. Calls Sync() and destroys the internal buffer.
676 */
98ccd545 677 virtual ~wxBufferedOutputStream();
23324ae1
FM
678
679 /**
680 Calls Sync() and changes the stream position.
681 */
98ccd545 682 virtual wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart)
23324ae1
FM
683
684 /**
685 Flushes the buffer and calls Sync() on the parent stream.
686 */
98ccd545 687 virtual void Sync();
23324ae1
FM
688};
689
690
e54c96f1 691
23324ae1
FM
692/**
693 @class wxInputStream
7c913512 694
23324ae1 695 wxInputStream is an abstract base class which may not be used directly.
7c913512 696
23324ae1
FM
697 @library{wxbase}
698 @category{streams}
699*/
700class wxInputStream : public wxStreamBase
701{
702public:
703 /**
704 Creates a dummy input stream.
705 */
706 wxInputStream();
707
708 /**
709 Destructor.
710 */
adaaa686 711 virtual ~wxInputStream();
23324ae1
FM
712
713 /**
714 Returns @true if some data is available in the stream right now, so that
715 calling Read() wouldn't block.
716 */
adaaa686 717 virtual bool CanRead() const;
23324ae1
FM
718
719 /**
720 Returns @true after an attempt has been made to read past the end of the
721 stream.
722 */
adaaa686 723 virtual bool Eof() const;
23324ae1
FM
724
725 /**
7c913512 726 Returns the first character in the input queue and removes it,
23324ae1
FM
727 blocking until it appears if necessary.
728 */
4cc4bfaf 729 char GetC();
23324ae1
FM
730
731 /**
732 Returns the last number of bytes read.
733 */
adaaa686 734 virtual size_t LastRead() const;
23324ae1
FM
735
736 /**
737 Returns the first character in the input queue without removing it.
738 */
adaaa686 739 virtual char Peek();
23324ae1 740
c977fa84
FM
741 /**
742 Reads the specified amount of bytes and stores the data in buffer.
743
744 @warning
745 The buffer absolutely needs to have at least the specified size.
746
747 @return This function returns a reference on the current object, so the
748 user can test any states of the stream right away.
749 */
750 wxInputStream Read(void* buffer, size_t size);
751
23324ae1
FM
752 /**
753 Reads data from the input queue and stores it in the specified output stream.
754 The data is read until an error is raised by one of the two streams.
3c4f71cc 755
d29a9a8a 756 @return This function returns a reference on the current object, so the
c977fa84 757 user can test any states of the stream right away.
23324ae1 758 */
c977fa84 759 wxInputStream& Read(wxOutputStream& stream_out);
23324ae1
FM
760
761 /**
762 Changes the stream current position.
3c4f71cc 763
7c913512 764 @param pos
4cc4bfaf 765 Offset to seek to.
7c913512 766 @param mode
4cc4bfaf 767 One of wxFromStart, wxFromEnd, wxFromCurrent.
3c4f71cc 768
d29a9a8a 769 @return The new stream position or wxInvalidOffset on error.
23324ae1 770 */
18e8e19b 771 virtual wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart);
23324ae1
FM
772
773 /**
774 Returns the current stream position.
775 */
18e8e19b 776 virtual wxFileOffset TellI() const;
23324ae1 777
c977fa84
FM
778 /**
779 This function is only useful in read mode.
780 It is the manager of the "Write-Back" buffer. This buffer acts like a
781 temporary buffer where data which has to be read during the next read IO
782 call are put. This is useful when you get a big block of data which you
783 didn't want to read: you can replace them at the top of the input queue
784 by this way.
785
786 Be very careful about this call in connection with calling SeekI() on
787 the same stream. Any call to SeekI() will invalidate any previous call
788 to this method (otherwise you could SeekI() to one position, "unread" a
789 few bytes there, SeekI() to another position and data would be either
790 lost or corrupted).
791
792 @return Returns the amount of bytes saved in the Write-Back buffer.
793 */
794 size_t Ungetch(const char* buffer, size_t size);
795
23324ae1
FM
796 /**
797 This function acts like the previous one except that it takes only one
798 character: it is sometimes shorter to use than the generic function.
799 */
7c913512 800 Return value bool Ungetch(char c);
23324ae1
FM
801};
802
803
c977fa84
FM
804/**
805 These enumeration values are returned by various functions in the context
806 of wxStream classes.
807*/
808enum wxStreamError
809{
810 wxSTREAM_NO_ERROR = 0, //!< No error occurred.
811 wxSTREAM_EOF, //!< EOF reached in Read() or similar.
812 wxSTREAM_WRITE_ERROR, //!< generic write error on the last write call.
813 wxSTREAM_READ_ERROR //!< generic read error on the last read call.
814};
e54c96f1 815
23324ae1
FM
816/**
817 @class wxStreamBase
7c913512 818
c977fa84
FM
819 This class is the base class of most stream related classes in wxWidgets.
820 It must not be used directly.
7c913512 821
23324ae1
FM
822 @library{wxbase}
823 @category{streams}
7c913512 824
e54c96f1 825 @see wxStreamBuffer
23324ae1 826*/
7c913512 827class wxStreamBase
23324ae1
FM
828{
829public:
830 /**
831 Creates a dummy stream object. It doesn't do anything.
832 */
833 wxStreamBase();
834
835 /**
836 Destructor.
837 */
adaaa686 838 virtual ~wxStreamBase();
23324ae1
FM
839
840 /**
841 This function returns the last error.
23324ae1 842 */
328f5751 843 wxStreamError GetLastError() const;
23324ae1
FM
844
845 /**
c977fa84
FM
846 Returns the length of the stream in bytes. If the length cannot be
847 determined (this is always the case for socket streams for example),
848 returns @c wxInvalidOffset.
3c4f71cc 849
1e24c2af 850 @since 2.5.4
23324ae1 851 */
adaaa686 852 virtual wxFileOffset GetLength() const;
23324ae1
FM
853
854 /**
c977fa84
FM
855 This function returns the size of the stream.
856 For example, for a file it is the size of the file.
857
858 @warning
859 There are streams which do not have size by definition, such as socket
860 streams. In that cases, GetSize returns 0 so you should always test its
861 return value.
23324ae1 862 */
adaaa686 863 virtual size_t GetSize() const;
23324ae1
FM
864
865 /**
866 Returns @true if no error occurred on the stream.
3c4f71cc 867
4cc4bfaf 868 @see GetLastError()
23324ae1 869 */
328f5751 870 virtual bool IsOk() const;
23324ae1
FM
871
872 /**
873 Returns @true if the streams supports seeking to arbitrary offsets.
874 */
adaaa686 875 virtual bool IsSeekable() const;
23324ae1
FM
876
877 /**
878 Internal function. It is called when the stream wants to read data of the
879 specified size. It should return the size that was actually read.
880 */
881 size_t OnSysRead(void* buffer, size_t bufsize);
882
883 /**
c977fa84
FM
884 Internal function.
885 It is called when the stream needs to change the current position.
23324ae1 886 */
18e8e19b 887 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
23324ae1
FM
888
889 /**
c977fa84
FM
890 Internal function.
891 It is called when the stream needs to know the real position.
23324ae1 892 */
18e8e19b 893 wxFileOffset OnSysTell() const;
23324ae1
FM
894
895 /**
896 See OnSysRead().
897 */
4cc4bfaf 898 size_t OnSysWrite(const void* buffer, size_t bufsize);
23324ae1 899};
e54c96f1 900