Debian Codegraph @

src/mpt/io_read/filecursor_filename_traits.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_IO_READ_FILECURSOR_FILENAME_TRAITS_HPP
4 #define MPT_IO_READ_FILECURSOR_FILENAME_TRAITS_HPP
5
6
7
8 #include "mpt/base/namespace.hpp"
9
10 #include <memory>
11 #include <optional>
12
13
14
15 namespace mpt {
16 inline namespace MPT_INLINE_NS {
17
18
19
20 namespace IO {
21
22
23
24 class FileCursorFilenameTraitsNone {
25
26 public:
27 struct empty_type { };
28
29 using filename_type = empty_type;
30 using shared_filename_type = empty_type;
31
32 static std::optional<filename_type> get_optional_filename(shared_filename_type /* filename */) {
33 return std::nullopt;
34 }
35 };
36
37 template <typename Tpath>
38 class FileCursorFilenameTraits {
39
40 public:
41 using filename_type = Tpath;
42 using shared_filename_type = std::shared_ptr<Tpath>;
43
44 static std::optional<filename_type> get_optional_filename(const shared_filename_type & filename) {
45 if (!filename) {
46 return std::nullopt;
47 }
48 if ((*filename) == Tpath{}) {
49 return std::nullopt;
50 }
51 return *filename;
52 }
53 };
54
55
56
57 } // namespace IO
58
59
60
61 } // namespace MPT_INLINE_NS
62 } // namespace mpt
63
64
65
66 #endif // MPT_IO_READ_FILECURSOR_FILENAME_TRAITS_HPP