roo_io
API Documentation for roo_io
Loading...
Searching...
No Matches
roo_io::InputStream Class Referenceabstract

Virtualizes access to files, memory, and other readable sources. More...

#include <input_stream.h>

Inheritance diagram for roo_io::InputStream:
[legend]

Public Member Functions

virtual ~InputStream ()
 
virtual bool isOpen () const
 Returns whether stream is considered open.
 
virtual void close ()
 Closes this stream.
 
virtual size_t read (byte *result, size_t count)=0
 Attempts to read up to count bytes into result.
 
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.
 
virtual void skip (uint64_t count)
 Skips over count bytes, updating status().
 
virtual Status status () const =0
 Returns status of the most recent I/O operation.
 

Detailed Description

Virtualizes access to files, memory, and other readable sources.

Represents an open resource with a read cursor.

For iterator-style usage, prefer BufferedInputStreamIterator to avoid virtual-call overhead per byte.

Definition at line 16 of file input_stream.h.

Constructor & Destructor Documentation

◆ ~InputStream()

virtual roo_io::InputStream::~InputStream ( )
inlinevirtual

Definition at line 18 of file input_stream.h.

References close().

Member Function Documentation

◆ close()

virtual void roo_io::InputStream::close ( )
inlinevirtual

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 in roo_io::NullInputStream, roo_io::MemoryInputStream< PtrType >, and roo_io::RingPipeInputStream.

Definition at line 36 of file input_stream.h.

Referenced by roo_io::InputStreamReader::close(), roo_io::InputStreamReader::reset(), roo_io::InputStreamReader::reset(), ~InputStream(), and roo_io::InputStreamReader::~InputStreamReader().

◆ isOpen()

virtual bool roo_io::InputStream::isOpen ( ) const
inlinevirtual

Returns whether stream is considered open.

Returns
true when status() is kOk or kEndOfStream.

Reimplemented in roo_io::NullInputStream, and roo_io::MemoryInputStream< PtrType >.

Definition at line 23 of file input_stream.h.

References roo_io::kEndOfStream, roo_io::kOk, and status().

◆ read()

virtual size_t roo_io::InputStream::read ( byte result,
size_t  count 
)
pure virtual

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.

Implemented in roo_io::NullInputStream, roo_io::MemoryInputStream< PtrType >, and roo_io::RingPipeInputStream.

Referenced by roo_io::BufferedInputStreamIterator::read(), roo_io::BufferedMultipassInputStreamIterator::read(), roo_io::BufferedInputStreamIterator::read(), roo_io::BufferedMultipassInputStreamIterator::read(), readFully(), skip(), and tryRead().

◆ readFully()

virtual size_t roo_io::InputStream::readFully ( byte buf,
size_t  count 
)
inlinevirtual

Attempts to read count bytes into buf; blocks as needed.

Updates status.

Unlike read(), this method keeps reading until one of the following:

  • count bytes are read,
  • end-of-stream is reached,
  • an error occurs.

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

Returns
Total bytes read.

Definition at line 84 of file input_stream.h.

References roo_io::count, and read().

◆ skip()

virtual void roo_io::InputStream::skip ( uint64_t  count)
inlinevirtual

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 in roo_io::NullInputStream, and roo_io::MemoryInputStream< PtrType >.

Definition at line 107 of file input_stream.h.

References roo_io::count, roo_io::kOk, read(), and status().

Referenced by roo_io::BufferedInputStreamIterator::skip(), and roo_io::BufferedMultipassInputStreamIterator::skip().

◆ status()

◆ tryRead()

virtual size_t roo_io::InputStream::tryRead ( byte result,
size_t  count 
)
inlinevirtual

Attempts to read up to count bytes into result without indefinitely blocking.

Updates status.

Similar to read(), but may return zero on success when no data is currently available without blocking.

The implementation has some leeway for deciding what constitutes unacceptable blocking, as long as it is guaranteed that callers can always make progress by calling tryRead() repeatedly, and never calling read().

Returns
Number of bytes read.

Reimplemented in roo_io::RingPipeInputStream.

Definition at line 67 of file input_stream.h.

References roo_io::count, and read().


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