| 1 |
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ |
| 2 |
|
| 3 |
#ifndef MPT_PATH_OS_PATH_HPP |
| 4 |
#define MPT_PATH_OS_PATH_HPP |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "mpt/base/detect.hpp" |
| 9 |
#include "mpt/base/namespace.hpp" |
| 10 |
#include "mpt/string/types.hpp" |
| 11 |
|
| 12 |
#if MPT_OS_WINDOWS |
| 13 |
#include <windows.h> |
| 14 |
#endif // MPT_OS_WINDOWS |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
namespace mpt { |
| 19 |
inline namespace MPT_INLINE_NS { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
// mpt::os_path is an alias to a string type that represents native operating system path encoding. |
| 24 |
// Note that this differs from std::filesystem::path::string_type on both Windows and Posix. |
| 25 |
// On Windows, we actually honor UNICODE and thus allow os_path.c_str() to be usable with WinAPI functions. |
| 26 |
// On Posix, we use a type-safe string type in locale encoding, in contrast to the encoding-confused supposedly UTF8 std::string in std::filesystem::path. |
| 27 |
|
| 28 |
#if MPT_OS_WINDOWS |
| 29 |
using os_path = mpt::winstring; |
| 30 |
#else // !MPT_OS_WINDOWS |
| 31 |
using os_path = mpt::lstring; |
| 32 |
#endif // MPT_OS_WINDOWS |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
// mpt::os_path literals that do not involve runtime conversion. |
| 37 |
|
| 38 |
#if MPT_OS_WINDOWS |
| 39 |
#define MPT_OS_PATH_CHAR(x) TEXT(x) |
| 40 |
#define MPT_OS_PATH_LITERAL(x) TEXT(x) |
| 41 |
#define MPT_OS_PATH(x) \ |
| 42 |
mpt::winstring { \ |
| 43 |
TEXT(x) \ |
| 44 |
} |
| 45 |
#else // !MPT_OS_WINDOWS |
| 46 |
#define MPT_OS_PATH_CHAR(x) x |
| 47 |
#define MPT_OS_PATH_LITERAL(x) x |
| 48 |
#define MPT_OS_PATH(x) \ |
| 49 |
mpt::lstring { \ |
| 50 |
x \ |
| 51 |
} |
| 52 |
#endif // MPT_OS_WINDOWS |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
} // namespace MPT_INLINE_NS |
| 57 |
} // namespace mpt |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#endif // MPT_PATH_OS_PATH_HPP |