1 #ifndef SIMDJSON_ERROR_INL_H
2 #define SIMDJSON_ERROR_INL_H
4 #include "simdjson/error.h"
11 struct error_code_info {
16 extern SIMDJSON_DLLIMPORTEXPORT
const error_code_info error_codes[];
22 return internal::error_codes[int(error)].message;
26 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
28 if (error < 0 || error >= error_code::NUM_ERROR_CODES) {
31 return internal::error_codes[error].message;
46 simdjson_inline
void simdjson_result_base<T>::tie(T &value,
error_code &error) && noexcept {
49 value = std::forward<simdjson_result_base<T>>(*this).first;
54 simdjson_warn_unused simdjson_inline
error_code simdjson_result_base<T>::get(T &value) && noexcept {
56 std::forward<simdjson_result_base<T>>(*this).tie(value, error);
61 simdjson_inline
error_code simdjson_result_base<T>::error() const noexcept {
65 #if SIMDJSON_EXCEPTIONS
68 simdjson_inline T& simdjson_result_base<T>::value() & noexcept(
false) {
69 if (error()) {
throw simdjson_error(error()); }
74 simdjson_inline T&& simdjson_result_base<T>::value() && noexcept(
false) {
75 return std::forward<simdjson_result_base<T>>(*this).take_value();
79 simdjson_inline T&& simdjson_result_base<T>::take_value() && noexcept(
false) {
80 if (error()) {
throw simdjson_error(error()); }
81 return std::forward<T>(this->first);
85 simdjson_inline simdjson_result_base<T>::operator T&&() && noexcept(
false) {
86 return std::forward<simdjson_result_base<T>>(*this).take_value();
92 simdjson_inline
const T& simdjson_result_base<T>::value_unsafe() const& noexcept {
97 simdjson_inline T&& simdjson_result_base<T>::value_unsafe() && noexcept {
98 return std::forward<T>(this->first);
102 simdjson_inline simdjson_result_base<T>::simdjson_result_base(T &&value,
error_code error) noexcept
103 : std::pair<T, error_code>(std::forward<T>(value), error) {}
105 simdjson_inline simdjson_result_base<T>::simdjson_result_base(
error_code error) noexcept
106 : simdjson_result_base(T{}, error) {}
108 simdjson_inline simdjson_result_base<T>::simdjson_result_base(T &&value) noexcept
109 : simdjson_result_base(std::forward<T>(value),
SUCCESS) {}
111 simdjson_inline simdjson_result_base<T>::simdjson_result_base() noexcept
122 std::forward<internal::simdjson_result_base<T>>(*this).tie(value, error);
127 return std::forward<internal::simdjson_result_base<T>>(*this).get(value);
132 return internal::simdjson_result_base<T>::error();
135 #if SIMDJSON_EXCEPTIONS
139 return internal::simdjson_result_base<T>::value();
144 return std::forward<internal::simdjson_result_base<T>>(*this).value();
149 return std::forward<internal::simdjson_result_base<T>>(*this).take_value();
154 return std::forward<internal::simdjson_result_base<T>>(*this).
take_value();
161 return internal::simdjson_result_base<T>::value_unsafe();
166 return std::forward<internal::simdjson_result_base<T>>(*this).value_unsafe();
170 simdjson_inline simdjson_result<T>::simdjson_result(T &&value,
error_code error) noexcept
171 : internal::simdjson_result_base<T>(std::forward<T>(value), error) {}
173 simdjson_inline simdjson_result<T>::simdjson_result(
error_code error) noexcept
174 : internal::simdjson_result_base<T>(error) {}
176 simdjson_inline simdjson_result<T>::simdjson_result(T &&value) noexcept
177 : internal::simdjson_result_base<T>(std::forward<T>(value)) {}
179 simdjson_inline simdjson_result<T>::simdjson_result() noexcept
180 : internal::simdjson_result_base<T>() {}
The top level simdjson namespace, containing everything the library provides.
std::ostream & operator<<(std::ostream &out, error_code error) noexcept
Write the error message to the output stream.
const char * error_message(error_code error) noexcept
It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whethe...
error_code
All possible errors returned by simdjson.
@ UNEXPECTED_ERROR
indicative of a bug in simdjson
@ UNINITIALIZED
unknown error, or uninitialized document
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_inline const T & value_unsafe() const &noexcept
Get the result value.
simdjson_inline T && take_value() &&noexcept(false)
Take the result value (move it).
simdjson_inline void tie(T &value, error_code &error) &&noexcept
Move the value and the error to the provided variables.
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
simdjson_inline T & value() &noexcept(false)
Get the result value.