errors.hpp
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
#ifndef CRUCIBLE_WINDOWS_ERRORS_HPP #define CRUCIBLE_WINDOWS_ERRORS_HPP #include "crucible/core/either.inl" #include "crucible/core/errors.hpp" #include <cstdint> #include <functional> #include <optional> #include <string> #include <variant> namespace crucible::windows::errors { class HostError : public core::errors::AbstractError { public: HostError(); ~HostError() override; [[nodiscard]] auto describe() const -> std::string override; [[nodiscard]] auto format() const -> std::string override; [[nodiscard]] auto source() const & -> std::optional<std::reference_wrapper<core::errors::AbstractError const>> override; private: std::uint32_t my_error_code { 0 }; auto format_error_code() const -> std::string; }; struct CreateDirectoryWFailed final { HostError host_error {}; }; struct CreateFileWFailed final { HostError host_error {}; }; struct GetFileAttributesWFailed final { HostError host_error {}; }; struct GetFileSizeExFailed final { HostError host_error {}; }; struct FindFirstFileWFailed final { HostError host_error {}; }; struct FindNextFileWFailed final { HostError host_error {}; }; struct MultiByteToWideCharFailed final { HostError host_error {}; }; struct ReadFileFailed final { HostError host_error {}; }; struct RemoveDirectoryWFailed final { HostError host_error {}; }; struct DeleteFileWFailed final { HostError host_error {}; }; struct WideCharToMultiByteFailed final { HostError host_error {}; }; struct WriteFileFailed final { HostError host_error {}; }; struct InputTooLarge final { }; struct NegativeFileSize final { }; struct OutputTruncated final { }; class WindowsError final : public core::errors::AbstractError { public: explicit WindowsError(CreateDirectoryWFailed const &variant); explicit WindowsError(CreateFileWFailed const &variant); explicit WindowsError(GetFileAttributesWFailed const &variant); explicit WindowsError(GetFileSizeExFailed const &variant); explicit WindowsError(FindFirstFileWFailed const &variant); explicit WindowsError(FindNextFileWFailed const &variant); explicit WindowsError(MultiByteToWideCharFailed const &variant); explicit WindowsError(ReadFileFailed const &variant); explicit WindowsError(RemoveDirectoryWFailed const &variant); explicit WindowsError(DeleteFileWFailed const &variant); explicit WindowsError(WideCharToMultiByteFailed const &variant); explicit WindowsError(WriteFileFailed const &variant); explicit WindowsError(InputTooLarge const &variant); explicit WindowsError(NegativeFileSize const &variant); explicit WindowsError(OutputTruncated const &variant); ~WindowsError() override; template<typename T> [[nodiscard]] auto is() const -> bool { return std::holds_alternative<T>(my_variant); } [[nodiscard]] auto describe() const -> std::string override; [[nodiscard]] auto format() const -> std::string override; [[nodiscard]] auto source() const & -> std::optional<std::reference_wrapper<core::errors::AbstractError const>> override; private: std::variant<CreateDirectoryWFailed, CreateFileWFailed, GetFileAttributesWFailed, GetFileSizeExFailed, FindFirstFileWFailed, FindNextFileWFailed, MultiByteToWideCharFailed, ReadFileFailed, RemoveDirectoryWFailed, DeleteFileWFailed, WideCharToMultiByteFailed, WriteFileFailed, InputTooLarge, NegativeFileSize, OutputTruncated> my_variant; }; template<typename T> using WindowsResult = core::either::Either<WindowsError, T>; } #endif // CRUCIBLE_WINDOWS_ERRORS_HPP