qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::istream< _IO_ > Class Template Reference

Input stream template class. More...

#include <stream.h>

Inheritance diagram for qb::io::istream< _IO_ >:
Collaboration diagram for qb::io::istream< _IO_ >:

Public Types

using transport_io_type = _IO_
 Type of the underlying transport IO.
using input_buffer_type = qb::allocator::pipe<char>
 Type of the input buffer.

Public Member Functions

 ~istream () noexcept
 Destructor.
_IO_ & transport () noexcept
 Get the underlying transport object.
const _IO_ & transport () const noexcept
 Get the underlying transport object (const version)
input_buffer_typein () noexcept
 Get the input buffer.
std::size_t pendingRead () const noexcept
 Get the number of bytes available for reading.
template<typename Available = void>
int read (std::enable_if_t< has_method_read< _IO_, int, char *, std::size_t >::value, Available > *=nullptr) noexcept
 Read data from the transport into the input buffer.
void flush (std::size_t size) noexcept
 Remove data from the front of the input buffer.
void eof () noexcept
 Handle end-of-file condition.
void close () noexcept
 Close the stream.

Protected Attributes

_IO_ _in
 The underlying IO object.
input_buffer_type _in_buffer
 Buffer for incoming data.

Detailed Description

template<typename _IO_>
class qb::io::istream< _IO_ >

Input stream template class.

This template class provides input stream functionality for various transport implementations. It manages an input buffer and provides methods for reading data from the underlying IO object into the buffer.

Template Parameters
_IO_The IO type that implements the actual transport operations

Constructor & Destructor Documentation

◆ ~istream()

template<typename _IO_>
qb::io::istream< _IO_ >::~istream ( )
inlinenoexcept

Destructor.

Ensures that the stream is closed properly when destroyed.

Member Function Documentation

◆ transport() [1/2]

template<typename _IO_>
_IO_ & qb::io::istream< _IO_ >::transport ( )
inlinenodiscardnoexcept

Get the underlying transport object.

Returns
Reference to the transport object

◆ transport() [2/2]

template<typename _IO_>
const _IO_ & qb::io::istream< _IO_ >::transport ( ) const
inlinenodiscardnoexcept

Get the underlying transport object (const version)

Returns
Const reference to the transport object

◆ in()

template<typename _IO_>
input_buffer_type & qb::io::istream< _IO_ >::in ( )
inlinenodiscardnoexcept

Get the input buffer.

Returns
Reference to the input buffer

◆ pendingRead()

template<typename _IO_>
std::size_t qb::io::istream< _IO_ >::pendingRead ( ) const
inlinenodiscardnoexcept

Get the number of bytes available for reading.

Returns
Number of bytes in the input buffer

◆ read()

template<typename _IO_>
template<typename Available = void>
int qb::io::istream< _IO_ >::read ( std::enable_if_t< has_method_read< _IO_, int, char *, std::size_t >::value, Available > * = nullptr)
inlinenodiscardnoexcept

Read data from the transport into the input buffer.

Returns
Number of bytes read on success, error code on failure

This method is enabled only if the IO type has a compatible read method. It reads data in fixed-size chunks and adjusts the buffer size based on the actual number of bytes read.

◆ flush()

template<typename _IO_>
void qb::io::istream< _IO_ >::flush ( std::size_t size)
inlinenoexcept

Remove data from the front of the input buffer.

Parameters
sizeNumber of bytes to remove

This method is typically called after processing data from the input buffer to free up space.

◆ eof()

template<typename _IO_>
void qb::io::istream< _IO_ >::eof ( )
inlinenoexcept

Handle end-of-file condition.

Resets or reorders the input buffer based on whether it contains data.

◆ close()

template<typename _IO_>
void qb::io::istream< _IO_ >::close ( )
inlinenoexcept

Close the stream.

Resets the input buffer and closes or disconnects the underlying transport, depending on the available methods.