StormByte C++ Library: Buffer module 0.0.9999
StormByte-Buffer is a StormByte library module for handling buffers
Loading...
Searching...
No Matches
bridge.hxx
1#pragma once
2
3#include <StormByte/buffer/external.hxx>
4#include <StormByte/buffer/fifo.hxx>
5
14namespace StormByte::Buffer {
52 class STORMBYTE_BUFFER_PUBLIC Bridge {
53 public:
61 inline Bridge(const ExternalReader& in, const ExternalWriter& out, std::size_t chunk_size = 4096) noexcept:
62 m_buffer(),
63 m_read_handler(in.Clone()),
64 m_write_handler(out.Clone()),
65 m_chunk_size(chunk_size) {}
66
73 inline Bridge(ExternalReader&& in, ExternalWriter&& out, std::size_t chunk_size = 4096) noexcept:
74 m_buffer(),
75 m_read_handler(in.Move()),
76 m_write_handler(out.Move()),
77 m_chunk_size(chunk_size) {}
78
87 Bridge(const Bridge& other) = delete;
88
90 inline Bridge(Bridge&& other) noexcept = default;
91
93 inline ~Bridge() noexcept {
94 Flush();
95 }
96
98 Bridge& operator=(const Bridge& other) = delete;
99
101 Bridge& operator=(Bridge&& other) noexcept = default;
102
109 inline std::size_t ChunkSize() const noexcept {
110 return m_chunk_size;
111 }
112
117 bool Flush() const noexcept;
118
131 bool Passthrough(std::size_t bytes) const noexcept;
132
143 bool Passthrough(std::size_t bytes) noexcept;
144
149 inline std::size_t PendingBytes() const noexcept {
150 return m_buffer.Size();
151 }
152
153 private:
154 mutable Buffer::FIFO m_buffer;
155 ExternalReader::PointerType m_read_handler;
156 ExternalWriter::PointerType m_write_handler;
157 std::size_t m_chunk_size;
158
164 bool PassthroughWrite(Buffer::DataType&& data) const noexcept;
165 };
166}
Pass-through adapter that forwards bytes from an ExternalReader to an ExternalWriter in chunks.
Definition bridge.hxx:52
bool Flush() const noexcept
Flushes any pending bytes in the internal buffer to the write handler.
Bridge & operator=(Bridge &&other) noexcept=default
Move assignment (defaulted).
Bridge(const Bridge &other)=delete
Copy constructor (deleted) — Bridge is non-copyable.
Bridge(ExternalReader &&in, ExternalWriter &&out, std::size_t chunk_size=4096) noexcept
Construct a Bridge with both read and write handlers (moving handlers).
Definition bridge.hxx:73
std::size_t ChunkSize() const noexcept
Gets the configured chunk size for passthrough operations.
Definition bridge.hxx:109
~Bridge() noexcept
Destructor — attempts to flush pending bytes.
Definition bridge.hxx:93
Bridge(const ExternalReader &in, const ExternalWriter &out, std::size_t chunk_size=4096) noexcept
Construct a Bridge with both read and write handlers (copying handlers).
Definition bridge.hxx:61
Bridge(Bridge &&other) noexcept=default
Move constructor (defaulted) — transfers handlers.
Bridge & operator=(const Bridge &other)=delete
Copy assignment (deleted).
Interface for reading data from an external source.
Definition external.hxx:26
Interface for writing data to an external source.
Definition external.hxx:174
Byte-oriented FIFO buffer with grow-on-demand.
Definition fifo.hxx:40