| Version: 3.3.1

Public Member Functions | Protected Member Functions | List of all members
wxStreamBase Class Reference
Class List by Category » Streams

`#include <wx/stream.h>`

Inheritance diagram for wxStreamBase:
[legend]

## Detailed Description

This class is the base class of most stream related classes in wxWidgets.

It must not be used directly.

##

Library: wxBase
Category: Streams

See also
  wxStreamBuffer

## Public Member Functions
| 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
virtual wxFileOffset | OnSysSeek (wxFileOffset pos, wxSeekMode mode)
| Internal function. More...
virtual wxFileOffset | OnSysTell () const
| Internal function. More...

## Constructor & Destructor Documentation

## ◆ wxStreamBase()

wxStreamBase::wxStreamBase | ( |  | ) |

Creates a dummy stream object.

It doesn't do anything.

## ◆ ~wxStreamBase()

virtual wxStreamBase::~wxStreamBase | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ GetLastError()

wxStreamError wxStreamBase::GetLastError | ( |  | ) | const

This function returns the last error.

## ◆ GetLength()

virtual wxFileOffset wxStreamBase::GetLength | ( |  | ) | const
| virtual

Returns the length of the stream in bytes.

If the length cannot be determined (this is always the case for socket streams for example), returns wxInvalidOffset.

Since
  2.5.4

Reimplemented in wxCountingOutputStream.

## ◆ GetSize()

virtual size_t wxStreamBase::GetSize | ( |  | ) | const
| virtual

This function returns the size of the stream.

For example, for a file it is the size of the file.

Warning
  There are streams which do not have size by definition, such as socket streams. In that cases, GetSize() returns 0 so you should always test its return value.

## ◆ IsOk()

virtual bool wxStreamBase::IsOk | ( |  | ) | const
| virtual

Returns true if no error occurred on the stream.

See also
  GetLastError()

Reimplemented in wxFileStream, wxFFileStream, wxFFileInputStream, wxFileInputStream, wxFileOutputStream, wxFFileOutputStream, and wxFSInputStream.

## ◆ IsSeekable()

virtual bool wxStreamBase::IsSeekable | ( |  | ) | const
| virtual

Returns true if the stream supports seeking to arbitrary offsets.

## ◆ OnSysSeek()

virtual wxFileOffset wxStreamBase::OnSysSeek | ( | wxFileOffset | pos,
|  | wxSeekMode | mode
| ) |  |
| protected virtual

Internal function.

It is called when the stream needs to change the current position.

Parameters

  pos | Offset to seek to.
  mode | One of the wxSeekMode enumeration values.

Returns
  The new stream position or wxInvalidOffset on error.

## ◆ OnSysTell()

virtual wxFileOffset wxStreamBase::OnSysTell | ( |  | ) | const
| protected virtual

Internal function.

It is called when the stream needs to know the real position.

Returns
  The current stream position.

## ◆ operator!()

bool wxStreamBase::operator! | ( |  | ) | const

Returns the opposite of IsOk().

You can use this function to test the validity of the stream as if it was a pointer:

bool DoSomething(wxInputStream& stream)
{
wxInt32 data;
if (!stream.Read(&data, 4))
return false;
...
}
wxInputStream
wxInputStream is an abstract base class which may not be used directly.
Definition: stream.h:580
wxInputStream::Read
virtual wxInputStream & Read(void *buffer, size_t size)
Reads the specified amount of bytes and stores the data in buffer.
wxInt32
int wxInt32
32 bit type (the mapping is more complex than a simple typedef and is not shown here).
Definition: defs.h:1415

## ◆ Reset()

void wxStreamBase::Reset | ( | wxStreamError | error = `wxSTREAM_NO_ERROR` | ) |

Resets the stream state.

By default, resets the stream to good state, i.e. clears any errors. Since wxWidgets 2.9.3 can be also used to explicitly set the state to the specified error (the error argument didn't exist in the previous versions).

See also
  GetLastError()