LeviLamina
Loading...
Searching...
No Matches
Path.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/deps/core/file/PathPart.h"
5
6// auto generated inclusion list
7#include "mc/deps/core/file/PathBuffer.h"
8#include "mc/deps/core/string/BasicStackString.h"
9
10// auto generated forward declare list
11// clang-format off
12namespace Core { class PathPart; }
13// clang-format on
14
15namespace Core {
16
17class Path : public ::Core::PathBuffer<::std::string> {
18public:
20
21 Path() = default;
22
23 Path(std::filesystem::path const& path) : Path(path.u8string()) {}
24 Path(std::u8string&& path) { value = std::move(*reinterpret_cast<std::string*>(&path)); }
25 Path(std::string&& path) { value = std::move(path); }
26 Path(std::u8string const& path) { value = *reinterpret_cast<std::string const*>(&path); }
27 Path(std::string const& path) { value = path; }
28 Path(char const* path) { value = path; }
29
30 Path(PathPart const& part) : Base{std::move(part.mUtf8StdString)} {}
31
32 Path(const Path& other) = default;
33
34 Path(Path&& other) noexcept : Base{std::move(other.value)} {}
35
36 Path& operator=(const Path& other) {
37 if (this != &other) value = other.value;
38 return *this;
39 }
40
41 Path& operator=(Path&& other) noexcept {
42 if (this != &other) value = std::move(other.value);
43 return *this;
44 }
45
46 bool operator<(const Path& rhs) const noexcept { return value < rhs.value; }
47
48 bool operator==(const Path& rhs) const noexcept { return value == rhs.value; }
49
50 [[nodiscard]] const char* getUtf8CString() const noexcept { return value.c_str(); }
51
52 [[nodiscard]] std::string_view getUtf8StringView() const noexcept { return value; }
53
54 [[nodiscard]] const std::string& getUtf8StdString() const noexcept { return value; }
55
56 [[nodiscard]] size_t size() const noexcept { return value.size(); }
57
58 [[nodiscard]] bool empty() const noexcept { return value.empty(); }
59
60 [[nodiscard]] bool isAbsolute() const noexcept {
61#ifdef _WIN32
62 auto const& s = value;
63 if (s.size() >= 2 && std::isalpha(static_cast<unsigned char>(s[0])) && s[1] == ':') return true;
64 if (s.size() >= 2 && s[0] == '\\' && s[1] == '\\') return true;
65 return false;
66#else
67 auto const& s = value;
68 return !s.empty() && s.front() == '/';
69#endif
70 }
71
72 [[nodiscard]] bool isDotOrDotDot() const noexcept {
73 return value == "." || value == "..";
74 }
75
76 // Static constant EMPTY
77 static const Path& EMPTY() {
78 static const Path emptyPath("");
79 return emptyPath;
80 }
81};
82
83} // namespace Core
Definition PathBuffer.h:8
Definition PathPart.h:7