Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_env.hpp
Go to the documentation of this file.
1#pragma once
2#include "../foray_basics.hpp"
3#include "../foray_logger.hpp"
4#include <filesystem>
5#include <vector>
6
7namespace foray::osi {
9 std::filesystem::path FromUtf8Path(std::string_view utf8path);
11 std::filesystem::path FromUtf8Path(std::u8string_view utf8path);
13 std::string ToUtf8Path(std::filesystem::path path);
14
15 std::string_view CurrentWorkingDirectory();
16
17 void OverrideCurrentWorkingDirectory(std::string_view path);
18
19 std::string MakeRelativePath(const std::string_view relative);
20
28 {
29 protected:
31 std::string mPath;
35 std::vector<std::string_view> mPathSections;
36
38 void VerifyPath();
42 static void sBuildFromSections(std::string& path, const std::vector<std::string_view>& sections);
43
47 Utf8Path(const std::vector<std::string_view>& sections, bool relative);
48
49 public:
50 inline Utf8Path(const Utf8Path& other) : mPath(other.mPath) { VerifyPath(); }
51 inline Utf8Path(Utf8Path&& other) : mPath(other.mPath) { VerifyPath(); }
52 Utf8Path& operator=(const Utf8Path& other);
55 template <typename StringViewLike>
56 Utf8Path(const StringViewLike& path) : mPath(path), mRelative()
57 {
58 VerifyPath();
59 }
60
62 Utf8Path operator/(const Utf8Path& other) const;
65
67 operator const std::string&() const;
69 operator const char*() const;
71 operator std::filesystem::path() const;
72
73 bool operator==(const Utf8Path& other) const;
74 bool operator!=(const Utf8Path& other) const;
75 bool operator<(const Utf8Path& other) const;
76 bool operator>(const Utf8Path& other) const;
77
83 bool IsRelative() const;
86
87 FORAY_GETTER_V(Path)
88 FORAY_GETTER_CR(PathSections)
89 };
90} // namespace foray::osi
91
92namespace std {
93
94 template <>
95 struct hash<foray::osi::Utf8Path>
96 {
97 inline size_t operator()(const foray::osi::Utf8Path& p) const { return std::hash<std::string>()(p.GetPath()); }
98 };
99} // namespace std
Utf8 encoded path wrapper.
Definition foray_env.hpp:28
static void sBuildFromSections(std::string &path, const std::vector< std::string_view > &sections)
Builds a new path string (stored to path parameter) from sections.
bool mRelative
If true, the path is a relative path.
Definition foray_env.hpp:33
bool operator==(const Utf8Path &other) const
Utf8Path()
Default constructs with empty relative path.
Utf8Path(const Utf8Path &other)
Definition foray_env.hpp:50
std::string mPath
The stored path, encoded as UTF-8.
Definition foray_env.hpp:31
Utf8Path MakeAbsolute() const
Returns this path appended to the current working directory.
bool operator>(const Utf8Path &other) const
bool operator<(const Utf8Path &other) const
Utf8Path(Utf8Path &&other)
Definition foray_env.hpp:51
Utf8Path & operator=(const Utf8Path &other)
Utf8Path & operator/=(const Utf8Path &other)
Update this paths by navigating relative to self as dictated by other.
Utf8Path(const StringViewLike &path)
Definition foray_env.hpp:56
bool IsRelative() const
Returns true, if the path is detected to be relative.
bool operator!=(const Utf8Path &other) const
void BuildSectionVector()
Updates mPathSections.
Utf8Path operator/(const Utf8Path &other) const
Combine paths, interpreted as navigating relative of this path to the other path.
void VerifyPath()
Detects absolute paths, and clears '../' and './' navigators where possible.
Utf8Path(const std::vector< std::string_view > &sections, bool relative)
Builds mPath member by concatenating mPathSections.
operator std::filesystem::path() const
Gets the internally stored path.
std::vector< std::string_view > mPathSections
Directory and file names making up this path. References sections in mPath, result of splitting by '/...
Definition foray_env.hpp:35
#define FORAY_GETTER_V(member)
Return value.
Definition foray_basics.hpp:39
#define FORAY_GETTER_CR(member)
Return constant reference.
Definition foray_basics.hpp:60
Definition foray_env.hpp:7
std::string MakeRelativePath(const std::string_view relative)
std::filesystem::path FromUtf8Path(std::string_view utf8path)
Convert UTF8 string path to absolute std::filesystem::path type.
std::string ToUtf8Path(std::filesystem::path path)
Convert std::filesystem::path type to UTF8 path.
std::string_view CurrentWorkingDirectory()
void OverrideCurrentWorkingDirectory(std::string_view path)
Definition foray_api.hpp:19
Definition foray_env.hpp:92
size_t operator()(const foray::osi::Utf8Path &p) const
Definition foray_env.hpp:97