Deserialize enums as well
This commit is contained in:
parent
7b6fe57aac
commit
9a2c2cfef6
|
@ -32,7 +32,8 @@ The following table shows the mapping of supported C++ types to supported JSON t
|
|||
* Raw pointer are not supported. This prevents
|
||||
forgetting to free memoery which would have to be allocated when deserializing.
|
||||
* For the same reason `const char *` strings are only supported for serialization.
|
||||
* Enums are only supported for serialization.
|
||||
* Enums are (de)serialized as their underlying integer value. When deserializing, it is currently *not* checked
|
||||
whether the present integer value is a valid enumeration item.
|
||||
* For deserialization, iteratables must provide an `emplace_back` method. So deserialization of eg. `std::forward_list`
|
||||
is currently not supported.
|
||||
* The JSON type for smart pointer depends on the type the pointer refers to. It can also be `null`.
|
||||
|
|
|
@ -359,6 +359,24 @@ inline void pull(
|
|||
reflectable = value.Get<Type>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pulls the specified enumeration item from the specified value which is supposed and checked to be compatible with the underlying type.
|
||||
* \remarks It is *not* checked, whether \a value is actually a valid enum item.
|
||||
*/
|
||||
template <typename Type, Traits::EnableIfAny<std::is_enum<Type>>...>
|
||||
inline void pull(
|
||||
Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
|
||||
{
|
||||
using ExpectedType = Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, uint64, int64>;
|
||||
if (!value.Is<ExpectedType>()) {
|
||||
if (errors) {
|
||||
errors->reportTypeMismatch<ExpectedType>(value.GetType());
|
||||
}
|
||||
return;
|
||||
}
|
||||
reflectable = static_cast<Type>(value.Get<ExpectedType>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pulls the std::string from the specified value which is supposed and checked to contain a string.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue