31#ifndef QB_IO_STREAM_H_
32#define QB_IO_STREAM_H_
48template <
typename _IO_>
84 [[nodiscard]]
const _IO_ &
102 [[nodiscard]] std::size_t
115 template <
typename Available =
void>
117 read(std::enable_if_t<has_method_read<_IO_, int, char *, std::size_t>::value,
118 Available> * =
nullptr) noexcept {
119 static constexpr const std::size_t bucket_read = 8192;
120 const auto ret =
_in.read(
_in_buffer.allocate_back(bucket_read), bucket_read);
160 if constexpr (has_member_func_disconnect<_IO_>::value)
176template <
typename _IO_>
212 [[nodiscard]]
const _IO_ &
230 [[nodiscard]] std::size_t
243 template <
typename Available =
void>
245 write(std::enable_if_t<has_method_write<_IO_, int, const char *, std::size_t>::value,
246 Available> * =
nullptr) noexcept {
270 publish(
char const *data, std::size_t size)
noexcept {
271 return static_cast<char *
>(
272 std::memcpy(
_out_buffer.allocate_back(size), data, size));
284 if constexpr (has_member_func_disconnect<_IO_>::value)
302template <
typename _IO_>
336 [[nodiscard]] std::size_t
352 template <
typename Available =
void>
354 write(std::enable_if_t<has_method_write<_IO_, int, const char *, std::size_t>::value,
355 Available> * =
nullptr) noexcept {
358 if (
static_cast<std::size_t
>(ret) !=
_out_buffer.size()) {
377 publish(
char const *data, std::size_t size)
noexcept {
378 return static_cast<char *
>(
379 std::memcpy(
_out_buffer.allocate_back(size), data, size));
Extensible buffer optimized for performance.
Definition pipe.h:552
Input stream template class.
Definition stream.h:49
input_buffer_type _in_buffer
Buffer for incoming data.
Definition stream.h:59
void flush(std::size_t size) noexcept
Remove data from the front of the input buffer.
Definition stream.h:134
std::size_t pendingRead() const noexcept
Get the number of bytes available for reading.
Definition stream.h:103
const _IO_ & transport() const noexcept
Get the underlying transport object (const version)
Definition stream.h:85
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.
Definition stream.h:117
input_buffer_type & in() noexcept
Get the input buffer.
Definition stream.h:94
void close() noexcept
Close the stream.
Definition stream.h:158
_IO_ transport_io_type
Type of the underlying transport IO.
Definition stream.h:52
_IO_ _in
The underlying IO object.
Definition stream.h:58
qb::allocator::pipe< char > input_buffer_type
Type of the input buffer.
Definition stream.h:55
void eof() noexcept
Handle end-of-file condition.
Definition stream.h:144
_IO_ & transport() noexcept
Get the underlying transport object.
Definition stream.h:76
~istream() noexcept
Destructor.
Definition stream.h:67
Output stream template class.
Definition stream.h:177
const _IO_ & transport() const noexcept
Get the underlying transport object (const version)
Definition stream.h:213
_IO_ _out
The underlying IO object.
Definition stream.h:186
std::size_t pendingWrite() const noexcept
Get the number of bytes pending for writing.
Definition stream.h:231
void close() noexcept
Close the stream.
Definition stream.h:282
_IO_ & transport() noexcept
Get the underlying transport object.
Definition stream.h:204
char * publish(char const *data, std::size_t size) noexcept
Add data to the output buffer for later writing.
Definition stream.h:270
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.
Definition stream.h:245
output_buffer_type _out_buffer
Buffer for outgoing data.
Definition stream.h:187
qb::allocator::pipe< char > output_buffer_type
Type of the output buffer.
Definition stream.h:183
output_buffer_type & out() noexcept
Get the output buffer.
Definition stream.h:222
_IO_ transport_io_type
Type of the underlying transport IO.
Definition stream.h:180
~ostream() noexcept
Destructor.
Definition stream.h:195
Combined input/output stream template class.
Definition stream.h:303
void close() noexcept
Close the stream.
Definition stream.h:388
std::size_t pendingWrite() const noexcept
Get the number of bytes pending for writing.
Definition stream.h:337
qb::allocator::pipe< char > output_buffer_type
Type of the output buffer.
Definition stream.h:309
output_buffer_type & out() noexcept
Get the output buffer.
Definition stream.h:328
_IO_ transport_io_type
Type of the underlying transport IO.
Definition stream.h:306
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.
Definition stream.h:354
char * publish(char const *data, std::size_t size) noexcept
Add data to the output buffer for later writing.
Definition stream.h:377
output_buffer_type _out_buffer
Definition stream.h:320
static constexpr const bool has_reset_on_pending_read
Definition stream.h:317
Implementation of a dynamic extensible buffer.
Advanced type traits and metaprogramming utilities for the QB Framework.