StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
consumer.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
44#include <StormByte/type_traits/safe.hxx>
45
47#include <StormByte/safe/owner.hxx>
48#include <StormByte/type_traits.hxx>
49
54namespace StormByte {
59 namespace Buffer {
60 class Producer;
61
81 public:
86
92
98 Consumer(const Consumer& other);
99
104 Consumer(Consumer&& other) noexcept;
105
109 ~Consumer() noexcept override;
110
117 Consumer& operator=(const Consumer& other);
118
124 Consumer& operator=(Consumer&& other) noexcept;
125
129
134
140 bool operator==(const Consumer& other) const noexcept;
141
147 inline bool operator!=(const Consumer& other) const noexcept {
148 return !(*this == other);
149 }
150
154
159
164 StormByte::ByteSize Available() const noexcept override;
165
171 const StormByte::Safe::Binary& Data() const noexcept override;
172
178 bool Empty() const noexcept override;
179
184 bool EoF() const noexcept override;
185
190 bool IsReadable() const noexcept override;
191
196 inline bool IsWritable() const noexcept {
197 return Storage().IsWritable();
198 }
199
204 inline bool HasError() const noexcept {
205 return Storage().HasError();
206 }
207
212 StormByte::ByteSize Size() const noexcept override;
213
218 class Producer Producer() const;
219
223
228
232 void Clean() noexcept override;
233
238 void Clear() noexcept override;
239
244 inline void Close() noexcept {
245 Storage().Close();
246 }
247
253 bool Drop(const StormByte::ByteSize& count) noexcept override;
254
260 void Seek(const std::ptrdiff_t& offset, const Position& mode) const noexcept override;
261
265
270
277 bool Extract(const StormByte::ByteSize& count, StormByte::Safe::Binary& out) noexcept override;
278
285 bool Extract(const StormByte::ByteSize& count, WriteOnly& out) noexcept override;
286
291 void ExtractUntilEoF(StormByte::Safe::Binary& out) noexcept override;
292
297 void ExtractUntilEoF(WriteOnly& out) noexcept override;
298
302
307
314 bool Read(const StormByte::ByteSize& count, StormByte::Safe::Binary& out) const noexcept override;
315
322 bool Read(const StormByte::ByteSize& count, WriteOnly& out) const noexcept override;
323
328 void ReadUntilEoF(StormByte::Safe::Binary& out) const noexcept override;
329
334 void ReadUntilEoF(WriteOnly& out) const noexcept override;
335
339
344
351 bool Peek(const StormByte::ByteSize& count, StormByte::Safe::Binary& out) const noexcept override;
352
359 bool Peek(const StormByte::ByteSize& count, WriteOnly& out) const noexcept override;
360
364
365 private:
366 friend class Producer;
367
368 StormByte::Safe::Owner m_buffer;
369
374 Ring& Storage() const noexcept;
375
380 explicit Consumer(StormByte::Safe::Owner buffer) noexcept;
381 };
382 }
383}
384
const StormByte::Safe::Binary & Data() const noexcept override
Snapshot of the underlying data.
bool Drop(const StormByte::ByteSize &count) noexcept override
Discard bytes from the current read position.
void Clean() noexcept override
Discard already-consumed data up to the read position.
bool EoF() const noexcept override
End-of-stream condition.
void ReadUntilEoF(WriteOnly &out) const noexcept override
Read until EoF into a writer.
~Consumer() noexcept override
Destroy the Consumer.
void Clear() noexcept override
Clear stored bytes.
bool Read(const StormByte::ByteSize &count, StormByte::Safe::Binary &out) const noexcept override
Read into owned storage and advance the cursor.
bool HasError() const noexcept
Whether the shared Ring is in a permanent error state.
Definition consumer.hxx:204
StormByte::ByteSize Size() const noexcept override
Total number of bytes stored in the shared Ring.
void ExtractUntilEoF(WriteOnly &out) noexcept override
Extract until EoF into a writer.
void Seek(const std::ptrdiff_t &offset, const Position &mode) const noexcept override
Move the logical read position.
bool Extract(const StormByte::ByteSize &count, WriteOnly &out) noexcept override
Extract bytes into a writer.
bool Extract(const StormByte::ByteSize &count, StormByte::Safe::Binary &out) noexcept override
Extract bytes into owned storage.
void ReadUntilEoF(StormByte::Safe::Binary &out) const noexcept override
Read until EoF into owned storage.
void Close() noexcept
Close the shared Ring for further writes.
Definition consumer.hxx:244
friend class Producer
Definition consumer.hxx:366
StormByte::ByteSize Available() const noexcept override
Bytes available from the current position.
bool Empty() const noexcept override
Whether the shared Ring holds no stored bytes.
Consumer(Consumer &&other) noexcept
Take a Consumer.
void ExtractUntilEoF(StormByte::Safe::Binary &out) noexcept override
Extract until EoF into owned storage.
bool Read(const StormByte::ByteSize &count, WriteOnly &out) const noexcept override
Read into a writer and advance the cursor.
bool Peek(const StormByte::ByteSize &count, StormByte::Safe::Binary &out) const noexcept override
Peek into owned storage.
bool IsWritable() const noexcept
Whether the shared Ring still accepts writes.
Definition consumer.hxx:196
bool IsReadable() const noexcept override
Whether the shared Ring can still be read.
Consumer()
Create a Consumer and a new shared Ring.
bool Peek(const StormByte::ByteSize &count, WriteOnly &out) const noexcept override
Peek into a writer.
Consumer(const Consumer &other)
Copy a Consumer.
Write-only handle over a shared Ring.
Definition producer.hxx:71
ReadOnly() noexcept
Default constructor.
Highly concurrent thread-safe ring buffer.
Definition ring.hxx:90
Buffer that can be written and not read.
Definition generic.hxx:497
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Buffer module of the StormByte suite.
Position
Forward declaration of the WriteOnly interface.
Definition typedefs.hxx:74
Detail::Owner Owner
Root namespace of the StormByte C++ suite.
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54