1#ifndef REFLECTIVE_RAPIDJSON_JSON_ERROR_HANDLING_H
2#define REFLECTIVE_RAPIDJSON_JSON_ERROR_HANDLING_H
9#include <c++utilities/misc/traits.h>
11#include <rapidjson/rapidjson.h>
48template <
typename Type,
49 Traits::EnableIf<Traits::Not<std::is_same<Type, bool>>, Traits::Any<std::is_integral<Type>, std::is_floating_point<Type>>> * =
nullptr>
55template <
typename Type, Traits::EnableIfAny<std::is_same<Type,
bool>> * =
nullptr>
constexpr JsonType jsonType()
60template <
typename Type, Traits::EnableIfAny<Traits::IsString<Type>, Traits::IsCString<Type>> * =
nullptr>
constexpr JsonType jsonType()
65template <
typename Type,
66 Traits::EnableIf<Traits::IsIteratable<Type>,
67 Traits::Not<Traits::Any<Traits::IsString<Type>, Traits::IsSpecializationOf<Type, std::map>,
68 Traits::IsSpecializationOf<Type, std::unordered_map>>>> * =
nullptr>
74template <
typename Type,
75 Traits::DisableIfAny<std::is_integral<Type>, std::is_floating_point<Type>, Traits::IsString<Type>, Traits::IsCString<Type>,
76 Traits::All<Traits::IsIteratable<Type>,
77 Traits::Not<Traits::Any<Traits::IsString<Type>, Traits::IsSpecializationOf<Type, std::map>,
78 Traits::IsSpecializationOf<Type, std::unordered_map>>>>> * =
nullptr>
90 case RAPIDJSON_NAMESPACE::kFalseType:
91 case RAPIDJSON_NAMESPACE::kTrueType:
93 case RAPIDJSON_NAMESPACE::kObjectType:
95 case RAPIDJSON_NAMESPACE::kArrayType:
97 case RAPIDJSON_NAMESPACE::kStringType:
99 case RAPIDJSON_NAMESPACE::kNumberType:
127 static constexpr std::size_t
noIndex = std::numeric_limits<std::size_t>::max();
137 , expectedType(expectedType)
138 , actualType(actualType)
157 template <
typename ExpectedType>
void reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType);
158 template <RAPIDJSON_NAMESPACE::Type expectedType>
void reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType);
180 void throwMaybe(
ThrowOn on)
const;
187 : currentRecord(
"[document]")
188 , currentMember(nullptr)
207inline void JsonDeserializationErrors::throwMaybe(ThrowOn on)
const
209 if (
static_cast<std::uint8_t
>(
throwOn) &
static_cast<std::uint8_t
>(on)) {
constexpr JsonDeserializationErrors::ThrowOn operator|(JsonDeserializationErrors::ThrowOn lhs, JsonDeserializationErrors::ThrowOn rhs)
Combines to ThrowOn values.
JsonDeserializationErrorKind
The JsonDeserializationErrorKind enum specifies which kind of error happend when populating variables...
JsonType
The JsonType enum specifies the JSON data type.
constexpr JsonType jsonType()
The JsonDeserializationError struct describes any errors of fromJson() except such caused by invalid ...
JsonType expectedType
The expected type (might not be relevant for all error kinds).
std::size_t index
The index in the array which was being processed when the error was ascertained.
JsonType actualType
The actual type (might not be relevant for all error kinds).
const char * member
The name of the member which was being processed when the error was ascertained.
const char * record
The name of the class or struct which was being processed when the error was ascertained.
static constexpr std::size_t noIndex
Indicates no array was being processed when the error occurred.
JsonDeserializationError(JsonDeserializationErrorKind kind, JsonType expectedType, JsonType actualType, const char *record, const char *member=nullptr, std::size_t index=noIndex)
Constructs a new JsonDeserializationError.
JsonDeserializationErrorKind kind
Which kind of error occurred.
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
void reportConversionError(JsonType jsonType)
Reports a conversion error.
void reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType)
Reports a type mismatch between.
const char * currentMember
The name of the member (in currentRecord) which is currently being processed.
ThrowOn
The list of fatal error types in form of flags.
const char * currentRecord
The name of the class or struct which is currently being processed.
void reportUnexpectedDuplicate(JsonType jsonType)
Reports an unexpected duplicate.
void reportArraySizeMismatch()
Reports an array size mismatch.
enum ReflectiveRapidJSON::JsonDeserializationErrors::ThrowOn throwOn
std::size_t currentIndex
The index in the array which is currently processed.
JsonDeserializationErrors()
Creates an empty JsonDeserializationErrors object with default context and no errors considered fatal...