basic_json now supports getting many type of strings
This commit is contained in:
parent
d2dd27dc3b
commit
8165707990
@ -70,6 +70,25 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
|
||||
s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
||||
}
|
||||
|
||||
template <
|
||||
typename BasicJsonType, typename CompatibleStringType,
|
||||
enable_if_t <
|
||||
is_compatible_string_type<BasicJsonType, CompatibleStringType>::value and
|
||||
not std::is_same<typename BasicJsonType::string_t,
|
||||
CompatibleStringType>::value and
|
||||
std::is_constructible <
|
||||
BasicJsonType, typename CompatibleStringType::value_type >::value,
|
||||
int > = 0 >
|
||||
void from_json(const BasicJsonType& j, CompatibleStringType& s)
|
||||
{
|
||||
if (JSON_UNLIKELY(not j.is_string()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
||||
s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
||||
}
|
||||
|
||||
template<typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
|
||||
{
|
||||
|
@ -120,6 +120,16 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType>
|
||||
std::is_constructible<typename RealType::mapped_type, typename CompatibleObjectType::mapped_type>::value;
|
||||
};
|
||||
|
||||
template<bool B, class RealType, class CompatibleStringType>
|
||||
struct is_compatible_string_type_impl : std::false_type {};
|
||||
|
||||
template<class RealType, class CompatibleStringType>
|
||||
struct is_compatible_string_type_impl<true, RealType, CompatibleStringType>
|
||||
{
|
||||
static constexpr auto value =
|
||||
std::is_same<typename RealType::value_type, typename CompatibleStringType::value_type>::value;
|
||||
};
|
||||
|
||||
template<class BasicJsonType, class CompatibleObjectType>
|
||||
struct is_compatible_object_type
|
||||
{
|
||||
@ -130,6 +140,15 @@ struct is_compatible_object_type
|
||||
typename BasicJsonType::object_t, CompatibleObjectType >::value;
|
||||
};
|
||||
|
||||
template<class BasicJsonType, class CompatibleStringType>
|
||||
struct is_compatible_string_type
|
||||
{
|
||||
static auto constexpr value = is_compatible_string_type_impl <
|
||||
conjunction<negation<std::is_same<void, CompatibleStringType>>,
|
||||
has_value_type<CompatibleStringType>>::value,
|
||||
typename BasicJsonType::string_t, CompatibleStringType >::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename T>
|
||||
struct is_basic_json_nested_type
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user