StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
buffered_location_writer.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
48#include <StormByte/safe/pointers.hxx>
49#include <StormByte/safe/string.hxx>
50#include <StormByte/system/device.hxx>
51
52#include <chrono>
53#include <memory>
54#include <utility>
55
60namespace StormByte {
65 namespace Buffer {
70 namespace Backend {
75 namespace IO {
81 }
82 }
83
88 namespace IO {
122 public:
129 public:
133 Parameters() = default;
134
140 template<typename... Knobs>
141 Parameters(Knobs... knobs): BufferedWriter::Parameters(std::move(knobs)...) {}
142
147 Parameters(const Parameters& other) = default;
148
153 Parameters(Parameters&& other) noexcept = default;
154
158 ~Parameters() noexcept = default;
159
165 Parameters& operator=(const Parameters& other) = default;
166
172 Parameters& operator=(Parameters&& other) noexcept = default;
173 };
174
179
185
189 virtual ~BufferedLocationWriter() noexcept override;
190
196
202 BufferedLocationWriter& operator=(BufferedLocationWriter&& other) noexcept;
203
212
217 bool IsSeekable() const noexcept;
218
223 bool IsSized() const noexcept;
224
229 StormByte::ByteSize Size() const noexcept final;
230
231 protected:
238 struct Unpacked {
248 parameters.WriteChunk().value_or(StormByte::ByteSize{0}),
249 parameters.BackPressure().value_or(0),
250 parameters.MaxWait().value_or(0),
251 parameters.MaxMemory().value_or(StormByte::ByteSize{0}),
252 parameters.WriteTransfer().value_or(StormByte::ByteSize{0}),
253 parameters.WriteThreshold().value_or(StormByte::ByteSize{0})},
254 m_probe(!parameters.WriteChunk().has_value()
255 && !parameters.BackPressure().has_value()
256 && !parameters.MaxMemory().has_value()
257 && !parameters.WriteTransfer().has_value()
258 && !parameters.WriteThreshold().has_value()) {}
259
264 Unpacked(const Unpacked& other) noexcept = default;
265
270 Unpacked(Unpacked&& other) noexcept = default;
271
275 ~Unpacked() noexcept = default;
276
282 Unpacked& operator=(const Unpacked& other) noexcept = default;
283
289 Unpacked& operator=(Unpacked&& other) noexcept = default;
290
292 bool m_probe;
293 };
294
305 BufferedLocationWriter(StormByte::Safe::String path, enum Location location, Unpacked knobs);
306
314 virtual StormByte::Safe::Shared<StormByte::System::Device> OriginDevice() const = 0;
315
327 virtual bool OriginDeviceUsable(const StormByte::Safe::Shared<StormByte::System::Device>& device) const noexcept;
328
333 virtual StormByte::ByteSize OriginSize() const noexcept = 0;
334
340 Result OriginSeek(StormByte::ByteSize absolute) override = 0;
341
349 void Setup() final;
350
351 private:
355 std::unique_ptr<StormByte::Buffer::Backend::IO::BufferedLocationWriter> m_io;
356 };
357 }
358 }
359}
360
Private state of StormByte::Buffer::IO::BufferedLocationWriter.
Location-writer knobs.
Definition buffered_location_writer.hxx:128
Parameters()=default
Construct an empty Safe-owned parameter bag.
~Parameters() noexcept=default
Release knobs through provider callbacks.
Parameters(Knobs... knobs)
Store writer knobs in Safe-owned optional values.
Definition buffered_location_writer.hxx:141
Parameters(Parameters &&other) noexcept=default
Transfer Safe-owned knobs.
Parameters(const Parameters &other)=default
Copy Safe-owned knobs; may allocate and throw.
BufferedLocationWriter(const BufferedLocationWriter &)=delete
Copy constructor is deleted.
StormByte::Safe::Shared< StormByte::System::Device > Device() const
Measurement of this location.
virtual StormByte::ByteSize OriginSize() const noexcept=0
Length the leaf can answer.
Result OriginSeek(StormByte::ByteSize absolute) override=0
Seek the origin to an absolute offset.
bool IsSized() const noexcept
This location has a length.
StormByte::ByteSize Size() const noexcept final
Length from the leaf.
virtual StormByte::Safe::Shared< StormByte::System::Device > OriginDevice() const =0
Leaf measurement.
void Setup() final
Apply the device write window when the constructor asked for a probe.
virtual bool OriginDeviceUsable(const StormByte::Safe::Shared< StormByte::System::Device > &device) const noexcept
Whether Setup may read windows from device.
bool IsSeekable() const noexcept
This location can seek.
Writer knobs.
Definition buffered_writer.hxx:246
StormByte::ByteSize WriteThreshold() const noexcept
Page drain high watermark.
friend class StormByte::Buffer::Backend::IO::BufferedWriter
Definition buffered_writer.hxx:235
StormByte::ByteSize MaxMemory() const noexcept
Byte budget for dirty pages that are not yet on the origin.
std::size_t BackPressure() const noexcept
Configured dirty cap in WriteChunk units.
StormByte::ByteSize WriteChunk() const noexcept
Configured ring unit and drain trigger, not a transfer maximum.
std::chrono::milliseconds MaxWait() const noexcept
Wait cap for OriginPush.
enum Location Location() const noexcept
Where Path points.
StormByte::ByteSize WriteTransfer() const noexcept
Maximum origin request in every mode.
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
PIMPL coordinators for the public IO types.
PIMPL coordinators for public Buffer types that are not IO.
Buffered binary sources and sinks.
Buffer module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_FORCE_INLINE
Knobs after Parameters has been unpacked.
Definition buffered_location_writer.hxx:238
WriterConfiguration m_configuration
Complete resolved writer policy.
Definition buffered_location_writer.hxx:291
bool m_probe
Probe device defaults during Setup.
Definition buffered_location_writer.hxx:292
Unpacked(const Unpacked &other) noexcept=default
Copy resolved knobs.
~Unpacked() noexcept=default
Destroy non-owning knobs.
STORMBYTE_FORCE_INLINE Unpacked(const Parameters &parameters)
Unpack a bag in the caller.
Definition buffered_location_writer.hxx:246
Unpacked(Unpacked &&other) noexcept=default
Move resolved knobs.
Per-call status plus how many bytes this call transferred.
Definition typedefs.hxx:214
Complete non-owning writer policy; Configure applies all fields together.
Definition parameters.hxx:244
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54