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

A concrete implementation of InputStream that performs input operations from an in-memory buffer. More...

#include <bond/io/memoryinputstream.h>

Inheritance diagram for Bond::MemoryInputStream:
Bond::InputStream Bond::Stream

Public Member Functions

 MemoryInputStream (const void *buffer, pos_t size)
 Constructs a MemoryInputStream object.
virtual ~MemoryInputStream ()
 Destroys a MemoryInputStream object.
virtual void VScan (const char *format, va_list argList) override
 Not implemented. Always throws a Bond::Exception.
virtual size_t Read (uint8_t *bytes, size_t numBytes) override
 Reads a sequence of bytes from the stream.
virtual int Read () override
 Reads a single byte from the stream.
virtual pos_t GetPosition () const override
 Returns the current position within the stream.
virtual pos_t GetEndPosition () const override
 Returns the size of the memory buffer.
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
 Tests whether the current position is at or beyond the end of the stream.
virtual bool HasError () const override
 Returns false, since a MemoryInputStream never enters an error state.
virtual void ClearError () override
 Does nothing, since a MemoryInputStream never enters an error state.
Public Member Functions inherited from Bond::InputStream
virtual ~InputStream ()
 Destroys an InputStream object.
virtual void Scan (const char *format,...)
 Reads formatted input from the stream.
size_t Read (char *bytes, size_t numBytes)
 Reads a sequence of bytes from the stream into a character buffer.
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 InputStream that performs input operations from an in-memory buffer.

MemoryInputStream provides a non-owning view over a contiguous block of memory and reads data from that buffer without copying it. Positions are clamped to the bounds of the buffer, and a MemoryInputStream never enters an error state.

See also
InputStream, MemoryOutputStream

Constructor & Destructor Documentation

◆ MemoryInputStream()

Bond::MemoryInputStream::MemoryInputStream ( const void * buffer,
pos_t size )

Constructs a MemoryInputStream object.

Parameters
bufferA pointer to the memory buffer from which bytes will be read. The buffer is not copied and must remain valid for the lifetime of the MemoryInputStream.
sizeThe size of the memory buffer, in bytes.

◆ ~MemoryInputStream()

virtual Bond::MemoryInputStream::~MemoryInputStream ( )
inlinevirtual

Destroys a MemoryInputStream object.

Member Function Documentation

◆ AddOffset()

virtual void Bond::MemoryInputStream::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::MemoryInputStream::ClearError ( )
inlineoverridevirtual

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

Implements Bond::Stream.

◆ GetEndPosition()

virtual pos_t Bond::MemoryInputStream::GetEndPosition ( ) const
inlineoverridevirtual

Returns the size of the memory buffer.

Implements Bond::Stream.

◆ GetPosition()

virtual pos_t Bond::MemoryInputStream::GetPosition ( ) const
inlineoverridevirtual

Returns the current position within the stream.

Returns
The current absolute stream position.

Implements Bond::Stream.

◆ HasError()

virtual bool Bond::MemoryInputStream::HasError ( ) const
inlineoverridevirtual

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

Implements Bond::Stream.

◆ IsEof()

virtual bool Bond::MemoryInputStream::IsEof ( ) const
inlineoverridevirtual

Tests whether the current position is at or beyond the end of the stream.

Returns
True if no more data can be read or written at the current position.

Implements Bond::Stream.

◆ Read() [1/2]

virtual int Bond::MemoryInputStream::Read ( )
overridevirtual

Reads a single byte from the stream.

Returns
The next byte in the stream, or Stream::Eof if the end of the stream is reached.

Implements Bond::InputStream.

◆ Read() [2/2]

virtual size_t Bond::MemoryInputStream::Read ( uint8_t * bytes,
size_t numBytes )
overridevirtual

Reads a sequence of bytes from the stream.

Parameters
bytesThe destination buffer where the bytes will be written.
numBytesThe maximum number of bytes to read.
Returns
The number of bytes actually read from the stream.

Reimplemented from Bond::InputStream.

◆ SetPosition()

virtual void Bond::MemoryInputStream::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::MemoryInputStream::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.

◆ VScan()

virtual void Bond::MemoryInputStream::VScan ( const char * format,
va_list argList )
overridevirtual

Not implemented. Always throws a Bond::Exception.

Implements Bond::InputStream.


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