roo_io
API Documentation for roo_io
Loading...
Searching...
No Matches
roo_io::MemoryInputStream< PtrType > Class Template Reference

#include <memory_input_stream.h>

Inheritance diagram for roo_io::MemoryInputStream< PtrType >:
[legend]
Collaboration diagram for roo_io::MemoryInputStream< PtrType >:
[legend]

Public Member Functions

 MemoryInputStream ()
 
 MemoryInputStream (PtrType begin, PtrType end)
 
bool isOpen () const override
 Returns whether stream is considered open.
 
size_t read (byte *buf, size_t count) override
 Attempts to read up to count bytes into result.
 
void skip (uint64_t count) override
 Skips over count bytes, updating status().
 
uint64_t position () const override
 Returns current byte offset from beginning of stream.
 
void seek (uint64_t position) override
 Seeks to byte offset from beginning.
 
uint64_t size () override
 Returns stream size in bytes from beginning.
 
void close () override
 Closes this stream.
 
Status status () const override
 Returns status of the most recent I/O operation.
 
- Public Member Functions inherited from roo_io::MultipassInputStream
virtual void rewind ()
 Resets stream to starting position.
 
- Public Member Functions inherited from roo_io::InputStream
virtual ~InputStream ()
 
virtual size_t tryRead (byte *result, size_t count)
 Attempts to read up to count bytes into result without indefinitely blocking.
 
virtual size_t readFully (byte *buf, size_t count)
 Attempts to read count bytes into buf; blocks as needed.
 

Detailed Description

template<typename PtrType>
class roo_io::MemoryInputStream< PtrType >

Definition at line 8 of file memory_input_stream.h.

Constructor & Destructor Documentation

◆ MemoryInputStream() [1/2]

template<typename PtrType >
roo_io::MemoryInputStream< PtrType >::MemoryInputStream ( )
inline

Definition at line 10 of file memory_input_stream.h.

◆ MemoryInputStream() [2/2]

template<typename PtrType >
roo_io::MemoryInputStream< PtrType >::MemoryInputStream ( PtrType  begin,
PtrType  end 
)
inline

Definition at line 13 of file memory_input_stream.h.

Member Function Documentation

◆ close()

template<typename PtrType >
void roo_io::MemoryInputStream< PtrType >::close ( )
inlineoverridevirtual

Closes this stream.

Updates status.

If previous status was kOk or kEndOfStream, status transitions to kClosed.

After close, read operations should return zero bytes.

Reimplemented from roo_io::InputStream.

Definition at line 57 of file memory_input_stream.h.

References roo_io::MemoryInputStream< PtrType >::isOpen(), and roo_io::kClosed.

◆ isOpen()

template<typename PtrType >
bool roo_io::MemoryInputStream< PtrType >::isOpen ( ) const
inlineoverridevirtual

Returns whether stream is considered open.

Returns
true when status() is kOk or kEndOfStream.

Reimplemented from roo_io::InputStream.

Definition at line 16 of file memory_input_stream.h.

References roo_io::kEndOfStream, and roo_io::kOk.

Referenced by roo_io::MemoryInputStream< PtrType >::close(), and roo_io::MemoryInputStream< PtrType >::seek().

◆ position()

template<typename PtrType >
uint64_t roo_io::MemoryInputStream< PtrType >::position ( ) const
inlineoverridevirtual

Returns current byte offset from beginning of stream.

If status is neither kOk nor kEndOfStream, return value is unspecified.

Implements roo_io::MultipassInputStream.

Definition at line 47 of file memory_input_stream.h.

Referenced by roo_io::MemoryInputStream< PtrType >::seek().

◆ read()

template<typename PtrType >
size_t roo_io::MemoryInputStream< PtrType >::read ( byte result,
size_t  count 
)
inlineoverridevirtual

Attempts to read up to count bytes into result.

Updates status.

Contract:

  • On success (status() == kOk), returns at least one byte.
  • On end-of-stream (status() == kEndOfStream), returns zero.
  • On error, may return zero or number of bytes read before failure.

If status before call is not kOk, leaves it unchanged and returns zero.

Implementations may return fewer than count bytes even when more data is available. Use readFully() if that is not the desired behavior.

Returns
Number of bytes read.

Implements roo_io::InputStream.

Definition at line 20 of file memory_input_stream.h.

References roo_io::count, roo_io::kEndOfStream, and roo_io::kOk.

◆ seek()

template<typename PtrType >
void roo_io::MemoryInputStream< PtrType >::seek ( uint64_t  offset)
inlineoverridevirtual

Seeks to byte offset from beginning.

Offset may be greater than current size().

If pre-call status is neither kOk nor kEndOfStream, status is unchanged.

On success, status becomes kOk and position() equals offset. On error, status updates accordingly.

Implements roo_io::MultipassInputStream.

Definition at line 49 of file memory_input_stream.h.

References roo_io::MemoryInputStream< PtrType >::isOpen(), roo_io::kOk, and roo_io::MemoryInputStream< PtrType >::position().

◆ size()

template<typename PtrType >
uint64_t roo_io::MemoryInputStream< PtrType >::size ( )
inlineoverridevirtual

Returns stream size in bytes from beginning.

Value may differ across calls when underlying source mutates.

If pre-call status is neither kOk nor kEndOfStream, status is unchanged and return value is 0.

On error, status updates accordingly and return value is 0.

Implements roo_io::MultipassInputStream.

Definition at line 55 of file memory_input_stream.h.

◆ skip()

template<typename PtrType >
void roo_io::MemoryInputStream< PtrType >::skip ( uint64_t  count)
inlineoverridevirtual

Skips over count bytes, updating status().

Conceptually equivalent to readFully(tmp, count) and discarding data.

If pre-call status is not kOk, leaves status unchanged and returns.

If skip ends exactly at stream end, status remains kOk. If skip ends before stream end, status remains kOk. If skip crosses stream end, status becomes kEndOfStream.

Any I/O error updates status accordingly.

Reimplemented from roo_io::InputStream.

Definition at line 34 of file memory_input_stream.h.

References roo_io::count, roo_io::kEndOfStream, and roo_io::kOk.

◆ status()

template<typename PtrType >
Status roo_io::MemoryInputStream< PtrType >::status ( ) const
inlineoverridevirtual

Returns status of the most recent I/O operation.

Implements roo_io::InputStream.

Definition at line 63 of file memory_input_stream.h.


The documentation for this class was generated from the following file: