Debian Codegraph @

src/mpt/io_file_read/inputfile_filecursor.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_IO_FILE_READ_INPUTFILE_FILECURSOR_HPP
4 #define MPT_IO_FILE_READ_INPUTFILE_FILECURSOR_HPP
5
6
7
8 #include "mpt/base/namespace.hpp"
9 #include "mpt/io/io.hpp"
10 #include "mpt/io/io_stdstream.hpp"
11 #include "mpt/io_file/inputfile.hpp"
12 #include "mpt/io_read/filecursor_filename_traits.hpp"
13 #include "mpt/io_read/filecursor_memory.hpp"
14 #include "mpt/io_read/filecursor_stdstream.hpp"
15 #include "mpt/io_read/filecursor_traits_filedata.hpp"
16 #include "mpt/io_read/filedata_memory.hpp"
17 #include "mpt/io_read/filedata_stdstream.hpp"
18
19
20
21 namespace mpt {
22 inline namespace MPT_INLINE_NS {
23
24
25
26 namespace IO {
27
28
29
30 // templated in order to reduce header inter-dependencies
31 template <typename Tpath>
32 inline FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>> make_FileCursor(UncachedInputFile & file) {
33 if (!file.IsValid()) {
34 return FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>>();
35 }
36 return mpt::IO::make_FileCursor<Tpath>(file.GetStream(), std::make_shared<Tpath>(file.GetFilename()));
37 }
38
39
40
41 // templated in order to reduce header inter-dependencies
42 template <typename Tpath>
43 inline FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>> make_FileCursor(CachedInputFile & file) {
44 if (!file.IsValid()) {
45 return FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>>();
46 }
47 if (file.IsCached()) {
48 return mpt::IO::make_FileCursor<Tpath>(file.GetCache(), std::make_shared<Tpath>(file.GetFilename()));
49 } else {
50 return mpt::IO::make_FileCursor<Tpath>(file.GetStream(), std::make_shared<Tpath>(file.GetFilename()));
51 }
52 }
53
54
55
56 // templated in order to reduce header inter-dependencies
57 template <typename Tpath>
58 inline FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>> make_FileCursor(InputFile & file) {
59 if (!file.IsValid()) {
60 return FileCursor<FileCursorTraitsFileData, FileCursorFilenameTraits<Tpath>>();
61 }
62 if (file.IsCached()) {
63 return mpt::IO::make_FileCursor<Tpath>(file.GetCache(), std::make_shared<Tpath>(file.GetFilename()));
64 } else {
65 return mpt::IO::make_FileCursor<Tpath>(file.GetStream(), std::make_shared<Tpath>(file.GetFilename()));
66 }
67 }
68
69
70
71 } // namespace IO
72
73
74
75 } // namespace MPT_INLINE_NS
76 } // namespace mpt
77
78
79
80 #endif // MPT_IO_FILE_READ_INPUTFILE_FILECURSOR_HPP