Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Path.h
Go to the documentation of this file.
1#pragma once
2
3#include "Utility/TSpan.h"
4
5#include <Common/Utility/string_utils.h>
6#include <Common/compiler.h>
7
8#include <cstddef>
9#include <string>
10#include <utility>
11#include <filesystem>
12
13namespace ph
14{
15
20class Path final
21{
22public:
25 Path();
26
35 explicit Path(std::string path);
36
40 explicit Path(std::string_view path);
41
45 explicit Path(TSpanView<char> path);
46
51 explicit Path(const char* path);
52
53 explicit Path(std::filesystem::path path);
54
55 bool isRelative() const;
56 bool isAbsolute() const;
57 bool isEmpty() const;
58 void clear();
59
64 Path append(const Path& other) const;
65
66 Path append(std::string_view pathStr) const;
67
68 Path toAbsolute() const;
69
72 std::string toString() const;
73
74 std::string toAbsoluteString() const;
75
79 std::string toNativeString() const;
80
91 std::size_t toNativeString(
92 TSpan<char> out_buffer,
93 std::size_t* out_numTotalChars = nullptr,
94 bool isNullTerminated = true) const;
95
98 std::filesystem::path toStdPath() const;
99
101
103
107 std::string getFilename() const;
108
113 std::string getExtension() const;
114
119 Path getLeadingElement() const;
120
127 Path getTrailingElement(bool ignoreTrailingSeparator = true) const;
128
132 Path getParent() const;
133
134 // TODO: replace/remove filename
135
139 Path replaceExtension(std::string_view replacement) const;
140
143 Path removeExtension() const;
144
145 Path operator / (const Path& other) const;
146 Path operator / (std::string_view pathStr) const;
147 bool operator == (const Path& other) const;
148
149private:
150 static wchar_t charToWchar(const char ch);
151
152 std::filesystem::path m_path;
153};
154
155inline bool Path::isRelative() const
156{
157 return m_path.is_relative();
158}
159
160inline bool Path::isAbsolute() const
161{
162 return m_path.is_absolute();
163}
164
165inline bool Path::isEmpty() const
166{
167 return m_path.empty();
168}
169
170inline void Path::clear()
171{
172 m_path.clear();
173}
174
175inline std::filesystem::path Path::toStdPath() const
176{
177 return m_path;
178}
179
180}// end namespace ph
181
PH_DEFINE_INLINE_TO_STRING_FORMATTER(ph::Path)
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
bool isRelative() const
Definition Path.h:155
Path removeExtension() const
Removes filename extension in the path, if any.
Definition Path.cpp:227
Path append(const Path &other) const
Definition Path.cpp:104
std::filesystem::path toStdPath() const
Get a standard path representation of this path.
Definition Path.h:175
void clear()
Definition Path.h:170
bool operator==(const Path &other) const
Definition Path.cpp:141
Path getLeadingElement() const
Definition Path.cpp:194
Path removeLeadingSeparator() const
Definition Path.cpp:146
std::string getFilename() const
Returns the filename if present.
Definition Path.cpp:184
std::string toNativeString() const
Get a string representation of this path in native format.
Definition Path.cpp:232
Path removeTrailingSeparator() const
Definition Path.cpp:165
Path getParent() const
Definition Path.cpp:217
std::string toString() const
Get a string representation of this path in generic format.
Definition Path.cpp:121
Path getTrailingElement(bool ignoreTrailingSeparator=true) const
Definition Path.cpp:201
Path toAbsolute() const
Definition Path.cpp:116
Path()
Creates empty path.
Definition Path.cpp:80
Path replaceExtension(std::string_view replacement) const
Changes filename extension in the path, if any. The behavior is the same as std::filesystem::path::re...
Definition Path.cpp:222
bool isEmpty() const
Definition Path.h:165
std::string getExtension() const
Returns filename extension if present. The extension string will start with a period character "....
Definition Path.cpp:189
Path operator/(const Path &other) const
Definition Path.cpp:131
std::string toAbsoluteString() const
Definition Path.cpp:126
bool isAbsolute() const
Definition Path.h:160
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12