CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
FilePath.hpp
Go to the documentation of this file.
1
2//
3// CeresEngine - A game development framework
4//
5// Created by Rogiel Sulzbach.
6// Copyright (c) 2018-2023 Rogiel Sulzbach. All rights reserved.
7//
8
9#pragma once
10
13
15
16#include <string>
17#include <filesystem>
18
19namespace CeresEngine {
20
37 class FilePath {
38 private:
41
42 public:
45
48
51
53 FilePath(const char* path);
54
55 FilePath(const FilePath&) = default;
56 FilePath(FilePath&&) = default;
57 FilePath& operator=(const FilePath&) = default;
59
61 virtual ~FilePath();
62
63 public:
76 [[nodiscard]] StringView getPath() const { return mPath; }
77
85
88 [[nodiscard]] bool isEmpty() const;
89
98
105
112
121
129
131 [[nodiscard]] FilePath getParentPath() const { return {getParent()}; }
132
140
143 [[nodiscard]] bool isAbsolute() const;
144
147 [[nodiscard]] bool isRelative() const;
148
156 [[nodiscard]] FilePath resolve(const FilePath& path) const;
157
170
172 [[nodiscard]] FilePath relativize(const FilePath& base) const;
173
175
178
180 [[nodiscard]] FilePath&& toRelative() && { return std::move(makeRelative()); }
181
183
186
188 [[nodiscard]] FilePath&& toAbsolute() && { return std::move(makeAbsolute()); }
189
190 public: // Operators
191 FilePath operator/(const FilePath& other) const;
193
194 public:
196 const String& toString() const { return mPath; }
197
198 std::filesystem::path toStdPath() const;
199
200 operator std::filesystem::path() const { return toStdPath(); }
201
202 protected:
204 void setPath(StringView path);
205
207 void setPath(String&& path);
208 };
209
210} // namespace CeresEngine
Path to file or directory.
Definition FilePath.hpp:37
const String & toString() const
The underlying path as a string in the unified format.
Definition FilePath.hpp:196
FilePath && toRelative() &&
Definition FilePath.hpp:180
FilePath toRelative() const &
Definition FilePath.hpp:177
FilePath resolve(const FilePath &path) const
Resolves a relative path from path.
StringView getExtension() const
Gets the path file extension.
FilePath & makeAbsolute()
String toNative() const
Gets the native path as string.
FilePath & operator=(FilePath &&)=default
void setPath(StringView path)
Sets a new path. Converts the path into the internal format.
StringView getBaseName() const
Gets the path base name.
bool isEmpty() const
Checks if path is empty.
FilePath toAbsolute() const &
Definition FilePath.hpp:185
FilePath(String &&path)
Creates a new FilePath by moving the contents of a path string.
std::filesystem::path toStdPath() const
bool isRelative() const
Check if path is a relative.
StringView getPath() const
Get path as string.
Definition FilePath.hpp:76
FilePath(const FilePath &)=default
FilePath & operator/=(const FilePath &other)
FilePath && toAbsolute() &&
Definition FilePath.hpp:188
void setPath(String &&path)
Sets a new path. Converts the path into the internal format.
FilePath & makeRelative()
StringView getFileName() const
Gets file name from the path.
virtual ~FilePath()
Destroys the FilePath instance.
FilePath normalize() const
Gets the normalized path (removed '.
StringView getDriveLetter() const
Gets drive letter on a Windows-style path.
FilePath operator/(const FilePath &other) const
StringView getParent() const
Gets the directory path.
FilePath(const char *path)
Creates a new FilePath from a const char* string.
FilePath(FilePath &&)=default
FilePath relativize(const FilePath &base) const
Relativizes this path to be a relative path from base.
bool isAbsolute() const
Checks if path is an absolute path.
String mPath
The underlying path as a string in the unified format.
Definition FilePath.hpp:40
FilePath()
Creates a new empty FilePath.
FilePath getParentPath() const
Gets the directory path.
Definition FilePath.hpp:131
StringView getFullPath() const
Gets full path.
FilePath(StringView path)
Creates a new FilePath from a string view that represents a path.
FilePath & operator=(const FilePath &)=default
Definition Application.hpp:19
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25