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

Output stream template class. More...

#include <stream.h>

Collaboration diagram for qb::io::ostream< _IO_ >:

Public Types

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

Public Member Functions

 ~ostream () noexcept
 Destructor.
_IO_ & transport () noexcept
 Get the underlying transport object.
const _IO_ & transport () const noexcept
 Get the underlying transport object (const version)
output_buffer_typeout () noexcept
 Get the output buffer.
std::size_t pendingWrite () const noexcept
 Get the number of bytes pending for writing.
template<typename Available = void>
int write (std::enable_if_t< has_method_write< _IO_, int, const char *, std::size_t >::value, Available > *=nullptr) noexcept
 Write data from the output buffer to the transport.
char * publish (char const *data, std::size_t size) noexcept
 Add data to the output buffer for later writing.
void close () noexcept
 Close the stream.

Protected Attributes

_IO_ _out
 The underlying IO object.
output_buffer_type _out_buffer
 Buffer for outgoing data.

Detailed Description

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

Output stream template class.

This template class provides output stream functionality for various transport implementations. It manages an output buffer and provides methods for writing data from the buffer to the underlying IO object.

Template Parameters
_IO_The IO type that implements the actual transport operations

Constructor & Destructor Documentation

◆ ~ostream()

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

Destructor.

Ensures that the stream is closed properly when destroyed.

Member Function Documentation

◆ transport() [1/2]

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

Get the underlying transport object.

Returns
Reference to the transport object

◆ transport() [2/2]

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

Get the underlying transport object (const version)

Returns
Const reference to the transport object

◆ out()

template<typename _IO_>
output_buffer_type & qb::io::ostream< _IO_ >::out ( )
inlinenodiscardnoexcept

Get the output buffer.

Returns
Reference to the output buffer

◆ pendingWrite()

template<typename _IO_>
std::size_t qb::io::ostream< _IO_ >::pendingWrite ( ) const
inlinenodiscardnoexcept

Get the number of bytes pending for writing.

Returns
Number of bytes in the output buffer

◆ write()

template<typename _IO_>
template<typename Available = void>
int qb::io::ostream< _IO_ >::write ( std::enable_if_t< has_method_write< _IO_, int, const char *, std::size_t >::value, Available > * = nullptr)
inlinenodiscardnoexcept

Write data from the output buffer to the transport.

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

This method is enabled only if the IO type has a compatible write method. It writes the entire buffer content and adjusts or resets the buffer based on the actual number of bytes written.

◆ publish()

template<typename _IO_>
char * qb::io::ostream< _IO_ >::publish ( char const * data,
std::size_t size )
inlinenoexcept

Add data to the output buffer for later writing.

Parameters
dataPointer to the data to add
sizeSize of the data to add
Returns
Pointer to the copied data in the output buffer

Copies the specified data to the output buffer for later transmission by the write method.

◆ close()

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

Close the stream.

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