-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherror.hh
105 lines (84 loc) · 2.35 KB
/
error.hh
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
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
// # Error (enum etc)
#pragma once
#include "snn-core/array.hh"
#include "snn-core/error_code.hh"
namespace snn::time
{
// ## Enums
// ### error
enum class error : u8
{
no_error = 0,
invalid_hour,
invalid_minute,
invalid_second,
invalid_day,
invalid_format_string,
invalid_fraction,
invalid_offset,
invalid_offset_hour,
invalid_offset_minute,
invalid_month,
invalid_month_name,
invalid_nanosecond,
invalid_tzif_data,
invalid_week,
invalid_weekday_name,
invalid_year,
invalid_zone_abbreviation,
invalid_zone_name,
string_exceeds_max_size,
trailing_characters,
unescaped_alpha_character, // Last (used below).
};
// ## Constants
// ### error_count
inline constexpr usize error_count = 22;
static_assert(to_underlying(error::unescaped_alpha_character) == (error_count - 1));
// ## Arrays
// ### error_messages
inline constexpr array<null_term<const char*>, error_count> error_messages{
"No error",
"Invalid hour",
"Invalid minute",
"Invalid second",
"Invalid day",
"Invalid format string",
"Invalid fraction",
"Invalid offset",
"Invalid offset hour",
"Invalid offset minute",
"Invalid month",
"Invalid month name",
"Invalid nanosecond",
"Invalid TZif data",
"Invalid week",
"Invalid weekday name",
"Invalid year",
"Invalid zone abbreviation",
"Invalid zone name",
"String exceeds maximum size",
"Trailing characters",
"Unescaped alpha character",
};
// ## Constants
// ### error_category
inline constexpr error_category error_category{"snn::time", "Time", error_messages};
// ## Functions
// ### make_error_code
[[nodiscard]] constexpr error_code make_error_code(const error e) noexcept
{
return error_code{i32{to_underlying(e)}, error_category};
}
}
namespace snn
{
// ## Specializations
// ### is_error_code_enum_strict
template <>
struct is_error_code_enum_strict<time::error> : public std::true_type
{
};
}