| Version: 3.2.5

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

`#include <wx/stream.h>`

Inheritance diagram for wxOutputStream:
[legend]

## Detailed Description

wxOutputStream is an abstract base class which may not be used directly.

It is the base class of all streams which provide a Write() function, i.e. which can be used to output data (e.g. to a file, to a socket, etc).

If you want to create your own output stream, you'll need to derive from this class and implement the protected OnSysWrite() function only.

##

Library: wxBase
Category: Streams

## Public Member Functions

| wxOutputStream ()
| Creates a dummy wxOutputStream object. More...
virtual | ~wxOutputStream ()
| Destructor. More...
virtual bool | Close ()
| Closes the stream, returning false if an error occurs. More...
virtual size_t | LastWrite () const
| Returns the number of bytes written during the last Write(). More...
void | PutC (char c)
| Puts the specified character in the output queue and increments the stream position. More...
virtual wxFileOffset | SeekO (wxFileOffset pos, wxSeekMode mode=wxFromStart)
| Changes the stream current position. More...
virtual wxFileOffset | TellO () const
| Returns the current stream position. More...
virtual wxOutputStream & | Write (const void *buffer, size_t size)
| Writes up to the specified amount of bytes using the data of buffer. More...
wxOutputStream & | Write (wxInputStream &stream_in)
| Reads data from the specified input stream and stores them in the current stream. More...
bool | WriteAll (const void *buffer, size_t size)
| Writes exactly the specified number of bytes from the buffer. 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 | OnSysWrite (const void *buffer, size_t bufsize)
| 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...

## Constructor & Destructor Documentation

## ◆ wxOutputStream()

wxOutputStream::wxOutputStream | ( |  | ) |

Creates a dummy wxOutputStream object.

## ◆ ~wxOutputStream()

virtual wxOutputStream::~wxOutputStream | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## ◆ Close()

virtual bool wxOutputStream::Close | ( |  | ) |

virtual

Closes the stream, returning false if an error occurs.

The stream is closed implicitly in the destructor if Close() is not called explicitly.

If this stream wraps another stream or some other resource such as a file, then the underlying resource is closed too if it is owned by this stream, or left open otherwise.

Reimplemented in wxZipOutputStream, wxTarOutputStream, and wxArchiveOutputStream.

## ◆ LastWrite()

virtual size_t wxOutputStream::LastWrite | ( |  | ) | const

virtual

Returns the number of bytes written during the last Write().

It may return 0 even if there is no error on the stream if it is only temporarily impossible to write to it.

## ◆ OnSysWrite()

size_t wxOutputStream::OnSysWrite | ( | const void * | buffer,
|  | size_t | bufsize
| ) |  |

protected

Internal function.

It is called when the stream wants to write data of the specified size bufsize into the given buffer.

It should return the size that was actually wrote (which maybe zero if bufsize is zero or if an error occurred; in this last case the internal variable `m_lasterror` should be appropriately set).

## ◆ PutC()

void wxOutputStream::PutC | ( | char | c | ) |

Puts the specified character in the output queue and increments the stream position.

## ◆ SeekO()

virtual wxFileOffset wxOutputStream::SeekO | ( | wxFileOffset | pos,
|  | wxSeekMode | mode = `wxFromStart`
| ) |  |

virtual

Changes the stream current position.

Parameters

  pos | Offset to seek to.
  mode | One of wxFromStart, wxFromEnd, wxFromCurrent.

Returns
  The new stream position or wxInvalidOffset on error.

Reimplemented in wxBufferedOutputStream.

## ◆ TellO()

virtual wxFileOffset wxOutputStream::TellO | ( |  | ) | const

virtual

Returns the current stream position.

## ◆ Write() [1/2]

virtual wxOutputStream& wxOutputStream::Write | ( | const void * | buffer,
|  | size_t | size
| ) |  |

virtual

Writes up to the specified amount of bytes using the data of buffer.

Note that not all data can always be written so you must check the number of bytes really written to the stream using LastWrite() when this function returns.

In some cases (for example a write end of a pipe which is currently full) it is even possible that there is no errors and zero bytes have been written. This function returns a reference on the current object, so the user can test any states of the stream right away.

## ◆ Write() [2/2]

wxOutputStream& wxOutputStream::Write | ( | wxInputStream & | stream_in | ) |

Reads data from the specified input stream and stores them in the current stream.

The data is read until an error is raised by one of the two streams.

## ◆ WriteAll()

bool wxOutputStream::WriteAll | ( | const void * | buffer,
|  | size_t | size
| ) |  |

Writes exactly the specified number of bytes from the buffer.

Returns true if exactly size bytes were written. Otherwise, returns false and LastWrite() should be used to retrieve the exact amount of the data written if necessary.

This method uses repeated calls to Write() (which may return writing only part of the data) if necessary.

Since
  2.9.5