StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ suite.
Loading...
Searching...
No Matches
bridge.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Buffer.
5 *
6 * StormByte-Buffer is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Buffer is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Buffer. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
24
29namespace StormByte::Buffer {
69 public:
83 inline Bridge(const ExternalReader& in,
84 const ExternalWriter& out,
85 std::size_t chunk_size = 4096) noexcept
86 : m_buffer()
87 , m_read_handler(in.Clone())
88 , m_write_handler(out.Clone())
89 , m_chunk_size(chunk_size)
90 {}
91
99 ExternalWriter&& out,
100 std::size_t chunk_size = 4096) noexcept
101 : m_buffer()
102 , m_read_handler(in.Move())
103 , m_write_handler(out.Move())
104 , m_chunk_size(chunk_size)
105 {}
106
110 Bridge(const Bridge&) = delete;
111
115 Bridge(Bridge&&) noexcept = default;
116
121 inline ~Bridge() noexcept {
122 Flush();
123 }
124
128 Bridge& operator=(const Bridge&) = delete;
129
133 Bridge& operator=(Bridge&&) noexcept = default;
134
146 inline std::size_t ChunkSize() const noexcept {
147 return m_chunk_size;
148 }
149
154 inline std::size_t PendingBytes() const noexcept {
155 return m_buffer.Size();
156 }
157
162 inline bool EoF() const noexcept {
163 return m_read_handler->EoF();
164 }
165
170 inline bool IsReadable() const noexcept {
171 return m_read_handler->IsReadable();
172 }
173
178 inline bool IsWritable() const noexcept {
179 return m_write_handler->IsWritable();
180 }
181
194 bool Flush() const noexcept;
195
202 bool FlushAndClose() const noexcept;
203
209 void SetError() const noexcept;
210
228 bool Passthrough(std::size_t bytes) const noexcept;
229
239 bool Passthrough(std::size_t bytes) noexcept;
240
243 private:
244 mutable FIFO m_buffer;
245 ExternalReader::PointerType m_read_handler;
246 ExternalWriter::PointerType m_write_handler;
247 std::size_t m_chunk_size;
248
257 bool PassthroughWrite(DataType&& data) const noexcept;
258 };
259}
Pass-through adapter that forwards bytes from an ExternalReader to an ExternalWriter in fixed-size ch...
Definition bridge.hxx:68
bool Flush() const noexcept
Flush any pending bytes to the writer.
bool IsWritable() const noexcept
Check whether the sink still accepts writes.
Definition bridge.hxx:178
Bridge & operator=(Bridge &&) noexcept=default
Move assignment.
bool EoF() const noexcept
Check whether the source has reached end-of-stream.
Definition bridge.hxx:162
Bridge(ExternalReader &&in, ExternalWriter &&out, std::size_t chunk_size=4096) noexcept
Construct a Bridge by moving the supplied handlers.
Definition bridge.hxx:98
Bridge(const Bridge &)=delete
Copy constructor (deleted – Bridge is non-copyable).
std::size_t PendingBytes() const noexcept
Number of bytes currently waiting in the internal buffer.
Definition bridge.hxx:154
bool IsReadable() const noexcept
Check whether the source is still readable.
Definition bridge.hxx:170
Bridge(const ExternalReader &in, const ExternalWriter &out, std::size_t chunk_size=4096) noexcept
Construct a Bridge by cloning the supplied handlers.
Definition bridge.hxx:83
Bridge(Bridge &&) noexcept=default
Move constructor.
Bridge & operator=(const Bridge &)=delete
Copy assignment (deleted – Bridge is non-copyable).
Abstract interface for reading data from an external or internal source.
Definition external.hxx:55
Abstract interface for writing data to an external or internal sink.
Definition external.hxx:284
Byte-oriented FIFO buffer with grow-on-demand and close/error support.
Definition fifo.hxx:58
Buffer module of the StormByte suite.
std::vector< std::byte > DataType
Primary byte storage type used throughout the buffer API.
Definition typedefs.hxx:62
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:28