StormByte C++ Library: Buffer module 0.0.9999
StormByte-Buffer is a StormByte library module for handling buffers
Loading...
Searching...
No Matches
producer.hxx
1#pragma once
2
3#include <StormByte/buffer/consumer.hxx>
4
13namespace StormByte::Buffer {
27 class STORMBYTE_BUFFER_PUBLIC Producer final: public WriteOnly {
28 public:
34 inline Producer() noexcept: m_buffer(std::make_shared<SharedFIFO>()) {};
35
42 inline Producer(std::shared_ptr<SharedFIFO> buffer): m_buffer(buffer) {}
43
49 inline Producer(const Consumer& consumer): m_buffer(consumer.m_buffer) {}
50
57 inline Producer(const Producer& other) noexcept {
58 m_buffer = other.m_buffer;
59 }
60
66 inline Producer(Producer&& other) noexcept {
67 m_buffer = std::move(other.m_buffer);
68 }
69
73 ~Producer() noexcept = default;
74
80 inline Producer& operator=(const Producer& other) noexcept {
81 if (this != &other)
82 m_buffer = other.m_buffer;
83 return *this;
84 }
85
90 inline Producer& operator=(Producer&& other) noexcept {
91 if (this != &other)
92 m_buffer = std::move(other.m_buffer);
93 return *this;
94 }
95
100 inline bool operator==(const Producer& other) const noexcept {
101 return m_buffer.get() == other.m_buffer.get();
102 }
103
108 inline bool operator!=(const Producer& other) const noexcept {
109 return !(*this == other);
110 }
111
118 inline void Close() noexcept {
119 m_buffer->Close();
120 }
121
122 inline bool IsWritable() const noexcept override {
123 return m_buffer->IsWritable();
124 }
125
132 inline void SetError() noexcept {
133 m_buffer->SetError();
134 }
135
145 inline bool Write(const std::size_t& count, const DataType& data) noexcept override {
146 return m_buffer->Write(count, data);
147 }
148
157 inline bool Write(const DataType& data) noexcept {
158 return Write(data.size(), data);
159 }
160
170 inline bool Write(const std::size_t& count, DataType&& data) noexcept override {
171 return m_buffer->Write(count, std::move(data));
172 }
173
182 inline bool Write(DataType&& data) noexcept {
183 return Write(data.size(), std::move(data));
184 }
185
195 inline bool Write(const std::size_t& count, const ReadOnly& data) noexcept override {
196 return m_buffer->Write(count, data);
197 }
198
208 inline bool Write(const std::size_t& count, ReadOnly&& data) noexcept override {
209 return m_buffer->Write(count, std::move(data));
210 }
211
213 using WriteOnly::Write;
214
222 inline class Consumer Consumer() {
223 return { m_buffer };
224 }
225
226 protected:
227 std::shared_ptr<SharedFIFO> m_buffer;
228 };
229}
Read-only interface for consuming data from a shared FIFO buffer.
Definition consumer.hxx:46
Producer interface for writing data to a shared FIFO buffer.
Definition producer.hxx:27
void SetError() noexcept
Thread-safe error state setting.
Definition producer.hxx:132
Producer(Producer &&other) noexcept
Move constructor.
Definition producer.hxx:66
Producer(std::shared_ptr< SharedFIFO > buffer)
Construct a Producer with an existing SharedFIFO buffer.
Definition producer.hxx:42
bool Write(const std::size_t &count, ReadOnly &&data) noexcept override
Move bytes from a vector to the buffer.
Definition producer.hxx:208
Producer() noexcept
Construct a Producer with a new SharedFIFO buffer.
Definition producer.hxx:34
Producer(const Producer &other) noexcept
Copy constructor.
Definition producer.hxx:57
bool Write(const DataType &data) noexcept
Write all bytes from a vector to the buffer.
Definition producer.hxx:157
bool operator!=(const Producer &other) const noexcept
Inequality comparison.
Definition producer.hxx:108
~Producer() noexcept=default
Destructor.
bool operator==(const Producer &other) const noexcept
Equality comparison.
Definition producer.hxx:100
void Close() noexcept
Thread-safe close for further writes.
Definition producer.hxx:118
bool Write(const std::size_t &count, const ReadOnly &data) noexcept override
Write bytes from a vector to the buffer.
Definition producer.hxx:195
Producer & operator=(Producer &&other) noexcept
Move assignment operator.
Definition producer.hxx:90
Producer(const Consumer &consumer)
Construct a Producer from a Consumer's buffer.
Definition producer.hxx:49
bool IsWritable() const noexcept override
Check if the buffer is writable.
Definition producer.hxx:122
bool Write(DataType &&data) noexcept
Move all bytes from a vector to the buffer.
Definition producer.hxx:182
bool Write(const std::size_t &count, const DataType &data) noexcept override
Write bytes from a vector to the buffer.
Definition producer.hxx:145
bool Write(const std::size_t &count, DataType &&data) noexcept override
Move bytes from a vector to the buffer.
Definition producer.hxx:170
Generic class providing a buffer that can be read but not written to.
Definition generic.hxx:146
Thread-safe FIFO built on top of FIFO.
Definition shared_fifo.hxx:52
Generic class providing a buffer that can be written to but not read from.
Definition generic.hxx:408