-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpath.hpp
More file actions
153 lines (123 loc) · 4.61 KB
/
Copy pathpath.hpp
File metadata and controls
153 lines (123 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#pragma once
#include <cstdint>
#include <filesystem>
#include <string>
#include <typeindex>
namespace odr::internal {
class AbsPath;
class RelPath;
class Path {
public:
Path() noexcept;
explicit Path(const char *c_string);
explicit Path(const std::string &string);
explicit Path(std::string_view string_view);
explicit Path(const std::filesystem::path &path);
Path(const Path &other) noexcept = default;
Path(Path &&other) noexcept = default;
virtual ~Path() noexcept = default;
Path &operator=(const Path &other) noexcept = default;
Path &operator=(Path &&other) noexcept = default;
bool operator==(const Path &other) const noexcept;
bool operator!=(const Path &other) const noexcept;
bool operator<(const Path &other) const noexcept;
bool operator>(const Path &other) const noexcept;
[[nodiscard]] const std::string &string() const noexcept;
[[nodiscard]] std::filesystem::path path() const noexcept;
[[nodiscard]] std::size_t hash() const noexcept;
[[nodiscard]] bool root() const noexcept;
[[nodiscard]] bool absolute() const noexcept;
[[nodiscard]] bool relative() const noexcept;
[[nodiscard]] bool visible() const noexcept;
[[nodiscard]] bool escaping() const noexcept;
[[nodiscard]] bool child_of(const Path &other) const;
[[nodiscard]] bool parent_of(const Path &other) const;
[[nodiscard]] bool ancestor_of(const Path &other) const;
[[nodiscard]] bool descendant_of(const Path &other) const;
[[nodiscard]] AbsPath as_absolute() const &;
[[nodiscard]] AbsPath as_absolute() &&;
[[nodiscard]] RelPath as_relative() const &;
[[nodiscard]] RelPath as_relative() &&;
[[nodiscard]] AbsPath make_absolute() const;
[[nodiscard]] RelPath make_relative() const;
[[nodiscard]] std::string basename() const noexcept;
[[nodiscard]] std::string extension() const noexcept;
[[nodiscard]] Path parent() const;
[[nodiscard]] Path join(const RelPath &other) const;
[[nodiscard]] Path rebase(const Path &on) const;
[[nodiscard]] Path common_root(const Path &other) const;
class Iterator final {
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = std::string;
using pointer = const std::string *;
using reference = const std::string &;
Iterator();
explicit Iterator(const std::string &path);
Iterator(const std::string &path, std::size_t begin);
explicit Iterator(const Path &path);
reference operator*() const;
pointer operator->() const;
bool operator==(const Iterator &other) const;
bool operator!=(const Iterator &other) const;
Iterator &operator++();
Iterator operator++(int);
private:
const std::string *m_path{nullptr};
std::size_t m_begin{0};
std::string m_part;
void fill_();
};
[[nodiscard]] Iterator begin() const;
[[nodiscard]] Iterator end() const;
private:
std::string m_path;
std::uint32_t m_upwards{0};
std::uint32_t m_downwards{0};
bool m_absolute{false};
friend std::ostream &operator<<(std::ostream &os, const Path &p) {
return os << p.m_path;
}
void parent_();
void join_(const std::string &);
};
class AbsPath final : public Path {
public:
static AbsPath current_working_directory();
AbsPath() noexcept;
explicit AbsPath(const char *c_string);
explicit AbsPath(const std::string &string);
explicit AbsPath(std::string_view string_view);
explicit AbsPath(const std::filesystem::path &path);
explicit AbsPath(Path path);
[[nodiscard]] AbsPath parent() const;
[[nodiscard]] AbsPath join(const RelPath &other) const;
[[nodiscard]] RelPath rebase(const AbsPath &on) const;
[[nodiscard]] AbsPath common_root(const AbsPath &other) const;
};
class RelPath final : public Path {
public:
RelPath() noexcept;
explicit RelPath(const char *c_string);
explicit RelPath(const std::string &string);
explicit RelPath(std::string_view string_view);
explicit RelPath(const std::filesystem::path &path);
explicit RelPath(Path path);
[[nodiscard]] RelPath parent() const;
[[nodiscard]] RelPath join(const RelPath &other) const;
[[nodiscard]] RelPath rebase(const RelPath &on) const;
[[nodiscard]] RelPath common_root(const RelPath &other) const;
};
} // namespace odr::internal
namespace std {
template <> struct hash<::odr::internal::Path> {
std::size_t operator()(const ::odr::internal::Path &p) const noexcept;
};
template <> struct hash<::odr::internal::AbsPath> {
std::size_t operator()(const ::odr::internal::AbsPath &p) const noexcept;
};
template <> struct hash<::odr::internal::RelPath> {
std::size_t operator()(const ::odr::internal::RelPath &p) const noexcept;
};
} // namespace std