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