StormByte-Buffer 2.0.0
C++26 buffer module of the StormByte suite
 
Loading...
Searching...
No Matches
parameters.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#include <StormByte/platform.h>
46
47#include <chrono>
48#include <cstddef>
49#include <optional>
50#include <utility>
51
56namespace StormByte {
61 namespace Buffer {
72 namespace IO {
77 class ReadAhead {
78 public:
84 m_value(value) {}
85
91 return m_value;
92 }
93
94 private:
95 StormByte::ByteSize m_value;
96 };
97
102 class MaxMemory {
103 public:
109 m_value(value) {}
110
116 return m_value;
117 }
118
119 private:
120 StormByte::ByteSize m_value;
121 };
122
127 class MaxWait {
128 public:
133 STORMBYTE_FORCE_INLINE explicit MaxWait(const std::chrono::milliseconds value) noexcept:
134 m_value(value) {}
135
140 STORMBYTE_FORCE_INLINE std::chrono::milliseconds Value() const noexcept {
141 return m_value;
142 }
143
144 private:
145 std::chrono::milliseconds m_value;
146 };
147
153 public:
159 m_value(value) {}
160
166 return m_value;
167 }
168
169 private:
170 StormByte::ByteSize m_value;
171 };
172
178 public:
183 STORMBYTE_FORCE_INLINE explicit BackPressure(const std::size_t value) noexcept:
184 m_value(value) {}
185
190 STORMBYTE_FORCE_INLINE std::size_t Value() const noexcept {
191 return m_value;
192 }
193
194 private:
195 std::size_t m_value;
196 };
197
206 public:
211
217 template<typename... Knobs>
218 STORMBYTE_FORCE_INLINE ReaderParameters(Knobs... knobs) {
219 (Apply(std::move(knobs)), ...);
220 }
221
226 STORMBYTE_FORCE_INLINE const std::optional<StormByte::ByteSize>& ReadAhead() const noexcept {
227 return m_read_ahead;
228 }
229
234 STORMBYTE_FORCE_INLINE const std::optional<StormByte::ByteSize>& MaxMemory() const noexcept {
235 return m_max_memory;
236 }
237
242 STORMBYTE_FORCE_INLINE const std::optional<std::chrono::milliseconds>& MaxWait() const noexcept {
243 return m_max_wait;
244 }
245
246 private:
247 STORMBYTE_FORCE_INLINE void Apply(class ReadAhead knob) noexcept {
248 m_read_ahead = knob.Value();
249 }
250
251 STORMBYTE_FORCE_INLINE void Apply(class MaxMemory knob) noexcept {
252 m_max_memory = knob.Value();
253 }
254
255 STORMBYTE_FORCE_INLINE void Apply(class MaxWait knob) noexcept {
256 m_max_wait = knob.Value();
257 }
258
259 template<typename Knob>
260 void Apply(Knob&&) = delete;
261
262 std::optional<StormByte::ByteSize> m_read_ahead;
263 std::optional<StormByte::ByteSize> m_max_memory;
264 std::optional<std::chrono::milliseconds> m_max_wait;
265 };
266
275 public:
280
286 template<typename... Knobs>
287 STORMBYTE_FORCE_INLINE WriterParameters(Knobs... knobs) {
288 (Apply(std::move(knobs)), ...);
289 }
290
295 STORMBYTE_FORCE_INLINE const std::optional<StormByte::ByteSize>& WriteChunk() const noexcept {
296 return m_write_chunk;
297 }
298
303 STORMBYTE_FORCE_INLINE const std::optional<std::size_t>& BackPressure() const noexcept {
304 return m_back_pressure;
305 }
306
311 STORMBYTE_FORCE_INLINE const std::optional<StormByte::ByteSize>& MaxMemory() const noexcept {
312 return m_max_memory;
313 }
314
319 STORMBYTE_FORCE_INLINE const std::optional<std::chrono::milliseconds>& MaxWait() const noexcept {
320 return m_max_wait;
321 }
322
323 private:
324 STORMBYTE_FORCE_INLINE void Apply(class WriteChunk knob) noexcept {
325 m_write_chunk = knob.Value();
326 }
327
328 STORMBYTE_FORCE_INLINE void Apply(class BackPressure knob) noexcept {
329 m_back_pressure = knob.Value();
330 }
331
332 STORMBYTE_FORCE_INLINE void Apply(class MaxMemory knob) noexcept {
333 m_max_memory = knob.Value();
334 }
335
336 STORMBYTE_FORCE_INLINE void Apply(class MaxWait knob) noexcept {
337 m_max_wait = knob.Value();
338 }
339
340 template<typename Knob>
341 void Apply(Knob&&) = delete;
342
343 std::optional<StormByte::ByteSize> m_write_chunk;
344 std::optional<std::size_t> m_back_pressure;
345 std::optional<StormByte::ByteSize> m_max_memory;
346 std::optional<std::chrono::milliseconds> m_max_wait;
347 };
348 }
349 }
350}
Writer ring cap in WriteChunk units.
Definition parameters.hxx:177
STORMBYTE_FORCE_INLINE BackPressure(const std::size_t value) noexcept
Store the cap in chunks.
Definition parameters.hxx:183
STORMBYTE_FORCE_INLINE std::size_t Value() const noexcept
Cap in chunks.
Definition parameters.hxx:190
Cache / dirty-page budget knob.
Definition parameters.hxx:102
STORMBYTE_FORCE_INLINE StormByte::ByteSize Value() const noexcept
Memory budget.
Definition parameters.hxx:115
STORMBYTE_FORCE_INLINE MaxMemory(const StormByte::ByteSize value) noexcept
Store the memory budget.
Definition parameters.hxx:108
Origin wait cap.
Definition parameters.hxx:127
STORMBYTE_FORCE_INLINE MaxWait(const std::chrono::milliseconds value) noexcept
Store the wait cap.
Definition parameters.hxx:133
STORMBYTE_FORCE_INLINE std::chrono::milliseconds Value() const noexcept
Wait cap.
Definition parameters.hxx:140
Prefetch length knob.
Definition parameters.hxx:77
STORMBYTE_FORCE_INLINE StormByte::ByteSize Value() const noexcept
Prefetch length.
Definition parameters.hxx:90
STORMBYTE_FORCE_INLINE ReadAhead(const StormByte::ByteSize value) noexcept
Store the prefetch length.
Definition parameters.hxx:83
Optional reader knobs.
Definition parameters.hxx:205
STORMBYTE_FORCE_INLINE ReaderParameters() noexcept=default
No knobs.
STORMBYTE_FORCE_INLINE const std::optional< std::chrono::milliseconds > & MaxWait() const noexcept
Wait cap when the caller set it.
Definition parameters.hxx:242
STORMBYTE_FORCE_INLINE const std::optional< StormByte::ByteSize > & ReadAhead() const noexcept
Prefetch length when the caller set it.
Definition parameters.hxx:226
STORMBYTE_FORCE_INLINE const std::optional< StormByte::ByteSize > & MaxMemory() const noexcept
Cache cap when the caller set it.
Definition parameters.hxx:234
Origin push unit.
Definition parameters.hxx:152
STORMBYTE_FORCE_INLINE StormByte::ByteSize Value() const noexcept
Chunk size.
Definition parameters.hxx:165
STORMBYTE_FORCE_INLINE WriteChunk(const StormByte::ByteSize value) noexcept
Store the chunk size.
Definition parameters.hxx:158
Optional writer knobs.
Definition parameters.hxx:274
STORMBYTE_FORCE_INLINE const std::optional< StormByte::ByteSize > & WriteChunk() const noexcept
Chunk size when the caller set it.
Definition parameters.hxx:295
STORMBYTE_FORCE_INLINE const std::optional< std::chrono::milliseconds > & MaxWait() const noexcept
Wait cap when the caller set it.
Definition parameters.hxx:319
STORMBYTE_FORCE_INLINE const std::optional< std::size_t > & BackPressure() const noexcept
Backpressure when the caller set it.
Definition parameters.hxx:303
STORMBYTE_FORCE_INLINE WriterParameters() noexcept=default
No knobs.
STORMBYTE_FORCE_INLINE const std::optional< StormByte::ByteSize > & MaxMemory() const noexcept
Dirty-page budget when the caller set it.
Definition parameters.hxx:311
Root namespace of the StormByte C++ suite.
#define STORMBYTE_FORCE_INLINE