1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxCountingOutputStream class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxCountingOutputStream
13 wxCountingOutputStream is a specialized output stream which does not write any
15 instead it counts how many bytes would get written if this were a normal
17 can sometimes be useful or required if some data gets serialized to a stream or
19 by using stream compression and thus the final size of the stream cannot be
21 than pretending to write the stream. One case where the resulting size would
23 known is if the data has to be written to a piece of memory and the memory has
25 allocated before writing to it (which is probably always the case when writing
32 class wxCountingOutputStream
: public wxOutputStream
36 Creates a wxCountingOutputStream object.
38 wxCountingOutputStream();
43 ~wxCountingOutputStream();
46 Returns the current size of the stream.
48 size_t GetSize() const;
53 @class wxBufferedInputStream
56 This stream acts as a cache. It caches the bytes read from the specified
57 input stream (See wxFilterInputStream).
58 It uses wxStreamBuffer and sets the default in-buffer size to 1024 bytes.
59 This class may not be used without some other stream to read the data
60 from (such as a file stream or a memory stream).
66 wxStreamBuffer, wxInputStream, wxBufferedOutputStream
68 class wxBufferedInputStream
: public wxFilterInputStream
91 Constructor. It initializes the stream buffer with the data of the specified
92 stream buffer. The new stream buffer has the same attributes, size, position
93 and they share the same buffer. This will cause problems if the stream to
94 which the stream buffer belong is destroyed and the newly cloned stream
95 buffer continues to be used, trying to call functions in the (destroyed)
96 stream. It is advised to use this feature only in very local area of the
99 @see @ref setbufferio() wxStreamBuffer:SetBufferIO
101 wxStreamBuffer(wxStreamBase
& stream
, BufMode mode
);
102 wxStreamBuffer(BufMode mode
);
103 wxStreamBuffer(const wxStreamBuffer
& buffer
);
107 Destructor. It finalizes all IO calls and frees all internal buffers if
118 Toggles the fixed flag. Usually this flag is toggled at the same time as
119 @e flushable. This flag allows (when it has the @false value) or forbids
120 (when it has the @true value) the stream buffer to resize dynamically the IO
125 void Fixed(bool fixed
);
128 Flushes the IO buffer.
133 Toggles the flushable flag. If @a flushable is disabled, no data are sent
134 to the parent stream.
136 void Flushable(bool flushable
);
139 Returns a pointer on the end of the stream buffer.
141 void* GetBufferEnd() const;
144 Returns a pointer on the current position of the stream buffer.
146 void* GetBufferPos() const;
149 Returns the size of the buffer.
151 size_t GetBufferSize() const;
154 Returns a pointer on the start of the stream buffer.
156 void* GetBufferStart() const;
159 Gets a single char from the stream buffer. It acts like the Read call.
166 Returns the amount of available data in the buffer.
168 size_t GetDataLeft();
171 Returns the current position (counted in bytes) in the stream buffer.
173 off_t
GetIntPosition() const;
176 Returns the amount of bytes read during the last IO call to the parent stream.
178 size_t GetLastAccess() const;
181 Puts a single char to the stream buffer.
185 void PutChar(char c
);
189 Copies data to @e buffer. The function returns when @a buffer is full or when
191 any more data in the current buffer.
195 size_t Read(void* buffer
, size_t size
);
196 Return value
size_t Read(wxStreamBuffer
* buffer
);
200 Resets to the initial state variables concerning the buffer.
205 Changes the current position.
206 @a mode may be one of the following:
210 The position is counted from the start of the stream.
214 The position is counted from the current position of the stream.
218 The position is counted from the end of the stream.
220 @returns Upon successful completion, it returns the new offset as
221 measured in bytes from the beginning of the stream.
222 Otherwise, it returns wxInvalidOffset.
224 off_t
Seek(off_t pos
, wxSeekMode mode
);
228 Destroys or invalidates the previous IO buffer and allocates a new one of the
231 @see Fixed(), Flushable()
233 void SetBufferIO(char* buffer_start
, char* buffer_end
);
235 wxStreamBuffer constructor
237 wxStreamBuffer::Fixed
239 wxStreamBuffer::Flushable
240 void SetBufferIO(size_t bufsize
);
244 Sets the current position (in bytes) in the stream buffer.
246 void SetIntPosition(size_t pos
);
249 Returns the parent stream of the stream buffer.
251 wxStreamBase
* Stream();
254 Gets the current position in the stream. This position is calculated from
255 the @e real position in the stream and from the internal buffer position: so
256 it gives you the position in the @e real stream counted from the start of
259 @returns Returns the current position in the stream if possible,
260 wxInvalidOffset in the other case.
265 Truncates the buffer to the current position.
266 Note: Truncate() cannot be used to enlarge the buffer. This is
267 usually not needed since the buffer expands automatically.
275 size_t Write(const void* buffer
, size_t size
);
276 size_t Write(wxStreamBuffer
* buffer
);
282 @class wxOutputStream
285 wxOutputStream is an abstract base class which may not be used directly.
290 class wxOutputStream
: public wxStreamBase
294 Creates a dummy wxOutputStream object.
304 Closes the stream, returning @false if an error occurs. The
305 stream is closed implicitly in the destructor if Close() is not
307 If this stream wraps another stream or some other resource such
308 as a file, then the underlying resource is closed too if it is owned
309 by this stream, or left open otherwise.
314 Returns the number of bytes written during the last
315 Write(). It may return 0 even if there is no
316 error on the stream if it is only temporarily impossible to write to it.
318 size_t LastWrite() const;
321 Puts the specified character in the output queue and increments the
327 Changes the stream current position.
332 One of wxFromStart, wxFromEnd, wxFromCurrent.
334 @returns The new stream position or wxInvalidOffset on error.
336 off_t
SeekO(off_t pos
, wxSeekMode mode
= wxFromStart
);
339 Returns the current stream position.
345 Reads data from the specified input stream and stores them
346 in the current stream. The data is read until an error is raised
347 by one of the two streams.
349 wxOutputStream
Write(const void* buffer
, size_t size
);
350 wxOutputStream
Write(wxInputStream
& stream_in
);
356 @class wxFilterClassFactory
359 Allows the creation of filter streams to handle compression formats such
362 For example, given a filename you can search for a factory that will
363 handle it and create a stream to decompress it:
366 factory = wxFilterClassFactory::Find(filename, wxSTREAM_FILEEXT);
368 stream = factory-NewStream(new wxFFileInputStream(filename));
371 wxFilterClassFactory::Find can also search
372 for a factory by MIME type, HTTP encoding or by wxFileSystem protocol.
373 The available factories can be enumerated
374 using @ref wxFilterClassFactory::getfirst "GetFirst() and GetNext".
380 wxFilterInputStream, wxFilterOutputStream, wxArchiveClassFactory, @ref
381 overview_wxarc "Archive formats such as zip"
383 class wxFilterClassFactory
: public wxObject
387 Returns @true if this factory can handle the given protocol, MIME type, HTTP
388 encoding or file extension.
389 When using wxSTREAM_FILEEXT for the second parameter, the first parameter
390 can be a complete filename rather than just an extension.
392 bool CanHandle(const wxString
& protocol
,
393 wxStreamProtocolType type
= wxSTREAM_PROTOCOL
) const;
396 A static member that finds a factory that can handle a given protocol, MIME
397 type, HTTP encoding or file extension. Returns a pointer to the class
398 factory if found, or @NULL otherwise. It does not give away ownership of the
400 When using wxSTREAM_FILEEXT for the second parameter, the first parameter
401 can be a complete filename rather than just an extension.
403 static const wxFilterClassFactory
* Find(const wxString
& protocol
,
404 wxStreamProtocolType type
= wxSTREAM_PROTOCOL
);
408 GetFirst and GetNext can be used to enumerate the available factories.
409 For example, to list them:
411 GetFirst()/GetNext() return a pointer to a factory or @NULL if no more
412 are available. They do not give away ownership of the factory.
414 static const wxFilterClassFactory
* GetFirst() const;
415 const wxFilterClassFactory
* GetNext() const;
419 Returns the wxFileSystem protocol supported by this factory. Equivalent
420 to wxString(*GetProtcols()).
422 wxString
GetProtocol() const;
425 Returns the protocols, MIME types, HTTP encodings or file extensions
426 supported by this factory, as an array of null terminated strings. It does
427 not give away ownership of the array or strings.
428 For example, to list the file extensions a factory supports:
430 const wxChar
* const* GetProtocols(wxStreamProtocolType type
= wxSTREAM_PROTOCOL
) const;
434 Create a new input or output stream to decompress or compress a given stream.
435 If the parent stream is passed as a pointer then the new filter stream
436 takes ownership of it. If it is passed by reference then it does not.
438 wxFilterInputStream
* NewStream(wxInputStream
& stream
) const;
439 const wxFilterOutputStream
* NewStream(wxOutputStream
& stream
) const;
440 const wxFilterInputStream
* NewStream(wxInputStream
* stream
) const;
441 const wxFilterOutputStream
* NewStream(wxOutputStream
* stream
) const;
445 Remove the file extension of @a location if it is one of the file
446 extensions handled by this factory.
448 wxString
PopExtension(const wxString
& location
) const;
451 Adds this class factory to the list returned
452 by @ref getfirst() GetFirst()/GetNext.
453 It is not necessary to do this to use the filter streams. It is usually
454 used when implementing streams, typically the implementation will
455 add a static instance of its factory class.
456 It can also be used to change the order of a factory already in the list,
457 bringing it to the front. This isn't a thread safe operation
458 so can't be done when other threads are running that will be using the list.
459 The list does not take ownership of the factory.
464 Removes this class factory from the list returned
465 by @ref getfirst() GetFirst()/GetNext.
466 Removing from the list isn't a thread safe operation
467 so can't be done when other threads are running that will be using the list.
468 The list does not own the factories, so removing a factory does not delete it.
475 @class wxFilterOutputStream
478 A filter stream has the capability of a normal
479 stream but it can be placed on top of another stream. So, for example, it
480 can compress, encrypt the data which are passed to it and write them to another
487 wxFilterClassFactory, wxFilterInputStream
489 class wxFilterOutputStream
: public wxOutputStream
494 Initializes a "filter" stream.
495 If the parent stream is passed as a pointer then the new filter stream
496 takes ownership of it. If it is passed by reference then it does not.
498 wxFilterOutputStream(wxOutputStream
& stream
);
499 wxFilterOutputStream(wxOutputStream
* stream
);
505 @class wxFilterInputStream
508 A filter stream has the capability of a normal stream but it can be placed on
510 of another stream. So, for example, it can uncompress or decrypt the data which
512 from another stream and pass it to the requester.
518 wxFilterClassFactory, wxFilterOutputStream
520 class wxFilterInputStream
: public wxInputStream
525 Initializes a "filter" stream.
526 If the parent stream is passed as a pointer then the new filter stream
527 takes ownership of it. If it is passed by reference then it does not.
529 wxFilterInputStream(wxInputStream
& stream
);
530 wxFilterInputStream(wxInputStream
* stream
);
536 @class wxBufferedOutputStream
539 This stream acts as a cache. It caches the bytes to be written to the specified
540 output stream (See wxFilterOutputStream). The
541 data is only written when the cache is full, when the buffered stream is
542 destroyed or when calling SeekO().
544 This class may not be used without some other stream to write the data
545 to (such as a file stream or a memory stream).
551 wxStreamBuffer, wxOutputStream
553 class wxBufferedOutputStream
: public wxFilterOutputStream
557 Creates a buffered stream using a buffer of a default size of 1024 bytes for
559 the stream @e parent.
561 wxBufferedOutputStream(const wxOutputStream
& parent
);
564 Destructor. Calls Sync() and destroys the internal buffer.
566 ~wxBufferedOutputStream();
569 Calls Sync() and changes the stream position.
571 off_t
SeekO(off_t pos
, wxSeekMode mode
);
574 Flushes the buffer and calls Sync() on the parent stream.
584 wxInputStream is an abstract base class which may not be used directly.
589 class wxInputStream
: public wxStreamBase
593 Creates a dummy input stream.
603 Returns @true if some data is available in the stream right now, so that
604 calling Read() wouldn't block.
606 bool CanRead() const;
609 Returns @true after an attempt has been made to read past the end of the
615 Returns the first character in the input queue and removes it,
616 blocking until it appears if necessary.
621 Returns the last number of bytes read.
623 size_t LastRead() const;
626 Returns the first character in the input queue without removing it.
632 Reads data from the input queue and stores it in the specified output stream.
633 The data is read until an error is raised by one of the two streams.
635 @returns This function returns a reference on the current object, so the
636 user can test any states of the stream right away.
638 wxInputStream
Read(void* buffer
, size_t size
);
640 This function returns a reference on the current object
, so the user can test
641 any states of the stream right away
.
642 wxInputStream
& Read(wxOutputStream
& stream_out
);
646 Changes the stream current position.
651 One of wxFromStart, wxFromEnd, wxFromCurrent.
653 @returns The new stream position or wxInvalidOffset on error.
655 off_t
SeekI(off_t pos
, wxSeekMode mode
= wxFromStart
);
658 Returns the current stream position.
664 This function acts like the previous one except that it takes only one
665 character: it is sometimes shorter to use than the generic function.
667 size_t Ungetch(const char* buffer
, size_t size
);
668 Return value
bool Ungetch(char c
);
677 This class is the base class of most stream related classes in wxWidgets. It
679 not be used directly.
691 Creates a dummy stream object. It doesn't do anything.
701 This function returns the last error.
709 An End-Of-File occurred.
711 @b wxSTREAM_WRITE_ERROR
713 A generic error occurred on the last write call.
715 @b wxSTREAM_READ_ERROR
717 A generic error occurred on the last read call.
719 wxStreamError
GetLastError() const;
722 Returns the length of the stream in bytes. If the length cannot be determined
723 (this is always the case for socket streams for example), returns
725 This function is new since wxWidgets version 2.5.4
727 wxFileOffset
GetLength() const;
731 This function returns the size of the stream. For example, for a file it is the
734 size_t GetSize() const;
737 Returns @true if no error occurred on the stream.
741 virtual bool IsOk() const;
744 Returns @true if the streams supports seeking to arbitrary offsets.
746 bool IsSeekable() const;
749 Internal function. It is called when the stream wants to read data of the
750 specified size. It should return the size that was actually read.
752 size_t OnSysRead(void* buffer
, size_t bufsize
);
755 Internal function. It is called when the stream needs to change the
758 off_t
OnSysSeek(off_t pos
, wxSeekMode mode
);
761 Internal function. Is is called when the stream needs to know the
764 off_t
OnSysTell() const;
769 size_t OnSysWrite(const void* buffer
, size_t bufsize
);