galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
FileError.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_FS_FILEERROR_HPP_
9#define GALAXY_FS_FILEERROR_HPP_
10
11#include <filesystem>
12#include <format>
13
14namespace galaxy
15{
19 class FileError final
20 {
21 public:
25 FileError() noexcept;
26
34 FileError(const std::string& mode, const std::string& reason, const std::filesystem::path& path) noexcept;
35
39 ~FileError() noexcept;
40
44 void log() const noexcept;
45
46 public:
50 std::string m_mode;
51
55 std::string m_reason;
56
60 std::filesystem::path m_path;
61 };
62} // namespace galaxy
63
64template<>
65struct std::formatter<std::filesystem::path> : std::formatter<std::string>
66{
67 auto format(const std::filesystem::path& path, format_context& ctx) const
68 {
69 return std::formatter<std::string>::format(path.string(), ctx);
70 }
71};
72
73template<>
74struct std::formatter<galaxy::FileError> : std::formatter<std::string>
75{
76 auto format(const galaxy::FileError& fe, format_context& ctx) const
77 {
78 return std::formatter<std::string>::format(std::format("Failed to {0} {2} because {1}", fe.m_mode, fe.m_reason, fe.m_path), ctx);
79 }
80};
81
82#endif
Stores information about a File I/O error.
Definition FileError.hpp:20
void log() const noexcept
Prints the file error in a nice format to the console.
Definition FileError.cpp:29
std::string m_reason
Reason for file i/o failure.
Definition FileError.hpp:55
std::string m_mode
File I/O mode.
Definition FileError.hpp:50
~FileError() noexcept
Destructor.
Definition FileError.cpp:25
std::filesystem::path m_path
Path error occured on.
Definition FileError.hpp:60
FileError() noexcept
Constructor.
Definition FileError.cpp:14
Timer.hpp galaxy.
Definition Timer.cpp:18
STL namespace.
auto format(const galaxy::FileError &fe, format_context &ctx) const
Definition FileError.hpp:76
auto format(const std::filesystem::path &path, format_context &ctx) const
Definition FileError.hpp:67