StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
buffered_location_reader.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 {
123 public:
130 public:
134 Parameters() = default;
135
141 template<typename... Knobs>
142 Parameters(Knobs... knobs): BufferedReader::Parameters(std::move(knobs)...) {}
143
148 Parameters(const Parameters& other) = default;
149
154 Parameters(Parameters&& other) noexcept = default;
155
159 ~Parameters() noexcept = default;
160
166 Parameters& operator=(const Parameters& other) = default;
167
173 Parameters& operator=(Parameters&& other) noexcept = default;
174 };
175
180
186
190 virtual ~BufferedLocationReader() noexcept override;
191
197
203 BufferedLocationReader& operator=(BufferedLocationReader&& other) noexcept;
204
213
214 protected:
221 struct Unpacked {
231 StormByte::ByteSize default_memory = StormByte::ByteSize{0}):
232 m_configuration{
233 parameters.ReadChunk().value_or(StormByte::ByteSize{64 * 1024}),
234 parameters.ReadAhead().value_or(StormByte::ByteSize{0}),
235 parameters.MaxMemory().value_or(default_memory),
236 parameters.MaxWait().value_or(0)},
237 m_probe(!parameters.ReadAhead().has_value()) {}
238
243 Unpacked(const Unpacked& other) noexcept = default;
244
249 Unpacked(Unpacked&& other) noexcept = default;
250
254 ~Unpacked() noexcept = default;
255
261 Unpacked& operator=(const Unpacked& other) noexcept = default;
262
268 Unpacked& operator=(Unpacked&& other) noexcept = default;
269
271 bool m_probe;
272 };
273
284 BufferedLocationReader(StormByte::Safe::String path, enum Location location, Unpacked knobs);
285
293 virtual StormByte::Safe::Shared<StormByte::System::Device> OriginDevice() const = 0;
294
306 virtual bool OriginDeviceUsable(const StormByte::Safe::Shared<StormByte::System::Device>& device) const noexcept;
307
312 bool OriginCanSeek() const noexcept final;
313
318 bool OriginHasSize() const noexcept final;
319
327 void Setup() final;
328
329 private:
333 std::unique_ptr<StormByte::Buffer::Backend::IO::BufferedLocationReader> m_io;
334 };
335 }
336 }
337}
338
Private state of StormByte::Buffer::IO::BufferedLocationReader.
Location-reader knobs.
Definition buffered_location_reader.hxx:129
Parameters()=default
Construct an empty Safe-owned parameter bag.
Parameters(Parameters &&other) noexcept=default
Transfer Safe-owned knobs.
Parameters(const Parameters &other)=default
Copy Safe-owned knobs; may allocate and throw.
~Parameters() noexcept=default
Release knobs through provider callbacks.
Parameters(Knobs... knobs)
Store reader knobs in Safe-owned optional values.
Definition buffered_location_reader.hxx:142
bool OriginHasSize() const noexcept final
A location has a length.
virtual bool OriginDeviceUsable(const StormByte::Safe::Shared< StormByte::System::Device > &device) const noexcept
Whether Setup may read windows from device.
bool OriginCanSeek() const noexcept final
A location can seek.
virtual StormByte::Safe::Shared< StormByte::System::Device > OriginDevice() const =0
Leaf measurement.
StormByte::Safe::Shared< StormByte::System::Device > Device() const
Measurement of this location.
BufferedLocationReader(const BufferedLocationReader &)=delete
Copy constructor is deleted.
void Setup() final
Apply the device read window when the constructor asked for a probe.
Reader knobs.
Definition buffered_reader.hxx:225
StormByte::ByteSize ReadAhead() const noexcept
Configured prefetch length in bytes.
enum Location Location() const noexcept
Where Path points.
StormByte::ByteSize MaxMemory() const noexcept
Configured cache memory cap in bytes.
friend class StormByte::Buffer::Backend::IO::BufferedReader
Definition buffered_reader.hxx:215
StormByte::ByteSize ReadChunk() const noexcept
Maximum request passed to the origin.
std::chrono::milliseconds MaxWait() const noexcept
Configured read wait limit.
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_reader.hxx:221
bool m_probe
Probe the read window during Setup.
Definition buffered_location_reader.hxx:271
Unpacked(const Unpacked &other) noexcept=default
Copy resolved knobs.
ReaderConfiguration m_configuration
Complete resolved reader policy.
Definition buffered_location_reader.hxx:270
Unpacked(Unpacked &&other) noexcept=default
Move resolved knobs.
~Unpacked() noexcept=default
Destroy non-owning knobs.
STORMBYTE_FORCE_INLINE Unpacked(const Parameters &parameters, StormByte::ByteSize default_memory=StormByte::ByteSize{0})
Unpack a bag in the caller.
Definition buffered_location_reader.hxx:230
Complete non-owning reader policy; scalar time crosses the DLL.
Definition parameters.hxx:234
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54