StormByte-Buffer 2.0.0
C++26 buffer module of the StormByte 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 original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Buffer source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the rest of the StormByte suite it vendors), which remains under its own
24 * license.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Buffer is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Buffer. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
45
50namespace StormByte {
55 namespace Buffer {
67 public:
76 inline Producer() noexcept : m_buffer(std::make_shared<Ring>()) {}
77
82 inline explicit Producer(std::shared_ptr<Ring> buffer) noexcept
83 : m_buffer(std::move(buffer)) {}
84
89 inline Producer(const Consumer& consumer) noexcept
90 : m_buffer(consumer.m_buffer) {}
91
96 inline Producer(const Producer& other) noexcept : m_buffer(other.m_buffer) {}
97
102 inline Producer(Producer&& other) noexcept : m_buffer(std::move(other.m_buffer)) {}
103
107 ~Producer() noexcept override;
108
114 inline Producer& operator=(const Producer& other) noexcept {
115 if (this != &other)
116 m_buffer = other.m_buffer;
117 return *this;
118 }
119
125 inline Producer& operator=(Producer&& other) noexcept {
126 if (this != &other)
127 m_buffer = std::move(other.m_buffer);
128 return *this;
129 }
130
145 inline bool operator==(const Producer& other) const noexcept {
146 return m_buffer.get() == other.m_buffer.get();
147 }
148
154 inline bool operator!=(const Producer& other) const noexcept {
155 return !(*this == other);
156 }
157
171 void Close() noexcept override;
172
176 void SetError() noexcept override;
177
182 bool IsWritable() const noexcept override;
183
188 StormByte::ByteSize Size() const noexcept override;
189
205 bool Write(const StormByte::ByteSize& count, const BinaryData& data) noexcept override;
206
212 inline bool Write(const BinaryData& data) noexcept {
213 return Write(data.size(), data);
214 }
215
222 bool Write(const StormByte::ByteSize& count, BinaryData&& data) noexcept override;
223
229 inline bool Write(BinaryData&& data) noexcept {
230 return Write(data.size(), std::move(data));
231 }
232
239 bool Write(const StormByte::ByteSize& count, const ReadOnly& data) noexcept override;
240
247 bool Write(const StormByte::ByteSize& count, ReadOnly&& data) noexcept override;
248
252 using WriteOnly::Write;
253
262 inline class Consumer Consumer() {
263 return StormByte::Buffer::Consumer{ m_buffer };
264 }
265
266 protected:
267 std::shared_ptr<Ring> m_buffer;
268 };
269 }
270}
Read-oriented handle over a shared Ring.
Definition consumer.hxx:84
Write-only handle over a shared Ring.
Definition producer.hxx:66
Producer(std::shared_ptr< Ring > buffer) noexcept
Share an existing Ring.
Definition producer.hxx:82
Producer(Producer &&other) noexcept
Move constructor.
Definition producer.hxx:102
bool Write(BinaryData &&data) noexcept
Append an entire StormByte::BinaryData (move).
Definition producer.hxx:229
Producer() noexcept
Construct a Producer with a new shared Ring.
Definition producer.hxx:76
Producer(const Producer &other) noexcept
Copy constructor.
Definition producer.hxx:96
~Producer() noexcept override
Destructor.
void Close() noexcept override
Close the shared Ring for further writes.
bool operator!=(const Producer &other) const noexcept
Inequality.
Definition producer.hxx:154
bool operator==(const Producer &other) const noexcept
Equality.
Definition producer.hxx:145
bool Write(const StormByte::ByteSize &count, const ReadOnly &data) noexcept override
Append bytes from a ReadOnly (copy).
Producer & operator=(Producer &&other) noexcept
Move assignment.
Definition producer.hxx:125
bool Write(const StormByte::ByteSize &count, ReadOnly &&data) noexcept override
Append bytes from a ReadOnly (extract).
bool Write(const StormByte::ByteSize &count, BinaryData &&data) noexcept override
Append bytes from a StormByte::BinaryData (move).
std::shared_ptr< Ring > m_buffer
Shared ring. Not null after construction.
Definition producer.hxx:267
Producer(const Consumer &consumer) noexcept
Share the Ring of a Consumer.
Definition producer.hxx:89
Buffer that can be read and not written.
Definition generic.hxx:228
High-performance, highly-concurrent thread-safe ring buffer.
Definition ring.hxx:83
Buffer that can be written and not read.
Definition generic.hxx:505
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54