#include <wx/stream.h>
wxInputStream is an abstract base class which may not be used directly.
It is the base class of all streams which provide a Read() function, i.e. which can be used to read data from a source (e.g. a file, a socket, etc).
If you want to create your own input stream, you'll need to derive from this class and implement the protected OnSysRead() function only.
Public Member Functions | |
wxInputStream () | |
Creates a dummy input stream. More... | |
virtual | ~wxInputStream () |
Destructor. More... | |
virtual bool | CanRead () const |
Returns true if some data is available in the stream right now, so that calling Read() wouldn't block. More... | |
virtual bool | Eof () const |
Returns true after an attempt has been made to read past the end of the stream. More... | |
int | GetC () |
Returns the first character in the input queue and removes it, blocking until it appears if necessary. More... | |
virtual size_t | LastRead () const |
Returns the last number of bytes read. More... | |
virtual char | Peek () |
Returns the first character in the input queue without removing it. More... | |
virtual wxInputStream & | Read (void *buffer, size_t size) |
Reads the specified amount of bytes and stores the data in buffer. More... | |
wxInputStream & | Read (wxOutputStream &stream_out) |
Reads data from the input queue and stores it in the specified output stream. More... | |
bool | ReadAll (void *buffer, size_t size) |
Reads exactly the specified number of bytes into the buffer. More... | |
virtual wxFileOffset | SeekI (wxFileOffset pos, wxSeekMode mode=wxFromStart) |
Changes the stream current position. More... | |
virtual wxFileOffset | TellI () const |
Returns the current stream position or wxInvalidOffset if it's not available (e.g. More... | |
size_t | Ungetch (const void *buffer, size_t size) |
This function is only useful in read mode. More... | |
bool | Ungetch (char c) |
This function acts like the previous one except that it takes only one character: it is sometimes shorter to use than the generic function. More... | |
Public Member Functions inherited from wxStreamBase | |
wxStreamBase () | |
Creates a dummy stream object. More... | |
virtual | ~wxStreamBase () |
Destructor. More... | |
wxStreamError | GetLastError () const |
This function returns the last error. More... | |
virtual wxFileOffset | GetLength () const |
Returns the length of the stream in bytes. More... | |
virtual size_t | GetSize () const |
This function returns the size of the stream. More... | |
virtual bool | IsOk () const |
Returns true if no error occurred on the stream. More... | |
virtual bool | IsSeekable () const |
Returns true if the stream supports seeking to arbitrary offsets. More... | |
void | Reset (wxStreamError error=wxSTREAM_NO_ERROR) |
Resets the stream state. More... | |
bool | operator! () const |
Returns the opposite of IsOk(). More... | |
Protected Member Functions | |
size_t | OnSysRead (void *buffer, size_t bufsize)=0 |
Internal function. More... | |
Protected Member Functions inherited from wxStreamBase | |
virtual wxFileOffset | OnSysSeek (wxFileOffset pos, wxSeekMode mode) |
Internal function. More... | |
virtual wxFileOffset | OnSysTell () const |
Internal function. More... | |
wxInputStream::wxInputStream | ( | ) |
Creates a dummy input stream.
|
virtual |
Destructor.
|
virtual |
Returns true if some data is available in the stream right now, so that calling Read() wouldn't block.
|
virtual |
Returns true after an attempt has been made to read past the end of the stream.
int wxInputStream::GetC | ( | ) |
Returns the first character in the input queue and removes it, blocking until it appears if necessary.
On success returns a value between 0 - 255; on end of file returns wxEOF
.
|
virtual |
Returns the last number of bytes read.
|
protectedpure virtual |
Internal function.
It is called when the stream wants to read data of the specified size bufsize and wants it to be placed inside buffer.
It should return the size that was actually read or zero if EOF has been reached or an error occurred (in this last case the internal m_lasterror
variable should be set accordingly as well).
|
virtual |
Returns the first character in the input queue without removing it.
|
virtual |
Reads the specified amount of bytes and stores the data in buffer.
To check if the call was successful you must use LastRead() to check if this call did actually read size bytes (if it didn't, GetLastError() should return a meaningful value).
wxInputStream& wxInputStream::Read | ( | wxOutputStream & | stream_out | ) |
Reads data from the input queue and stores it in the specified output stream.
The data is read until an error is raised by one of the two streams.
bool wxInputStream::ReadAll | ( | void * | buffer, |
size_t | size | ||
) |
Reads exactly the specified number of bytes into the buffer.
Returns true only if the entire amount of data was read, otherwise false is returned and the number of bytes really read can be retrieved using LastRead(), as with Read().
This method uses repeated calls to Read() (which may return after reading less than the requested number of bytes) if necessary.
|
virtual |
Changes the stream current position.
This operation in general is possible only for seekable streams (see wxStreamBase::IsSeekable()); non-seekable streams support only seeking positive amounts in mode wxFromCurrent
(this is implemented by reading data and simply discarding it).
pos | Offset to seek to. |
mode | One of wxFromStart, wxFromEnd, wxFromCurrent. |
|
virtual |
Returns the current stream position or wxInvalidOffset if it's not available (e.g.
socket streams do not have a size nor a current stream position).
size_t wxInputStream::Ungetch | ( | const void * | buffer, |
size_t | size | ||
) |
This function is only useful in read mode.
It is the manager of the "Write-Back" buffer. This buffer acts like a temporary buffer where data which has to be read during the next read IO call are put. This is useful when you get a big block of data which you didn't want to read: you can replace them at the top of the input queue by this way.
Be very careful about this call in connection with calling SeekI() on the same stream. Any call to SeekI() will invalidate any previous call to this method (otherwise you could SeekI() to one position, "unread" a few bytes there, SeekI() to another position and data would be either lost or corrupted).
bool wxInputStream::Ungetch | ( | char | c | ) |
This function acts like the previous one except that it takes only one character: it is sometimes shorter to use than the generic function.