StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ suite.
Loading...
Searching...
No Matches
producer.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
23
28namespace StormByte::Buffer {
42 public:
51 inline Producer() noexcept : m_buffer(std::make_shared<Ring>()) {}
52
57 inline explicit Producer(std::shared_ptr<Ring> buffer) noexcept
58 : m_buffer(std::move(buffer)) {}
59
64 inline Producer(const Consumer& consumer) noexcept
65 : m_buffer(consumer.m_buffer) {}
66
71 inline Producer(const Producer& other) noexcept : m_buffer(other.m_buffer) {}
72
77 inline Producer(Producer&& other) noexcept : m_buffer(std::move(other.m_buffer)) {}
78
80 ~Producer() noexcept override;
81
87 inline Producer& operator=(const Producer& other) noexcept {
88 if (this != &other) m_buffer = other.m_buffer;
89 return *this;
90 }
91
97 inline Producer& operator=(Producer&& other) noexcept {
98 if (this != &other) m_buffer = std::move(other.m_buffer);
99 return *this;
100 }
101
114 inline bool operator==(const Producer& other) const noexcept {
115 return m_buffer.get() == other.m_buffer.get();
116 }
117
123 inline bool operator!=(const Producer& other) const noexcept {
124 return !(*this == other);
125 }
126
139 void Close() noexcept override;
140
145 void SetError() noexcept override;
146
151 bool IsWritable() const noexcept override;
152
166 bool Write(const std::size_t& count, const DataType& data) noexcept override;
167
173 inline bool Write(const DataType& data) noexcept {
174 return Write(data.size(), data);
175 }
176
183 bool Write(const std::size_t& count, DataType&& data) noexcept override;
184
190 inline bool Write(DataType&& data) noexcept {
191 return Write(data.size(), std::move(data));
192 }
193
200 bool Write(const std::size_t& count, const ReadOnly& data) noexcept override;
201
208 bool Write(const std::size_t& count, ReadOnly&& data) noexcept override;
209
211 using WriteOnly::Write;
212
224 inline class Consumer Consumer() {
225 return StormByte::Buffer::Consumer{ m_buffer };
226 }
227
230 protected:
231 std::shared_ptr<Ring> m_buffer;
232 };
233}
Read-oriented handle over a shared Ring.
Definition consumer.hxx:53
Write-only handle over a shared Ring.
Definition producer.hxx:41
Producer(std::shared_ptr< Ring > buffer) noexcept
Construct a Producer that shares an existing Ring.
Definition producer.hxx:57
Producer(Producer &&other) noexcept
Move construct.
Definition producer.hxx:77
bool Write(const std::size_t &count, ReadOnly &&data) noexcept override
Append bytes from a ReadOnly (move / extract path).
Producer() noexcept
Construct a Producer with a fresh shared Ring.
Definition producer.hxx:51
Producer(const Producer &other) noexcept
Copy construct (shares the same Ring).
Definition producer.hxx:71
~Producer() noexcept override
Destructor.
void Close() noexcept override
Close the shared Ring for further writes.
bool operator!=(const Producer &other) const noexcept
Inequality comparison.
Definition producer.hxx:123
bool operator==(const Producer &other) const noexcept
Equality comparison.
Definition producer.hxx:114
bool Write(const std::size_t &count, const ReadOnly &data) noexcept override
Append bytes from a ReadOnly (copy path).
Producer & operator=(Producer &&other) noexcept
Move assignment.
Definition producer.hxx:97
bool Write(DataType &&data) noexcept
Append an entire DataType (move path).
Definition producer.hxx:190
std::shared_ptr< Ring > m_buffer
Shared ring storage.
Definition producer.hxx:231
Producer(const Consumer &consumer) noexcept
Construct a Producer that shares the Ring of a Consumer.
Definition producer.hxx:64
bool Write(const std::size_t &count, DataType &&data) noexcept override
Append bytes from a DataType (move path).
Pure interface for a buffer that can be read but not written.
Definition generic.hxx:164
High-performance, highly-concurrent thread-safe ring buffer.
Definition ring.hxx:62
Pure interface for a buffer that can be written but not read.
Definition generic.hxx:420
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