A concrete implementation of OutputStream that performs output operations to an in-memory buffer.
More...
#include <bond/io/memoryoutputstream.h>
|
| | MemoryOutputStream (void *buffer, pos_t size) |
| | Constructs a MemoryOutputStream object and writes a null terminator at the start of the buffer.
|
| virtual | ~MemoryOutputStream () |
| | Destroys a MemoryOutputStream object.
|
| virtual void | VPrint (const char *format, va_list argList) override |
| | Writes formatted output to the buffer followed by a null terminator, which is not counted in the current position. The output is truncated if it does not fit.
|
| virtual void | Write (const uint8_t *bytes, size_t numBytes) override |
| | Writes a sequence of bytes to the stream.
|
| virtual void | Write (uint8_t c) override |
| | Writes a single byte to the stream.
|
| virtual pos_t | GetPosition () const override |
| | Returns the current position within the stream.
|
| virtual pos_t | GetEndPosition () const override |
| | Returns the highest position that has been written to or moved to.
|
| virtual void | SetPosition (off_t offset) override |
| | Sets the current position within the stream, clamped to the range [0, size].
|
| virtual void | SetPositionFromEnd (off_t offset) override |
| | Sets the current position relative to the end of the stream.
|
| virtual void | AddOffset (off_t offset) override |
| | Advances the current position by the given offset.
|
| virtual bool | IsEof () const override |
| | Returns whether the buffer is full.
|
| virtual bool | HasError () const override |
| | Returns false, since a MemoryOutputStream never enters an error state.
|
| virtual void | ClearError () override |
| | Does nothing, since a MemoryOutputStream never enters an error state.
|
| virtual | ~OutputStream () |
| | Destroys an OutputStream object.
|
| virtual void | Flush () |
| | Flushes any buffered output.
|
| virtual void | Print (const char *format,...) |
| | Writes formatted output to the stream.
|
| virtual | ~Stream () |
| | Destroys a Stream object.
|
| virtual void | Close () |
| | Closes the stream.
|
|
| typedef long | pos_t |
| | A type used to represent absolute positions within a stream.
|
| typedef long | off_t |
| | A type used to represent relative offsets within a stream.
|
| static const int | Eof = -1 |
| | A special value returned by single-byte input functions to indicate end of stream.
|
A concrete implementation of OutputStream that performs output operations to an in-memory buffer.
MemoryOutputStream provides a non-owning view over a writable memory buffer and writes data to that buffer without reallocating it. Output that does not fit in the buffer is silently discarded, positions are clamped to the bounds of the buffer, and a MemoryOutputStream never enters an error state.
Formatted output written with Print() or VPrint() is null terminated, so a MemoryOutputStream can be used to format a C-style string. Unformatted output written with Write() is not.
- See also
- MemoryInputStream, OutputStream
◆ MemoryOutputStream()
| Bond::MemoryOutputStream::MemoryOutputStream |
( |
void * | buffer, |
|
|
pos_t | size ) |
Constructs a MemoryOutputStream object and writes a null terminator at the start of the buffer.
- Parameters
-
| buffer | A pointer to the memory buffer to which bytes will be written. The buffer is not copied and must remain valid for the lifetime of the MemoryOutputStream. |
| size | The size of the memory buffer, in bytes. It must be at least 1. |
◆ ~MemoryOutputStream()
| virtual Bond::MemoryOutputStream::~MemoryOutputStream |
( |
| ) |
|
|
inlinevirtual |
◆ AddOffset()
| virtual void Bond::MemoryOutputStream::AddOffset |
( |
off_t | offset | ) |
|
|
overridevirtual |
Advances the current position by the given offset.
- Parameters
-
| offset | The signed amount by which the current position should be adjusted. |
Implements Bond::Stream.
◆ ClearError()
| virtual void Bond::MemoryOutputStream::ClearError |
( |
| ) |
|
|
inlineoverridevirtual |
◆ GetEndPosition()
| virtual pos_t Bond::MemoryOutputStream::GetEndPosition |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the highest position that has been written to or moved to.
Implements Bond::Stream.
◆ GetPosition()
| virtual pos_t Bond::MemoryOutputStream::GetPosition |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the current position within the stream.
- Returns
- The current absolute stream position.
Implements Bond::Stream.
◆ HasError()
| virtual bool Bond::MemoryOutputStream::HasError |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ IsEof()
| virtual bool Bond::MemoryOutputStream::IsEof |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns whether the buffer is full.
Implements Bond::Stream.
◆ SetPosition()
| virtual void Bond::MemoryOutputStream::SetPosition |
( |
off_t | offset | ) |
|
|
overridevirtual |
Sets the current position within the stream, clamped to the range [0, size].
- Parameters
-
| offset | The absolute position to which the stream should be moved. |
Implements Bond::Stream.
◆ SetPositionFromEnd()
| virtual void Bond::MemoryOutputStream::SetPositionFromEnd |
( |
off_t | offset | ) |
|
|
overridevirtual |
Sets the current position relative to the end of the stream.
- Parameters
-
| offset | The offset from the end position to which the stream should be moved, i.e. the new position is GetEndPosition() + offset, so offset is normally zero or negative. |
Implements Bond::Stream.
◆ VPrint()
| virtual void Bond::MemoryOutputStream::VPrint |
( |
const char * | format, |
|
|
va_list | argList ) |
|
overridevirtual |
Writes formatted output to the buffer followed by a null terminator, which is not counted in the current position. The output is truncated if it does not fit.
- Parameters
-
| format | A printf-style format string describing the text to be written. |
| argList | A variable argument list containing the values to be formatted. |
Implements Bond::OutputStream.
◆ Write() [1/2]
| virtual void Bond::MemoryOutputStream::Write |
( |
const uint8_t * | bytes, |
|
|
size_t | numBytes ) |
|
overridevirtual |
Writes a sequence of bytes to the stream.
- Parameters
-
| bytes | The buffer containing the bytes to be written. |
| numBytes | The number of bytes to write. |
Reimplemented from Bond::OutputStream.
◆ Write() [2/2]
| virtual void Bond::MemoryOutputStream::Write |
( |
uint8_t | byte | ) |
|
|
overridevirtual |
The documentation for this class was generated from the following file:
- include/bond/io/memoryoutputstream.h