Debian Codegraph @

src/mpt/io_read/filecursor_traits_filedata.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_IO_READ_FILECURSOR_TRAITS_FILEDATA_HPP
4 #define MPT_IO_READ_FILECURSOR_TRAITS_FILEDATA_HPP
5
6
7
8 #include "mpt/base/memory.hpp"
9 #include "mpt/base/namespace.hpp"
10 #include "mpt/io_read/filedata.hpp"
11 #include "mpt/io_read/filedata_base.hpp"
12 #include "mpt/io_read/filedata_memory.hpp"
13
14 #include <memory>
15
16
17
18 namespace mpt {
19 inline namespace MPT_INLINE_NS {
20
21
22
23 namespace IO {
24
25
26
27 class FileCursorTraitsFileData {
28
29 public:
30 using pos_type = IFileData::pos_type;
31
32 using data_type = std::shared_ptr<const IFileData>;
33 using ref_data_type = const IFileData &;
34 using shared_data_type = std::shared_ptr<const IFileData>;
35 using value_data_type = std::shared_ptr<const IFileData>;
36
37 static shared_data_type get_shared(const data_type & data) {
38 return data;
39 }
40 static ref_data_type get_ref(const data_type & data) {
41 return *data;
42 }
43
44 static value_data_type make_data() {
45 return std::make_shared<FileDataDummy>();
46 }
47 static value_data_type make_data(mpt::const_byte_span data) {
48 return std::make_shared<FileDataMemory>(data);
49 }
50
51 static value_data_type make_chunk(shared_data_type data, pos_type position, pos_type size) {
52 return std::static_pointer_cast<IFileData>(std::make_shared<FileDataWindow>(data, position, size));
53 }
54 };
55
56
57
58 } // namespace IO
59
60
61
62 } // namespace MPT_INLINE_NS
63 } // namespace mpt
64
65
66
67 #endif // MPT_IO_READ_FILECURSOR_TRAITS_FILEDATA_HPP