Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::MemoryOutputStream Class Reference

A concrete implementation of OutputStream that performs output operations to an in-memory buffer. More...

#include <bond/io/memoryoutputstream.h>

Inheritance diagram for Bond::MemoryOutputStream:
Bond::OutputStream Bond::Stream

Public Member Functions

 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.
Public Member Functions inherited from Bond::OutputStream
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.
Public Member Functions inherited from Bond::Stream
virtual ~Stream ()
 Destroys a Stream object.
virtual void Close ()
 Closes the stream.

Additional Inherited Members

Public Types inherited from Bond::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 Public Attributes inherited from Bond::Stream
static const int Eof = -1
 A special value returned by single-byte input functions to indicate end of stream.

Detailed Description

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

Constructor & Destructor Documentation

◆ 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
bufferA 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.
sizeThe size of the memory buffer, in bytes. It must be at least 1.

◆ ~MemoryOutputStream()

virtual Bond::MemoryOutputStream::~MemoryOutputStream ( )
inlinevirtual

Destroys a MemoryOutputStream object.

Member Function Documentation

◆ AddOffset()

virtual void Bond::MemoryOutputStream::AddOffset ( off_t offset)
overridevirtual

Advances the current position by the given offset.

Parameters
offsetThe signed amount by which the current position should be adjusted.

Implements Bond::Stream.

◆ ClearError()

virtual void Bond::MemoryOutputStream::ClearError ( )
inlineoverridevirtual

Does nothing, since a MemoryOutputStream never enters an error state.

Implements Bond::Stream.

◆ 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

Returns false, since a MemoryOutputStream never enters an error state.

Implements Bond::Stream.

◆ 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
offsetThe 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
offsetThe 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
formatA printf-style format string describing the text to be written.
argListA 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
bytesThe buffer containing the bytes to be written.
numBytesThe number of bytes to write.

Reimplemented from Bond::OutputStream.

◆ Write() [2/2]

virtual void Bond::MemoryOutputStream::Write ( uint8_t byte)
overridevirtual

Writes a single byte to the stream.

Parameters
byteThe byte to write.

Implements Bond::OutputStream.


The documentation for this class was generated from the following file:
  • include/bond/io/memoryoutputstream.h