blob: 7f57fec905d8ad4a54d23c8b1b9cb1c7cb7b5b30 (
plain) (
blame)
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
|
// This source code is released into the public domain.
export module nihil.core:errc;
import nihil.std;
namespace nihil {
export enum struct errc : std::uint8_t {
no_error = 0,
///////////////////////////////////////////////////////////////
// nihil.cli
incomplete_command,
usage_error,
///////////////////////////////////////////////////////////////
// nihil.ucl
failed_to_create_object,
type_mismatch,
///////////////////////////////////////////////////////////////
// nihil.util
// Empty string is not allowed.
empty_string,
// Invalid unit, e.g. in parse_size()
invalid_unit,
};
struct nihil_error_category final : std::error_category
{
[[nodiscard]] auto name() const noexcept -> char const * override
{
return "nihil";
}
[[nodiscard]] auto message(int err) const -> std::string override
{
switch (static_cast<errc>(err)) {
case errc::no_error:
return "No error";
case errc::incomplete_command:
return "Incomplete command";
case errc::usage_error:
return "Usage error";
case errc::empty_string:
return "Empty string is not permitted";
case errc::invalid_unit:
return "Invalid unit specifier";
case errc::failed_to_create_object:
return "Failed to create UCL object";
case errc::type_mismatch:
return "UCL type does not match expected type";
default:
return "Undefined error";
}
}
};
export [[nodiscard]] auto nihil_category() noexcept -> std::error_category &
{
static auto category = nihil_error_category();
return category;
}
export [[nodiscard]] auto make_error_condition(errc ec) -> std::error_condition
{
return {static_cast<int>(ec), nihil_category()};
}
} // namespace nihil
export template <>
struct std::is_error_condition_enum<nihil::errc> : std::true_type
{
};
|