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
150
151
152
153
154
155
156
|
/*
* libfud
* Copyright 2024 Dominick Allen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FUD_STATUS_HPP
#define FUD_STATUS_HPP
#include <cstdint>
namespace fud {
// NOLINTNEXTLINE(performance-enum-size)
enum class [[nodiscard]] FudStatus : int32_t
{
/** \brief Indisputable success. */
Success = 0,
/** \brief Either partially succeeding, or failing in a recoverable way. */
Partial,
/** \brief Typically a major failure in an underlying system call. */
Failure,
/** \brief An argument passed in was a null pointer and is invalid. */
NullPointer,
/** \brief An argument passed in is in an invalid state or mismatches with other arguments. */
ArgumentInvalid,
/** \brief An handle to a managed object is not valid. */
HandleInvalid,
/** \brief An object is uninitialized or no longer valid. */
ObjectInvalid,
/** \brief A utf sequence in a string is invalid. */
Utf8Invalid,
/** \brief A string is not terminated or has a length field exceeding its capacity. */
StringInvalid,
/** \brief The requested operation on the object is not valid for its current state. */
OperationInvalid,
/** \brief An object which is to be initialized has already been initialized. */
AlreadyInitialized,
/** \brief A format string is invalid. */
FormatInvalid,
/** \brief A string being parsed as a number is out of range for the requested type. */
RangeError,
/** \brief The given index is not in range of a randomly accessible container. */
IndexInvalid,
/** \brief An object in a container already exists in the requested slot for a new object. */
Exists,
/** \brief An object in a container does not exist in the requested slot for an existing object. */
NotFound,
/** \brief A container is empty when something was expected to be present. */
Empty,
/** \brief A container is full when attempting to add something to it. */
Full,
/** \brief An operation requiring elevated permissions failed. */
PermissionDenied,
/** \brief Two or more objects overlap when they are expected to be distinct. */
Aliased,
/** \brief An requested allocation could not be completed. */
AllocFailure,
/** \brief An requested deallocation could not be completed. */
DeallocFailure,
/** \brief The function is not implemented, but is planned to be implemented. */
NotImplemented,
/** \brief The function or desired mode of action for a function is not supported. */
NotSupported
};
constexpr const char* FudStatusToString(FudStatus status)
{
switch (status) {
case FudStatus::Success:
return "Success";
case FudStatus::Partial:
return "Partial";
case FudStatus::Failure:
return "Failure";
case FudStatus::NullPointer:
return "NullPointer";
case FudStatus::ArgumentInvalid:
return "ArgumentInvalid";
case FudStatus::HandleInvalid:
return "HandleInvalid";
case FudStatus::ObjectInvalid:
return "ObjectInvalid";
case FudStatus::StringInvalid:
return "StringInvalid";
case FudStatus::OperationInvalid:
return "OperationInvalid";
case FudStatus::Utf8Invalid:
return "Utf8Invalid";
case FudStatus::RangeError:
return "RangeError";
case FudStatus::FormatInvalid:
return "FormatInvalid";
case FudStatus::AlreadyInitialized:
return "AlreadyInitialized";
case FudStatus::IndexInvalid:
return "IndexInvalid";
case FudStatus::Exists:
return "Exists";
case FudStatus::NotFound:
return "NotFound";
case FudStatus::Empty:
return "Empty";
case FudStatus::Full:
return "Full";
case FudStatus::PermissionDenied:
return "PermissionDenied";
case FudStatus::Aliased:
return "Aliased";
case FudStatus::AllocFailure:
return "AllocFailure";
case FudStatus::DeallocFailure:
return "DeallocFailure";
case FudStatus::NotImplemented:
return "NotImplemented";
case FudStatus::NotSupported:
return "NotSupported";
default:
return "Unknown";
}
}
constexpr bool anyAreNull()
{
return false;
}
template <typename T>
constexpr bool anyAreNull(const T* pointer)
{
return pointer == nullptr;
}
template <typename T, typename... Ts>
constexpr bool anyAreNull(T pointer, Ts... pointers)
{
if (pointer == nullptr) {
return true;
}
return anyAreNull(pointers...);
}
} // namespace fud
#endif
|