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