wxWidgets: wxStreamBuffer Class Reference

| Version: 3.1.5

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
wxStreamBuffer Class Reference
Class List by Category » Streams

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.1/wxWidgets3.1-3.1.5-4.x86_64/src/wxWidgets-3.1.5/interface/wx/stream.h>`

## Detailed Description

wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer linked to a stream.

Each stream always has one autoinitialized stream buffer, but you may attach more of them to the same stream.

##

Library: wxBase

<>< =''>:</>&;&;< =''>\ </></>

See also
  wxStreamBase, Stream Classes Overview

## Public Types
enum | BufMode { read , write , read_write }
| BufMode flags. More...

## Public Member Functions
| wxStreamBuffer (wxStreamBase &stream, BufMode mode)
| Constructor, creates a new stream buffer using stream as a parent stream and mode as the IO mode.
| wxStreamBuffer (size_t bufsize, wxInputStream &stream)
| Constructor for an input buffer of the specified size.
| wxStreamBuffer (size_t bufsize, wxOutputStream &stream)
| Constructor for an output buffer of the specified size.
| wxStreamBuffer (BufMode mode)
| Constructor; creates a new empty stream buffer which won't flush any data to a stream.
| wxStreamBuffer (const wxStreamBuffer &buffer)
| Copy constructor.
| ~wxStreamBuffer ()
| Destructor.
bool | FillBuffer ()
| Fill the IO buffer.
void | Fixed (bool fixed)
| Toggles the fixed flag.
bool | FlushBuffer ()
| Flushes the IO buffer.
void | Flushable (bool flushable)
| Toggles the flushable flag.
void * | GetBufferEnd () const
| Returns a pointer on the end of the stream buffer.
void * | GetBufferPos () const
| Returns a pointer on the current position of the stream buffer.
size_t | GetBufferSize () const
| Returns the size of the buffer.
void * | GetBufferStart () const
| Returns a pointer on the start of the stream buffer.
virtual char | GetChar ()
| Gets a single char from the stream buffer.
size_t | GetDataLeft ()
| Returns the amount of available data in the buffer.
size_t | GetIntPosition () const
| Returns the current position (counted in bytes) in the stream buffer.
size_t | GetLastAccess () const
| Returns the amount of bytes read during the last IO call to the parent stream.
virtual void | PutChar (char c)
| Puts a single char to the stream buffer.
virtual size_t | Read (void *buffer, size_t size)
| Reads a block of the specified size and stores the data in buffer.
size_t | Read (wxStreamBuffer *buffer)
| Copies data to buffer.
void | ResetBuffer ()
| Resets to the initial state variables concerning the buffer.
virtual wxFileOffset | Seek (wxFileOffset pos, wxSeekMode mode)
| Changes the current position.
void | SetBufferIO (void *start, void *end, bool takeOwnership=false)
| Specifies which pointers to use for stream buffering.
void | SetBufferIO (size_t bufsize)
| Destroys or invalidates the previous IO buffer and allocates a new one of the specified size.
void | SetIntPosition (size_t pos)
| Sets the current position (in bytes) in the stream buffer.
wxStreamBase * | Stream ()
| Returns the parent stream of the stream buffer.
virtual wxFileOffset | Tell () const
| Gets the current position in the stream.
void | Truncate ()
| Truncates the buffer to the current position.
virtual size_t | Write (const void *buffer, size_t size)
| Writes a block of the specified size using data of buffer.
size_t | Write (wxStreamBuffer *buffer)
| See Read().

## Member Enumeration Documentation

## ◆ BufMode

enum wxStreamBuffer::BufMode

BufMode flags.

Enumerator
read |
write |
read_write |

## Constructor & Destructor Documentation

## ◆ wxStreamBuffer() [1/5]

wxStreamBuffer::wxStreamBuffer | ( | wxStreamBase & | stream,
|  | BufMode | mode )

Constructor, creates a new stream buffer using stream as a parent stream and mode as the IO mode.

Parameters

  stream | The parent stream.
  mode | Can be: wxStreamBuffer::read, wxStreamBuffer::write, wxStreamBuffer::read_write.

One stream can have many stream buffers but only one is used internally to pass IO call (e.g. wxInputStream::Read() -> wxStreamBuffer::Read()), but you can call directly wxStreamBuffer::Read without any problems. Note that all errors and messages linked to the stream are stored in the stream, not the stream buffers:

streambuffer.Read(...);
streambuffer2.Read(...);
// This call erases previous error messages set by 'streambuffer'
// assuming that both instances are stream buffers for the same stream

See also
  SetBufferIO()

## ◆ wxStreamBuffer() [2/5]

wxStreamBuffer::wxStreamBuffer | ( | size_t | bufsize,
|  | wxInputStream & | stream )

Constructor for an input buffer of the specified size.

Using it is equivalent to using the constructor above with read mode and calling SetBufferIO() but is more convenient.

Since
  2.9.0

Parameters

  bufsize | The size of buffer in bytes.
  stream | The associated input stream, the buffer will be used in read mode.

## ◆ wxStreamBuffer() [3/5]

wxStreamBuffer::wxStreamBuffer | ( | size_t | bufsize,
|  | wxOutputStream & | stream )

Constructor for an output buffer of the specified size.

Using it is equivalent to using the constructor above with write mode and calling SetBufferIO() but is more convenient.

Since
  2.9.0

Parameters

  bufsize | The size of buffer in bytes.
  stream | The associated output stream, the buffer will be used in write mode.

## ◆ wxStreamBuffer() [4/5]

wxStreamBuffer::wxStreamBuffer | ( | BufMode | mode | ) |

Constructor; creates a new empty stream buffer which won't flush any data to a stream.

mode specifies the type of the buffer (read, write, read_write).

This stream buffer has the advantage to be stream independent and to work only on memory buffers but it is still compatible with the rest of the wxStream classes. You can write, read to this special stream and it will grow (if it is allowed by the user) its internal buffer. Briefly, it has all functionality of a "normal" stream.

Warning
  The "read_write" mode doesn't currently work for standalone stream buffers.

See also
  SetBufferIO()

## ◆ wxStreamBuffer() [5/5]

wxStreamBuffer::wxStreamBuffer | ( | const wxStreamBuffer & | buffer | ) |

Copy constructor.

This method initializes the stream buffer with the data of the specified stream buffer. The new stream buffer has the same attributes, size, position and they share the same buffer. This will cause problems if the stream to which the stream buffer belong is destroyed and the newly cloned stream buffer continues to be used, trying to call functions in the (destroyed) stream. It is advised to use this feature only in very local area of the program.

## ◆ ~wxStreamBuffer()

wxStreamBuffer::~wxStreamBuffer | ( |  | ) |

Destructor.

It finalizes all IO calls and frees all internal buffers if necessary.

## Member Function Documentation

## ◆ FillBuffer()

bool wxStreamBuffer::FillBuffer | ( |  | ) |

Fill the IO buffer.

## ◆ Fixed()

void wxStreamBuffer::Fixed | ( | bool | fixed | ) |

Toggles the fixed flag.

Usually this flag is toggled at the same time as flushable. This flag allows (when it has the false value) or forbids (when it has the true value) the stream buffer to resize dynamically the IO buffer.

See also
  SetBufferIO()

## ◆ Flushable()

void wxStreamBuffer::Flushable | ( | bool | flushable | ) |

Toggles the flushable flag.

If flushable is disabled, no data are sent to the parent stream.

## ◆ FlushBuffer()

bool wxStreamBuffer::FlushBuffer | ( |  | ) |

Flushes the IO buffer.

## ◆ GetBufferEnd()

void * wxStreamBuffer::GetBufferEnd | ( |  | ) | const

Returns a pointer on the end of the stream buffer.

## ◆ GetBufferPos()

void * wxStreamBuffer::GetBufferPos | ( |  | ) | const

Returns a pointer on the current position of the stream buffer.

## ◆ GetBufferSize()

size_t wxStreamBuffer::GetBufferSize | ( |  | ) | const

Returns the size of the buffer.

## ◆ GetBufferStart()

void * wxStreamBuffer::GetBufferStart | ( |  | ) | const

Returns a pointer on the start of the stream buffer.

## ◆ GetChar()

virtual char wxStreamBuffer::GetChar | ( |  | ) |
| virtual

Gets a single char from the stream buffer.

It acts like the Read() call.

Warning
  You aren't directly notified if an error occurred during the IO call.

See also
  Read()

## ◆ GetDataLeft()

size_t wxStreamBuffer::GetDataLeft | ( |  | ) |

Returns the amount of available data in the buffer.

## ◆ GetIntPosition()

size_t wxStreamBuffer::GetIntPosition | ( |  | ) | const

Returns the current position (counted in bytes) in the stream buffer.

## ◆ GetLastAccess()

size_t wxStreamBuffer::GetLastAccess | ( |  | ) | const

Returns the amount of bytes read during the last IO call to the parent stream.

## ◆ PutChar()

virtual void wxStreamBuffer::PutChar | ( | char | c | ) |
| virtual

Puts a single char to the stream buffer.

Warning
  You aren't directly notified if an error occurred during the IO call.

See also
  Read()

## ◆ Read() [1/2]

virtual size_t wxStreamBuffer::Read | ( | void * | buffer,
|  | size_t | size )
| virtual

Reads a block of the specified size and stores the data in buffer.

This function tries to read from the buffer first and if more data has been requested, reads more data from the associated stream and updates the buffer accordingly until all requested data is read.

Returns
  It returns the size of the data read. If the returned size is different of the specified size, an error has occurred and should be tested using GetLastError().

## ◆ Read() [2/2]

size_t wxStreamBuffer::Read | ( | wxStreamBuffer * | buffer | ) |

Copies data to buffer.

The function returns when buffer is full or when there isn't any more data in the current buffer.

See also
  Write()

## ◆ ResetBuffer()

void wxStreamBuffer::ResetBuffer | ( |  | ) |

Resets to the initial state variables concerning the buffer.

## ◆ Seek()

virtual wxFileOffset wxStreamBuffer::Seek | ( | wxFileOffset | pos,
|  | wxSeekMode | mode )
| virtual

Changes the current position.

Parameter mode may be one of the following:

- wxFromStart: The position is counted from the start of the stream.
- wxFromCurrent: The position is counted from the current position of the stream.
- wxFromEnd: The position is counted from the end of the stream.

Returns
  Upon successful completion, it returns the new offset as measured in bytes from the beginning of the stream. Otherwise, it returns wxInvalidOffset.

## ◆ SetBufferIO() [1/2]

void wxStreamBuffer::SetBufferIO | ( | size_t | bufsize | ) |

Destroys or invalidates the previous IO buffer and allocates a new one of the specified size.

Warning
  All previous pointers aren't valid anymore.

Remarks
  The created IO buffer is growable by the object.

See also
  Fixed(), Flushable()

## ◆ SetBufferIO() [2/2]

void wxStreamBuffer::SetBufferIO | ( | void * | start,
|  | void * | end,
|  | bool | takeOwnership = false )

Specifies which pointers to use for stream buffering.

You need to pass a pointer on the start of the buffer end and another on the end. The object will use this buffer to cache stream data. It may be used also as a source/destination buffer when you create an empty stream buffer (See wxStreamBuffer::wxStreamBuffer).

Remarks
  When you use this function, you will have to destroy the IO buffers yourself after the stream buffer is destroyed or don't use it anymore. In the case you use it with an empty buffer, the stream buffer will not resize it when it is full.

See also
  wxStreamBuffer(), Fixed(), Flushable()

## ◆ SetIntPosition()

void wxStreamBuffer::SetIntPosition | ( | size_t | pos | ) |

Sets the current position (in bytes) in the stream buffer.

Warning
  Since it is a very low-level function, there is no check on the position: specifying an invalid position can induce unexpected results.

## ◆ Stream()

wxStreamBase * wxStreamBuffer::Stream | ( |  | ) |

Returns the parent stream of the stream buffer.

Deprecated
  use GetStream() instead

## ◆ Tell()

virtual wxFileOffset wxStreamBuffer::Tell | ( |  | ) | const
| virtual

Gets the current position in the stream.

This position is calculated from the real position in the stream and from the internal buffer position: so it gives you the position in the real stream counted from the start of the stream.

Returns
  Returns the current position in the stream if possible, wxInvalidOffset in the other case.

## ◆ Truncate()

void wxStreamBuffer::Truncate | ( |  | ) |

Truncates the buffer to the current position.

Note
  Truncate() cannot be used to enlarge the buffer. This is usually not needed since the buffer expands automatically.

## ◆ Write() [1/2]

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

Writes a block of the specified size using data of buffer.

The data are cached in a buffer before being sent in one block to the stream.

## ◆ Write() [2/2]

size_t wxStreamBuffer::Write | ( | wxStreamBuffer * | buffer | ) |

See Read().