Debian Codegraph @

src/mpt/io_read/filedata_base_seekable.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_IO_READ_FILEDATA_BASE_SEEKABLE_HPP
4 #define MPT_IO_READ_FILEDATA_BASE_SEEKABLE_HPP
5
6
7
8 #include "mpt/base/alloc.hpp"
9 #include "mpt/base/memory.hpp"
10 #include "mpt/base/namespace.hpp"
11 #include "mpt/base/span.hpp"
12 #include "mpt/io_read/filedata.hpp"
13
14 #include <algorithm>
15 #include <vector>
16
17 #include <cstddef>
18
19
20
21 namespace mpt {
22 inline namespace MPT_INLINE_NS {
23
24
25
26 namespace IO {
27
28
29
30 class FileDataSeekable : public IFileData {
31
32 private:
33 pos_type streamLength;
34
35 protected:
36 FileDataSeekable(pos_type streamLength_)
37 : streamLength(streamLength_) {
38 return;
39 }
40
41 public:
42 bool IsValid() const override {
43 return true;
44 }
45
46 bool HasFastGetLength() const override {
47 return true;
48 }
49
50 bool HasPinnedView() const override {
51 return false;
52 }
53
54 const std::byte * GetRawData() const override {
55 return nullptr;
56 }
57
58 pos_type GetLength() const override {
59 return streamLength;
60 }
61
62 mpt::byte_span Read(pos_type pos, mpt::byte_span dst) const override {
63 return InternalReadSeekable(pos, dst);
64 }
65
66 private:
67 virtual mpt::byte_span InternalReadSeekable(pos_type pos, mpt::byte_span dst) const = 0;
68 };
69
70
71
72 } // namespace IO
73
74
75
76 } // namespace MPT_INLINE_NS
77 } // namespace mpt
78
79
80
81 #endif // MPT_IO_READ_FILEDATA_BASE_SEEKABLE_HPP