CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
core_error.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <string_view>
12#include <cstdint>
13#include <format>
14#include <fmt/core.h>
15
16namespace CaptureMoment::Core {
17
26namespace ErrorHandling {
27
36enum class CoreError : uint8_t {
37 // ==========================================
38 // Success State
39 // ==========================================
40
44 Success = 0,
45
46 // ==========================================
47 // Image Processing Errors
48 // ==========================================
49
55
61
67
73
74 // ==========================================
75 // I/O Errors
76 // ==========================================
77
82 IOError = 5,
83
88 FileNotFound = 6,
89
95
100 DecodingError = 8,
101
106 SourceNotLoaded = 9,
107
108 // ==========================================
109 // System Errors
110 // ==========================================
111
116 Unexpected = 99
117};
118
124enum class CoreErrorCategory : uint8_t {
128 System = 0,
129
133 ImageProcessing = 1,
134
138 Serialization = 2,
139
143 Common = 3,
144
148 Source = 4
149};
150
151
152// ============================================================
153// Helpers (Conversion functions)
154// ============================================================
155
189
197[[nodiscard]] constexpr std::string_view to_string(CoreError code)
198{
199 switch (code)
200 {
201 case CoreError::Success: return "Success";
202 case CoreError::InvalidImageRegion: return "InvalidImageRegion";
203 case CoreError::AllocationFailed: return "AllocationFailed";
204 case CoreError::InvalidHalideBuffer: return "InvalidHalideBuffer";
205 case CoreError::InvalidWorkingImage: return "InvalidWorkingImage";
206 case CoreError::IOError: return "IOError";
207 case CoreError::Unexpected: return "Unexpected";
208 case CoreError::FileNotFound: return "FileNotFound";
209 case CoreError::UnsupportedFormat: return "UnsupportedFormat";
210 case CoreError::SourceNotLoaded: return "SourceNotLoaded";
211 case CoreError::DecodingError: return "DecodingError";
212 default: return "Unknown";
213 }
214}
215
222[[nodiscard]] constexpr std::string_view to_string(CoreErrorCategory category)
223{
224 switch (category)
225 {
226 case CoreErrorCategory::System: return "System";
227 case CoreErrorCategory::ImageProcessing: return "ImageProcessing";
228 case CoreErrorCategory::Serialization: return "Serialization";
229 case CoreErrorCategory::Common: return "Common";
230 case CoreErrorCategory::Source: return "Source";
231
232 default: return "Unknown";
233 }
234}
235
236} // namespace ErrorHandling
237
238} // namespace CaptureMoment::Core
239
244template <>
245struct std::formatter<CaptureMoment::Core::ErrorHandling::CoreError> : std::formatter<std::string_view>
246{
247 template <typename FormatContext>
248 auto format(const CaptureMoment::Core::ErrorHandling::CoreError code, FormatContext& ctx) const
249 {
250 return std::formatter<std::string_view>::format(
252 }
253};
263template <>
264struct fmt::formatter<CaptureMoment::Core::ErrorHandling::CoreError>
265{
266 template <typename ParseContext>
267 constexpr auto parse(ParseContext& ctx) {
268 return ctx.begin();
269 }
270
271 template <typename FormatContext>
272 auto format(const CaptureMoment::Core::ErrorHandling::CoreError& code, FormatContext& ctx) const {
273 const auto sv { CaptureMoment::Core::ErrorHandling::to_string(code) };
274 auto out = ctx.out();
275 for (const char c : sv) {
276 *out++ = c;
277 }
278 return out;
279 }
280};
constexpr std::string_view to_string(CoreError code)
Converts a CoreError code to a human-readable string.
Definition core_error.h:197
CoreErrorCategory
Enumeration of high-level error categories.
Definition core_error.h:124
@ Serialization
Errors related to Serialization, File I/O, or Network.
@ System
General system or unknown errors.
@ Common
General errors applicable to multiple subsystems.
@ ImageProcessing
Errors related to Image Processing, GPU, or Memory.
@ Source
Specific to SourceManager, file loading, and caching.
CoreError
Enumeration of all error codes for CaptureMoment Core.
Definition core_error.h:36
@ InvalidImageRegion
The provided ImageRegion dimensions or data are invalid.
@ FileNotFound
The specified file path does not exist.
@ DecodingError
Failed to decode the image data.
@ Success
Operation completed successfully.
@ SourceNotLoaded
Attempted to access image data without loading a file first.
@ InvalidWorkingImage
The working image state is invalid or corrupted.
@ AllocationFailed
Memory allocation failed.
@ Unexpected
An unexpected error occurred.
@ UnsupportedFormat
The file format is not supported by OIIO or the system.
@ InvalidHalideBuffer
Halide buffer is invalid or undefined.
constexpr CoreErrorCategory get_error_category(CoreError code)
Converts a CoreError code to its high-level Category.
Definition core_error.h:162
Manages the lifecycle of a single IWorkingImage instance.
Contains the error handling infrastructure for the Core library.
auto format(const CaptureMoment::Core::ErrorHandling::CoreError &code, FormatContext &ctx) const
Definition core_error.h:272
auto format(const CaptureMoment::Core::ErrorHandling::CoreError code, FormatContext &ctx) const
Definition core_error.h:248
CaptureMoment — footer