Commit 3e15b551 by Théo DELRIEU

run make pretty

parent fbac056c
...@@ -168,7 +168,7 @@ using is_unscoped_enum = ...@@ -168,7 +168,7 @@ using is_unscoped_enum =
namespace detail namespace detail
{ {
template <typename Json> std::string type_name(const Json &j) template <typename Json> std::string type_name(const Json& j)
{ {
switch (j.m_type) switch (j.m_type)
{ {
...@@ -190,7 +190,7 @@ template <typename Json> std::string type_name(const Json &j) ...@@ -190,7 +190,7 @@ template <typename Json> std::string type_name(const Json &j)
} }
// dispatch utility (taken from ranges-v3) // dispatch utility (taken from ranges-v3)
template <unsigned N> struct priority_tag : priority_tag<N - 1> {}; template <unsigned N> struct priority_tag : priority_tag < N - 1 > {};
template <> struct priority_tag<0> {}; template <> struct priority_tag<0> {};
...@@ -202,7 +202,7 @@ template <> ...@@ -202,7 +202,7 @@ template <>
struct external_constructor<value_t::boolean> struct external_constructor<value_t::boolean>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::boolean_t b) noexcept static void construct(Json& j, typename Json::boolean_t b) noexcept
{ {
j.m_type = value_t::boolean; j.m_type = value_t::boolean;
j.m_value = b; j.m_value = b;
...@@ -214,7 +214,7 @@ template <> ...@@ -214,7 +214,7 @@ template <>
struct external_constructor<value_t::string> struct external_constructor<value_t::string>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, const typename Json::string_t& s) static void construct(Json& j, const typename Json::string_t& s)
{ {
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = s; j.m_value = s;
...@@ -226,7 +226,7 @@ template <> ...@@ -226,7 +226,7 @@ template <>
struct external_constructor<value_t::number_float> struct external_constructor<value_t::number_float>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::number_float_t val) noexcept static void construct(Json& j, typename Json::number_float_t val) noexcept
{ {
// replace infinity and NAN by null // replace infinity and NAN by null
if (not std::isfinite(val)) if (not std::isfinite(val))
...@@ -244,7 +244,7 @@ template <> ...@@ -244,7 +244,7 @@ template <>
struct external_constructor<value_t::number_unsigned> struct external_constructor<value_t::number_unsigned>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::number_unsigned_t val) noexcept static void construct(Json& j, typename Json::number_unsigned_t val) noexcept
{ {
j.m_type = value_t::number_unsigned; j.m_type = value_t::number_unsigned;
j.m_value = val; j.m_value = val;
...@@ -256,7 +256,7 @@ template <> ...@@ -256,7 +256,7 @@ template <>
struct external_constructor<value_t::number_integer> struct external_constructor<value_t::number_integer>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::number_integer_t val) noexcept static void construct(Json& j, typename Json::number_integer_t val) noexcept
{ {
j.m_type = value_t::number_integer; j.m_type = value_t::number_integer;
j.m_value = val; j.m_value = val;
...@@ -268,7 +268,7 @@ template <> ...@@ -268,7 +268,7 @@ template <>
struct external_constructor<value_t::array> struct external_constructor<value_t::array>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, const typename Json::array_t& arr) static void construct(Json& j, const typename Json::array_t& arr)
{ {
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = arr; j.m_value = arr;
...@@ -279,7 +279,7 @@ struct external_constructor<value_t::array> ...@@ -279,7 +279,7 @@ struct external_constructor<value_t::array>
enable_if_t<not std::is_same<CompatibleArrayType, enable_if_t<not std::is_same<CompatibleArrayType,
typename Json::array_t>::value, typename Json::array_t>::value,
int> = 0> int> = 0>
static void construct(Json &j, const CompatibleArrayType &arr) static void construct(Json& j, const CompatibleArrayType& arr)
{ {
using std::begin; using std::begin;
using std::end; using std::end;
...@@ -294,7 +294,7 @@ template <> ...@@ -294,7 +294,7 @@ template <>
struct external_constructor<value_t::object> struct external_constructor<value_t::object>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, const typename Json::object_t& obj) static void construct(Json& j, const typename Json::object_t& obj)
{ {
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = obj; j.m_value = obj;
...@@ -305,7 +305,7 @@ struct external_constructor<value_t::object> ...@@ -305,7 +305,7 @@ struct external_constructor<value_t::object>
enable_if_t<not std::is_same<CompatibleObjectType, enable_if_t<not std::is_same<CompatibleObjectType,
typename Json::object_t>::value, typename Json::object_t>::value,
int> = 0> int> = 0>
static void construct(Json &j, const CompatibleObjectType &obj) static void construct(Json& j, const CompatibleObjectType& obj)
{ {
using std::begin; using std::begin;
using std::end; using std::end;
...@@ -380,11 +380,11 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType> ...@@ -380,11 +380,11 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType>
template<class BasicJson, class CompatibleObjectType> template<class BasicJson, class CompatibleObjectType>
struct is_compatible_object_type struct is_compatible_object_type
{ {
static auto constexpr value = is_compatible_object_type_impl< static auto constexpr value = is_compatible_object_type_impl <
conjunction<negation<std::is_same<void, CompatibleObjectType>>, conjunction<negation<std::is_same<void, CompatibleObjectType>>,
has_mapped_type<CompatibleObjectType>, has_mapped_type<CompatibleObjectType>,
has_key_type<CompatibleObjectType>>::value, has_key_type<CompatibleObjectType>>::value,
typename BasicJson::object_t, CompatibleObjectType>::value; typename BasicJson::object_t, CompatibleObjectType >::value;
}; };
template <typename BasicJson, typename T> template <typename BasicJson, typename T>
...@@ -461,15 +461,15 @@ struct has_from_json ...@@ -461,15 +461,15 @@ struct has_from_json
template <typename Json, typename T> template <typename Json, typename T>
struct has_non_default_from_json struct has_non_default_from_json
{ {
private: private:
template < template <
typename U, typename U,
typename = enable_if_t<std::is_same< typename = enable_if_t<std::is_same<
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>> T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value >>
static int detect(U &&); static int detect(U&&);
static void detect(...); static void detect(...);
public: public:
static constexpr bool value = std::is_integral<decltype(detect( static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value; std::declval<typename Json::template json_serializer<T, void>>()))>::value;
}; };
...@@ -478,13 +478,13 @@ public: ...@@ -478,13 +478,13 @@ public:
template <typename Json, typename T> template <typename Json, typename T>
struct has_to_json struct has_to_json
{ {
private: private:
template <typename U, typename = decltype(uncvref_t<U>::to_json( template <typename U, typename = decltype(uncvref_t<U>::to_json(
std::declval<Json &>(), std::declval<T>()))> std::declval<Json&>(), std::declval<T>()))>
static int detect(U &&); static int detect(U&&);
static void detect(...); static void detect(...);
public: public:
static constexpr bool value = std::is_integral<decltype(detect( static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value; std::declval<typename Json::template json_serializer<T, void>>()))>::value;
}; };
...@@ -496,21 +496,29 @@ template <typename Json, typename ArithmeticType, ...@@ -496,21 +496,29 @@ template <typename Json, typename ArithmeticType,
not std::is_same<ArithmeticType, not std::is_same<ArithmeticType,
typename Json::boolean_t>::value, typename Json::boolean_t>::value,
int> = 0> int> = 0>
void get_arithmetic_value(const Json &j, ArithmeticType &val) void get_arithmetic_value(const Json& j, ArithmeticType& val)
{ {
// unsigned must be checked first, since is_number_integer() == true for unsigned // unsigned must be checked first, since is_number_integer() == true for unsigned
if (j.is_number_unsigned()) if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer()) else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float()) else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else else
{
throw std::domain_error("type must be number, but is " + type_name(j)); throw std::domain_error("type must be number, but is " + type_name(j));
}
} }
template <typename Json> template <typename Json>
void to_json(Json &j, typename Json::boolean_t b) noexcept void to_json(Json& j, typename Json::boolean_t b) noexcept
{ {
external_constructor<value_t::boolean>::construct(j, b); external_constructor<value_t::boolean>::construct(j, b);
} }
...@@ -519,14 +527,14 @@ template <typename Json, typename CompatibleString, ...@@ -519,14 +527,14 @@ template <typename Json, typename CompatibleString,
enable_if_t<std::is_constructible<typename Json::string_t, enable_if_t<std::is_constructible<typename Json::string_t,
CompatibleString>::value, CompatibleString>::value,
int> = 0> int> = 0>
void to_json(Json &j, const CompatibleString &s) void to_json(Json& j, const CompatibleString& s)
{ {
external_constructor<value_t::string>::construct(j, s); external_constructor<value_t::string>::construct(j, s);
} }
template <typename Json, typename FloatType, template <typename Json, typename FloatType,
enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
void to_json(Json &j, FloatType val) noexcept void to_json(Json& j, FloatType val) noexcept
{ {
external_constructor<value_t::number_float>::construct(j, static_cast<typename Json::number_float_t>(val)); external_constructor<value_t::number_float>::construct(j, static_cast<typename Json::number_float_t>(val));
} }
...@@ -536,8 +544,8 @@ template < ...@@ -536,8 +544,8 @@ template <
typename Json, typename CompatibleNumberUnsignedType, typename Json, typename CompatibleNumberUnsignedType,
enable_if_t<is_compatible_integer_type<typename Json::number_unsigned_t, enable_if_t<is_compatible_integer_type<typename Json::number_unsigned_t,
CompatibleNumberUnsignedType>::value, CompatibleNumberUnsignedType>::value,
int> = 0> int> = 0 >
void to_json(Json &j, CompatibleNumberUnsignedType val) noexcept void to_json(Json& j, CompatibleNumberUnsignedType val) noexcept
{ {
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename Json::number_unsigned_t>(val)); external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename Json::number_unsigned_t>(val));
} }
...@@ -546,26 +554,26 @@ template < ...@@ -546,26 +554,26 @@ template <
typename Json, typename CompatibleNumberIntegerType, typename Json, typename CompatibleNumberIntegerType,
enable_if_t<is_compatible_integer_type<typename Json::number_integer_t, enable_if_t<is_compatible_integer_type<typename Json::number_integer_t,
CompatibleNumberIntegerType>::value, CompatibleNumberIntegerType>::value,
int> = 0> int> = 0 >
void to_json(Json &j, CompatibleNumberIntegerType val) noexcept void to_json(Json& j, CompatibleNumberIntegerType val) noexcept
{ {
external_constructor<value_t::number_integer>::construct(j, static_cast<typename Json::number_integer_t>(val)); external_constructor<value_t::number_integer>::construct(j, static_cast<typename Json::number_integer_t>(val));
} }
template <typename Json, typename UnscopedEnumType, template <typename Json, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0> enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void to_json(Json &j, UnscopedEnumType e) noexcept void to_json(Json& j, UnscopedEnumType e) noexcept
{ {
external_constructor<value_t::number_integer>::construct(j, e); external_constructor<value_t::number_integer>::construct(j, e);
} }
template < template <
typename Json, typename CompatibleArrayType, typename Json, typename CompatibleArrayType,
enable_if_t< enable_if_t <
is_compatible_array_type<Json, CompatibleArrayType>::value or is_compatible_array_type<Json, CompatibleArrayType>::value or
std::is_same<typename Json::array_t, CompatibleArrayType>::value, std::is_same<typename Json::array_t, CompatibleArrayType>::value,
int> = 0> int > = 0 >
void to_json(Json &j, const CompatibleArrayType &arr) void to_json(Json& j, const CompatibleArrayType& arr)
{ {
external_constructor<value_t::array>::construct(j, arr); external_constructor<value_t::array>::construct(j, arr);
} }
...@@ -573,49 +581,53 @@ void to_json(Json &j, const CompatibleArrayType &arr) ...@@ -573,49 +581,53 @@ void to_json(Json &j, const CompatibleArrayType &arr)
template < template <
typename Json, typename CompatibleObjectType, typename Json, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value, enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value,
int> = 0> int> = 0 >
void to_json(Json &j, const CompatibleObjectType &arr) void to_json(Json& j, const CompatibleObjectType& arr)
{ {
external_constructor<value_t::object>::construct(j, arr); external_constructor<value_t::object>::construct(j, arr);
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::boolean_t& b) void from_json(const Json& j, typename Json::boolean_t& b)
{ {
if (!j.is_boolean()) if (!j.is_boolean())
{
throw std::domain_error("type must be boolean, but is " + type_name(j)); throw std::domain_error("type must be boolean, but is " + type_name(j));
}
b = *j.template get_ptr<const typename Json::boolean_t*>(); b = *j.template get_ptr<const typename Json::boolean_t*>();
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::string_t& s) void from_json(const Json& j, typename Json::string_t& s)
{ {
if (!j.is_string()) if (!j.is_string())
{
throw std::domain_error("type must be string, but is " + type_name(j)); throw std::domain_error("type must be string, but is " + type_name(j));
}
s = *j.template get_ptr<const typename Json::string_t*>(); s = *j.template get_ptr<const typename Json::string_t*>();
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::number_float_t& val) void from_json(const Json& j, typename Json::number_float_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::number_unsigned_t& val) void from_json(const Json& j, typename Json::number_unsigned_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::number_integer_t& val) void from_json(const Json& j, typename Json::number_integer_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template <typename Json, typename UnscopedEnumType, template <typename Json, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0> enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void from_json(const Json &j, UnscopedEnumType& e) void from_json(const Json& j, UnscopedEnumType& e)
{ {
typename std::underlying_type<UnscopedEnumType>::type val = e; typename std::underlying_type<UnscopedEnumType>::type val = e;
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
...@@ -623,38 +635,46 @@ void from_json(const Json &j, UnscopedEnumType& e) ...@@ -623,38 +635,46 @@ void from_json(const Json &j, UnscopedEnumType& e)
} }
template <typename Json> template <typename Json>
void from_json(const Json &j, typename Json::array_t &arr) void from_json(const Json& j, typename Json::array_t& arr)
{ {
if (!j.is_array()) if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
}
arr = *j.template get_ptr<const typename Json::array_t*>(); arr = *j.template get_ptr<const typename Json::array_t*>();
} }
// forward_list doesn't have an insert method, TODO find a way to avoid including forward_list // forward_list doesn't have an insert method, TODO find a way to avoid including forward_list
template <typename Json, typename T, typename Allocator> template <typename Json, typename T, typename Allocator>
void from_json(const Json &j, std::forward_list<T, Allocator>& l) void from_json(const Json& j, std::forward_list<T, Allocator>& l)
{ {
// do not perform the check when user wants to retrieve jsons // do not perform the check when user wants to retrieve jsons
// (except when it's null.. ?) // (except when it's null.. ?)
if (j.is_null()) if (j.is_null())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
}
if (not std::is_same<T, Json>::value) if (not std::is_same<T, Json>::value)
{ {
if (!j.is_array()) if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
} }
}
for (auto it = j.rbegin(), end = j.rend(); it != end; ++it) for (auto it = j.rbegin(), end = j.rend(); it != end; ++it)
{
l.push_front(it->template get<T>()); l.push_front(it->template get<T>());
}
} }
template <typename Json, typename CompatibleArrayType> template <typename Json, typename CompatibleArrayType>
void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag<0>) void from_json_array_impl(const Json& j, CompatibleArrayType& arr, priority_tag<0>)
{ {
using std::begin; using std::begin;
using std::end; using std::end;
std::transform( std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &i) j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json & i)
{ {
// get<Json>() returns *this, this won't call a from_json method when // get<Json>() returns *this, this won't call a from_json method when
// value_type is Json // value_type is Json
...@@ -663,8 +683,8 @@ void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag ...@@ -663,8 +683,8 @@ void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
} }
template <typename Json, typename CompatibleArrayType> template <typename Json, typename CompatibleArrayType>
auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag<1>) auto from_json_array_impl(const Json& j, CompatibleArrayType& arr, priority_tag<1>)
-> decltype( -> decltype(
arr.reserve(std::declval<typename CompatibleArrayType::size_type>()), arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
void()) void())
{ {
...@@ -673,7 +693,7 @@ auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag ...@@ -673,7 +693,7 @@ auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
arr.reserve(j.size()); arr.reserve(j.size());
std::transform( std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &i) j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json & i)
{ {
// get<Json>() returns *this, this won't call a from_json method when // get<Json>() returns *this, this won't call a from_json method when
// value_type is Json // value_type is Json
...@@ -686,29 +706,35 @@ template < ...@@ -686,29 +706,35 @@ template <
enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and
not std::is_same<typename Json::array_t, not std::is_same<typename Json::array_t,
CompatibleArrayType>::value, CompatibleArrayType>::value,
int> = 0> int> = 0 >
void from_json(const Json &j, CompatibleArrayType &arr) void from_json(const Json& j, CompatibleArrayType& arr)
{ {
if (j.is_null()) if (j.is_null())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
}
// when T == Json, do not check if value_t is correct // when T == Json, do not check if value_t is correct
if (not std::is_same<typename CompatibleArrayType::value_type, Json>::value) if (not std::is_same<typename CompatibleArrayType::value_type, Json>::value)
{ {
if (!j.is_array()) if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
} }
from_json_array_impl(j, arr, priority_tag<1>{}); }
from_json_array_impl(j, arr, priority_tag<1> {});
} }
template < template <
typename Json, typename CompatibleObjectType, typename Json, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value, enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value,
int> = 0> int> = 0 >
void from_json(const Json &j, CompatibleObjectType &obj) void from_json(const Json& j, CompatibleObjectType& obj)
{ {
if (!j.is_object()) if (!j.is_object())
{
throw std::domain_error("type must be object, but is " + type_name(j)); throw std::domain_error("type must be object, but is " + type_name(j));
}
auto inner_object = j.template get_ptr<const typename Json::object_t*>(); auto inner_object = j.template get_ptr<const typename Json::object_t*>();
using std::begin; using std::begin;
...@@ -724,25 +750,35 @@ void from_json(const Json &j, CompatibleObjectType &obj) ...@@ -724,25 +750,35 @@ void from_json(const Json &j, CompatibleObjectType &obj)
// in case of a custom BooleanType which is not an arithmetic type? // in case of a custom BooleanType which is not an arithmetic type?
template < template <
typename Json, typename ArithmeticType, typename Json, typename ArithmeticType,
enable_if_t< enable_if_t <
std::is_arithmetic<ArithmeticType>::value and std::is_arithmetic<ArithmeticType>::value and
not std::is_same<ArithmeticType, typename Json::number_unsigned_t>::value and not std::is_same<ArithmeticType, typename Json::number_unsigned_t>::value and
not std::is_same<ArithmeticType, typename Json::number_integer_t>::value and not std::is_same<ArithmeticType, typename Json::number_integer_t>::value and
not std::is_same<ArithmeticType, typename Json::number_float_t>::value and not std::is_same<ArithmeticType, typename Json::number_float_t>::value and
not std::is_same<ArithmeticType, typename Json::boolean_t>::value, not std::is_same<ArithmeticType, typename Json::boolean_t>::value,
int> = 0> int > = 0 >
void from_json(const Json &j, ArithmeticType &val) void from_json(const Json& j, ArithmeticType& val)
{ {
if (j.is_number_unsigned()) if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer()) else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float()) else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else if (j.is_boolean()) else if (j.is_boolean())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::boolean_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::boolean_t*>());
}
else else
{
throw std::domain_error("type must be number, but is " + type_name(j)); throw std::domain_error("type must be number, but is " + type_name(j));
}
} }
struct to_json_fn struct to_json_fn
...@@ -762,20 +798,20 @@ struct to_json_fn ...@@ -762,20 +798,20 @@ struct to_json_fn
static_assert(sizeof(Json) == 0, "to_json method in T's namespace can not be called"); static_assert(sizeof(Json) == 0, "to_json method in T's namespace can not be called");
} }
public: public:
template <typename Json, typename T> template <typename Json, typename T>
void operator()(Json &j, T &&val) const void operator()(Json& j, T&& val) const
noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val), priority_tag<1>{}))) noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val), priority_tag<1> {})))
{ {
return call(j, std::forward<T>(val), priority_tag<1>{}); return call(j, std::forward<T>(val), priority_tag<1> {});
} }
}; };
struct from_json_fn struct from_json_fn
{ {
private: private:
template <typename Json, typename T> template <typename Json, typename T>
auto call(const Json &j, T &val, priority_tag<1>) const auto call(const Json& j, T& val, priority_tag<1>) const
noexcept(noexcept(from_json(j, val))) noexcept(noexcept(from_json(j, val)))
-> decltype(from_json(j, val), void()) -> decltype(from_json(j, val), void())
{ {
...@@ -783,17 +819,17 @@ private: ...@@ -783,17 +819,17 @@ private:
} }
template <typename Json, typename T> template <typename Json, typename T>
void call(const Json &, T&, priority_tag<0>) const noexcept void call(const Json&, T&, priority_tag<0>) const noexcept
{ {
static_assert(sizeof(Json) == 0, "from_json method in T's namespace can not be called"); static_assert(sizeof(Json) == 0, "from_json method in T's namespace can not be called");
} }
public: public:
template <typename Json, typename T> template <typename Json, typename T>
void operator()(const Json &j, T &val) const void operator()(const Json& j, T& val) const
noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1>{}))) noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1> {})))
{ {
return call(j, val, priority_tag<1>{}); return call(j, val, priority_tag<1> {});
} }
}; };
...@@ -830,8 +866,8 @@ struct DecimalSeparator : std::numpunct<char> ...@@ -830,8 +866,8 @@ struct DecimalSeparator : std::numpunct<char>
inline namespace inline namespace
{ {
constexpr const auto & to_json = detail::static_const<detail::to_json_fn>::value; constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
constexpr const auto & from_json = detail::static_const<detail::from_json_fn>::value; constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
} }
// default JSONSerializer template argument, doesn't care about template argument // default JSONSerializer template argument, doesn't care about template argument
...@@ -846,7 +882,7 @@ struct adl_serializer ...@@ -846,7 +882,7 @@ struct adl_serializer
} }
template <typename Json, typename T> template <typename Json, typename T>
static void to_json(Json &j, T &&val) noexcept( static void to_json(Json& j, T&& val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<T>(val)))) noexcept(::nlohmann::to_json(j, std::forward<T>(val))))
{ {
::nlohmann::to_json(j, std::forward<T>(val)); ::nlohmann::to_json(j, std::forward<T>(val));
...@@ -947,7 +983,7 @@ class basic_json ...@@ -947,7 +983,7 @@ class basic_json
{ {
private: private:
template <::nlohmann::value_t> friend struct detail::external_constructor; template <::nlohmann::value_t> friend struct detail::external_constructor;
template <typename Json> friend std::string detail::type_name(const Json &); template <typename Json> friend std::string detail::type_name(const Json&);
/// workaround type for MSVC /// workaround type for MSVC
using basic_json_t = basic_json<ObjectType, ArrayType, StringType, using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
...@@ -1854,8 +1890,8 @@ class basic_json ...@@ -1854,8 +1890,8 @@ class basic_json
basic_json_t, U>::value and basic_json_t, U>::value and
detail::has_to_json<basic_json, U>::value, detail::has_to_json<basic_json, U>::value,
int> = 0> int> = 0>
basic_json(T &&val) noexcept(noexcept(JSONSerializer<U>::to_json( basic_json(T && val) noexcept(noexcept(JSONSerializer<U>::to_json(
std::declval<basic_json_t &>(), std::forward<T>(val)))) std::declval<basic_json_t&>(), std::forward<T>(val))))
{ {
JSONSerializer<U>::to_json(*this, std::forward<T>(val)); JSONSerializer<U>::to_json(*this, std::forward<T>(val));
} }
...@@ -3041,17 +3077,17 @@ class basic_json ...@@ -3041,17 +3077,17 @@ class basic_json
template < template <
typename T, typename T,
typename U = uncvref_t<T>, typename U = uncvref_t<T>,
enable_if_t< enable_if_t <
not std::is_same<basic_json_t, U>::value and not std::is_same<basic_json_t, U>::value and
detail::has_from_json<basic_json_t, U>::value and detail::has_from_json<basic_json_t, U>::value and
not detail::has_non_default_from_json<basic_json_t, not detail::has_non_default_from_json<basic_json_t,
U>::value, U>::value,
int> = 0> int > = 0 >
// do we really want the uncvref ? if a user call get<int &>, shouldn't we // do we really want the uncvref ? if a user call get<int &>, shouldn't we
// static assert ? // static assert ?
// i know there is a special behaviour for boolean_t* and such // i know there is a special behaviour for boolean_t* and such
auto get() const noexcept(noexcept(JSONSerializer<U>::from_json( auto get() const noexcept(noexcept(JSONSerializer<U>::from_json(
std::declval<const basic_json_t &>(), std::declval<U &>()))) std::declval<const basic_json_t&>(), std::declval<U&>())))
-> U -> U
{ {
static_assert(std::is_default_constructible<U>::value and static_assert(std::is_default_constructible<U>::value and
...@@ -3083,8 +3119,8 @@ class basic_json ...@@ -3083,8 +3119,8 @@ class basic_json
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_non_default_from_json<basic_json_t, detail::has_non_default_from_json<basic_json_t,
uncvref_t<T>>::value, uncvref_t<T>>::value,
int> = 0> int> = 0 >
uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<const basic_json_t &>()))) uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<const basic_json_t&>())))
{ {
return JSONSerializer<T>::from_json(*this); return JSONSerializer<T>::from_json(*this);
} }
...@@ -7871,7 +7907,10 @@ class basic_json ...@@ -7871,7 +7907,10 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
std::string type_name() const { return detail::type_name(*this); } std::string type_name() const
{
return detail::type_name(*this);
}
private: private:
/*! /*!
...@@ -9427,7 +9466,8 @@ class basic_json ...@@ -9427,7 +9466,8 @@ class basic_json
{ {
lexer_char_t yych; lexer_char_t yych;
unsigned int yyaccept = 0; unsigned int yyaccept = 0;
static const unsigned char yybm[] = { static const unsigned char yybm[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 32, 32, 0, 0, 32, 0, 0, 0, 32, 32, 0, 0, 32, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...@@ -9461,396 +9501,873 @@ class basic_json ...@@ -9461,396 +9501,873 @@ class basic_json
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
if ((m_limit - m_cursor) < 5) fill_line_buffer(5); // LCOV_EXCL_LINE if ((m_limit - m_cursor) < 5)
{
fill_line_buffer(5); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yybm[0+yych] & 32) { if (yybm[0 + yych] & 32)
{
goto basic_json_parser_6; goto basic_json_parser_6;
} }
if (yych <= '[') { if (yych <= '[')
if (yych <= '-') { {
if (yych <= '"') { if (yych <= '-')
if (yych <= 0x00) goto basic_json_parser_2; {
if (yych <= '!') goto basic_json_parser_4; if (yych <= '"')
{
if (yych <= 0x00)
{
goto basic_json_parser_2;
}
if (yych <= '!')
{
goto basic_json_parser_4;
}
goto basic_json_parser_9; goto basic_json_parser_9;
} else { }
if (yych <= '+') goto basic_json_parser_4; else
if (yych <= ',') goto basic_json_parser_10; {
if (yych <= '+')
{
goto basic_json_parser_4;
}
if (yych <= ',')
{
goto basic_json_parser_10;
}
goto basic_json_parser_12; goto basic_json_parser_12;
} }
} else { }
if (yych <= '9') { else
if (yych <= '/') goto basic_json_parser_4; {
if (yych <= '0') goto basic_json_parser_13; if (yych <= '9')
{
if (yych <= '/')
{
goto basic_json_parser_4;
}
if (yych <= '0')
{
goto basic_json_parser_13;
}
goto basic_json_parser_15; goto basic_json_parser_15;
} else { }
if (yych <= ':') goto basic_json_parser_17; else
if (yych <= 'Z') goto basic_json_parser_4; {
if (yych <= ':')
{
goto basic_json_parser_17;
}
if (yych <= 'Z')
{
goto basic_json_parser_4;
}
goto basic_json_parser_19; goto basic_json_parser_19;
} }
} }
} else { }
if (yych <= 'n') { else
if (yych <= 'e') { {
if (yych == ']') goto basic_json_parser_21; if (yych <= 'n')
{
if (yych <= 'e')
{
if (yych == ']')
{
goto basic_json_parser_21;
}
goto basic_json_parser_4;
}
else
{
if (yych <= 'f')
{
goto basic_json_parser_23;
}
if (yych <= 'm')
{
goto basic_json_parser_4; goto basic_json_parser_4;
} else { }
if (yych <= 'f') goto basic_json_parser_23;
if (yych <= 'm') goto basic_json_parser_4;
goto basic_json_parser_24; goto basic_json_parser_24;
} }
} else { }
if (yych <= 'z') { else
if (yych == 't') goto basic_json_parser_25; {
if (yych <= 'z')
{
if (yych == 't')
{
goto basic_json_parser_25;
}
goto basic_json_parser_4; goto basic_json_parser_4;
} else { }
if (yych <= '{') goto basic_json_parser_26; else
if (yych == '}') goto basic_json_parser_28; {
if (yych <= '{')
{
goto basic_json_parser_26;
}
if (yych == '}')
{
goto basic_json_parser_28;
}
goto basic_json_parser_4; goto basic_json_parser_4;
} }
} }
} }
basic_json_parser_2: basic_json_parser_2:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::end_of_input; break; } {
last_token_type = token_type::end_of_input;
break;
}
basic_json_parser_4: basic_json_parser_4:
++m_cursor; ++m_cursor;
basic_json_parser_5: basic_json_parser_5:
{ last_token_type = token_type::parse_error; break; } {
last_token_type = token_type::parse_error;
break;
}
basic_json_parser_6: basic_json_parser_6:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yybm[0+yych] & 32) { if (yybm[0 + yych] & 32)
{
goto basic_json_parser_6; goto basic_json_parser_6;
} }
{ continue; } {
continue;
}
basic_json_parser_9: basic_json_parser_9:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 0x1F) goto basic_json_parser_5; if (yych <= 0x1F)
if (yych <= 0x7F) goto basic_json_parser_31; {
if (yych <= 0xC1) goto basic_json_parser_5; goto basic_json_parser_5;
if (yych <= 0xF4) goto basic_json_parser_31; }
if (yych <= 0x7F)
{
goto basic_json_parser_31;
}
if (yych <= 0xC1)
{
goto basic_json_parser_5;
}
if (yych <= 0xF4)
{
goto basic_json_parser_31;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_10: basic_json_parser_10:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::value_separator; break; } {
last_token_type = token_type::value_separator;
break;
}
basic_json_parser_12: basic_json_parser_12:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') goto basic_json_parser_5; if (yych <= '/')
if (yych <= '0') goto basic_json_parser_13; {
if (yych <= '9') goto basic_json_parser_15; goto basic_json_parser_5;
}
if (yych <= '0')
{
goto basic_json_parser_13;
}
if (yych <= '9')
{
goto basic_json_parser_15;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_13: basic_json_parser_13:
yyaccept = 1; yyaccept = 1;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 'D') { if (yych <= 'D')
if (yych == '.') goto basic_json_parser_43; {
} else { if (yych == '.')
if (yych <= 'E') goto basic_json_parser_44; {
if (yych == 'e') goto basic_json_parser_44; goto basic_json_parser_43;
}
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
} }
basic_json_parser_14: basic_json_parser_14:
{ last_token_type = token_type::value_number; break; } {
last_token_type = token_type::value_number;
break;
}
basic_json_parser_15: basic_json_parser_15:
yyaccept = 1; yyaccept = 1;
m_marker = ++m_cursor; m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3) fill_line_buffer(3); // LCOV_EXCL_LINE if ((m_limit - m_cursor) < 3)
{
fill_line_buffer(3); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yybm[0+yych] & 64) { if (yybm[0 + yych] & 64)
{
goto basic_json_parser_15; goto basic_json_parser_15;
} }
if (yych <= 'D') { if (yych <= 'D')
if (yych == '.') goto basic_json_parser_43; {
if (yych == '.')
{
goto basic_json_parser_43;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} else { }
if (yych <= 'E') goto basic_json_parser_44; else
if (yych == 'e') goto basic_json_parser_44; {
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} }
basic_json_parser_17: basic_json_parser_17:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::name_separator; break; } {
last_token_type = token_type::name_separator;
break;
}
basic_json_parser_19: basic_json_parser_19:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::begin_array; break; } {
last_token_type = token_type::begin_array;
break;
}
basic_json_parser_21: basic_json_parser_21:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::end_array; break; } {
last_token_type = token_type::end_array;
break;
}
basic_json_parser_23: basic_json_parser_23:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'a') goto basic_json_parser_45; if (yych == 'a')
{
goto basic_json_parser_45;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_24: basic_json_parser_24:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'u') goto basic_json_parser_46; if (yych == 'u')
{
goto basic_json_parser_46;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_25: basic_json_parser_25:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'r') goto basic_json_parser_47; if (yych == 'r')
{
goto basic_json_parser_47;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_26: basic_json_parser_26:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::begin_object; break; } {
last_token_type = token_type::begin_object;
break;
}
basic_json_parser_28: basic_json_parser_28:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::end_object; break; } {
last_token_type = token_type::end_object;
break;
}
basic_json_parser_30: basic_json_parser_30:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
basic_json_parser_31: basic_json_parser_31:
if (yybm[0+yych] & 128) { if (yybm[0 + yych] & 128)
{
goto basic_json_parser_30; goto basic_json_parser_30;
} }
if (yych <= 0xE0) { if (yych <= 0xE0)
if (yych <= '\\') { {
if (yych <= 0x1F) goto basic_json_parser_32; if (yych <= '\\')
if (yych <= '"') goto basic_json_parser_33; {
if (yych <= 0x1F)
{
goto basic_json_parser_32;
}
if (yych <= '"')
{
goto basic_json_parser_33;
}
goto basic_json_parser_35; goto basic_json_parser_35;
} else { }
if (yych <= 0xC1) goto basic_json_parser_32; else
if (yych <= 0xDF) goto basic_json_parser_36; {
if (yych <= 0xC1)
{
goto basic_json_parser_32;
}
if (yych <= 0xDF)
{
goto basic_json_parser_36;
}
goto basic_json_parser_37; goto basic_json_parser_37;
} }
} else { }
if (yych <= 0xEF) { else
if (yych == 0xED) goto basic_json_parser_39; {
if (yych <= 0xEF)
{
if (yych == 0xED)
{
goto basic_json_parser_39;
}
goto basic_json_parser_38; goto basic_json_parser_38;
} else { }
if (yych <= 0xF0) goto basic_json_parser_40; else
if (yych <= 0xF3) goto basic_json_parser_41; {
if (yych <= 0xF4) goto basic_json_parser_42; if (yych <= 0xF0)
{
goto basic_json_parser_40;
}
if (yych <= 0xF3)
{
goto basic_json_parser_41;
}
if (yych <= 0xF4)
{
goto basic_json_parser_42;
}
} }
} }
basic_json_parser_32: basic_json_parser_32:
m_cursor = m_marker; m_cursor = m_marker;
if (yyaccept == 0) { if (yyaccept == 0)
{
goto basic_json_parser_5; goto basic_json_parser_5;
} else { }
else
{
goto basic_json_parser_14; goto basic_json_parser_14;
} }
basic_json_parser_33: basic_json_parser_33:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::value_string; break; } {
last_token_type = token_type::value_string;
break;
}
basic_json_parser_35: basic_json_parser_35:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 'e') { if (yych <= 'e')
if (yych <= '/') { {
if (yych == '"') goto basic_json_parser_30; if (yych <= '/')
if (yych <= '.') goto basic_json_parser_32; {
if (yych == '"')
{
goto basic_json_parser_30;
}
if (yych <= '.')
{
goto basic_json_parser_32;
}
goto basic_json_parser_30; goto basic_json_parser_30;
} else { }
if (yych <= '\\') { else
if (yych <= '[') goto basic_json_parser_32; {
if (yych <= '\\')
{
if (yych <= '[')
{
goto basic_json_parser_32;
}
goto basic_json_parser_30;
}
else
{
if (yych == 'b')
{
goto basic_json_parser_30; goto basic_json_parser_30;
} else { }
if (yych == 'b') goto basic_json_parser_30;
goto basic_json_parser_32; goto basic_json_parser_32;
} }
} }
} else { }
if (yych <= 'q') { else
if (yych <= 'f') goto basic_json_parser_30; {
if (yych == 'n') goto basic_json_parser_30; if (yych <= 'q')
{
if (yych <= 'f')
{
goto basic_json_parser_30;
}
if (yych == 'n')
{
goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= 's') { else
if (yych <= 'r') goto basic_json_parser_30; {
if (yych <= 's')
{
if (yych <= 'r')
{
goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= 't') goto basic_json_parser_30; else
if (yych <= 'u') goto basic_json_parser_48; {
if (yych <= 't')
{
goto basic_json_parser_30;
}
if (yych <= 'u')
{
goto basic_json_parser_48;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
} }
} }
basic_json_parser_36: basic_json_parser_36:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) goto basic_json_parser_32; if (yych <= 0x7F)
if (yych <= 0xBF) goto basic_json_parser_30; {
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_37: basic_json_parser_37:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x9F) goto basic_json_parser_32; if (yych <= 0x9F)
if (yych <= 0xBF) goto basic_json_parser_36; {
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_36;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_38: basic_json_parser_38:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) goto basic_json_parser_32; if (yych <= 0x7F)
if (yych <= 0xBF) goto basic_json_parser_36; {
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_36;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_39: basic_json_parser_39:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) goto basic_json_parser_32; if (yych <= 0x7F)
if (yych <= 0x9F) goto basic_json_parser_36; {
goto basic_json_parser_32;
}
if (yych <= 0x9F)
{
goto basic_json_parser_36;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_40: basic_json_parser_40:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x8F) goto basic_json_parser_32; if (yych <= 0x8F)
if (yych <= 0xBF) goto basic_json_parser_38; {
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_38;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_41: basic_json_parser_41:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) goto basic_json_parser_32; if (yych <= 0x7F)
if (yych <= 0xBF) goto basic_json_parser_38; {
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_38;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_42: basic_json_parser_42:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) goto basic_json_parser_32; if (yych <= 0x7F)
if (yych <= 0x8F) goto basic_json_parser_38; {
goto basic_json_parser_32;
}
if (yych <= 0x8F)
{
goto basic_json_parser_38;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_43: basic_json_parser_43:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') goto basic_json_parser_32; if (yych <= '/')
if (yych <= '9') goto basic_json_parser_49; {
goto basic_json_parser_32;
}
if (yych <= '9')
{
goto basic_json_parser_49;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_44: basic_json_parser_44:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= ',') { if (yych <= ',')
if (yych == '+') goto basic_json_parser_51; {
if (yych == '+')
{
goto basic_json_parser_51;
}
goto basic_json_parser_32;
}
else
{
if (yych <= '-')
{
goto basic_json_parser_51;
}
if (yych <= '/')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= '-') goto basic_json_parser_51; if (yych <= '9')
if (yych <= '/') goto basic_json_parser_32; {
if (yych <= '9') goto basic_json_parser_52; goto basic_json_parser_52;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_45: basic_json_parser_45:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'l') goto basic_json_parser_54; if (yych == 'l')
{
goto basic_json_parser_54;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_46: basic_json_parser_46:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'l') goto basic_json_parser_55; if (yych == 'l')
{
goto basic_json_parser_55;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_47: basic_json_parser_47:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'u') goto basic_json_parser_56; if (yych == 'u')
{
goto basic_json_parser_56;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_48: basic_json_parser_48:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto basic_json_parser_32; {
if (yych <= '9') goto basic_json_parser_57; if (yych <= '/')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= 'F') goto basic_json_parser_57; if (yych <= '9')
if (yych <= '`') goto basic_json_parser_32; {
if (yych <= 'f') goto basic_json_parser_57; goto basic_json_parser_57;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_57;
}
if (yych <= '`')
{
goto basic_json_parser_32;
}
if (yych <= 'f')
{
goto basic_json_parser_57;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_49: basic_json_parser_49:
yyaccept = 1; yyaccept = 1;
m_marker = ++m_cursor; m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3) fill_line_buffer(3); // LCOV_EXCL_LINE if ((m_limit - m_cursor) < 3)
{
fill_line_buffer(3); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 'D') { if (yych <= 'D')
if (yych <= '/') goto basic_json_parser_14; {
if (yych <= '9') goto basic_json_parser_49; if (yych <= '/')
{
goto basic_json_parser_14;
}
if (yych <= '9')
{
goto basic_json_parser_49;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} else { }
if (yych <= 'E') goto basic_json_parser_44; else
if (yych == 'e') goto basic_json_parser_44; {
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} }
basic_json_parser_51: basic_json_parser_51:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') goto basic_json_parser_32; if (yych <= '/')
if (yych >= ':') goto basic_json_parser_32; {
goto basic_json_parser_32;
}
if (yych >= ':')
{
goto basic_json_parser_32;
}
basic_json_parser_52: basic_json_parser_52:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '/') goto basic_json_parser_14; if (yych <= '/')
if (yych <= '9') goto basic_json_parser_52; {
goto basic_json_parser_14;
}
if (yych <= '9')
{
goto basic_json_parser_52;
}
goto basic_json_parser_14; goto basic_json_parser_14;
basic_json_parser_54: basic_json_parser_54:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 's') goto basic_json_parser_58; if (yych == 's')
{
goto basic_json_parser_58;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_55: basic_json_parser_55:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'l') goto basic_json_parser_59; if (yych == 'l')
{
goto basic_json_parser_59;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_56: basic_json_parser_56:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'e') goto basic_json_parser_61; if (yych == 'e')
{
goto basic_json_parser_61;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_57: basic_json_parser_57:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto basic_json_parser_32; {
if (yych <= '9') goto basic_json_parser_63; if (yych <= '/')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= 'F') goto basic_json_parser_63; if (yych <= '9')
if (yych <= '`') goto basic_json_parser_32; {
if (yych <= 'f') goto basic_json_parser_63; goto basic_json_parser_63;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_63;
}
if (yych <= '`')
{
goto basic_json_parser_32;
}
if (yych <= 'f')
{
goto basic_json_parser_63;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_58: basic_json_parser_58:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'e') goto basic_json_parser_64; if (yych == 'e')
{
goto basic_json_parser_64;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_59: basic_json_parser_59:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::literal_null; break; } {
last_token_type = token_type::literal_null;
break;
}
basic_json_parser_61: basic_json_parser_61:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::literal_true; break; } {
last_token_type = token_type::literal_true;
break;
}
basic_json_parser_63: basic_json_parser_63:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto basic_json_parser_32; {
if (yych <= '9') goto basic_json_parser_66; if (yych <= '/')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= 'F') goto basic_json_parser_66; if (yych <= '9')
if (yych <= '`') goto basic_json_parser_32; {
if (yych <= 'f') goto basic_json_parser_66; goto basic_json_parser_66;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_66;
}
if (yych <= '`')
{
goto basic_json_parser_32;
}
if (yych <= 'f')
{
goto basic_json_parser_66;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_64: basic_json_parser_64:
++m_cursor; ++m_cursor;
{ last_token_type = token_type::literal_false; break; } {
last_token_type = token_type::literal_false;
break;
}
basic_json_parser_66: basic_json_parser_66:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE if (m_limit <= m_cursor)
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') { if (yych <= '@')
if (yych <= '/') goto basic_json_parser_32; {
if (yych <= '9') goto basic_json_parser_30; if (yych <= '/')
{
goto basic_json_parser_32;
}
if (yych <= '9')
{
goto basic_json_parser_30;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_30;
}
if (yych <= '`')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} else { }
if (yych <= 'F') goto basic_json_parser_30; if (yych <= 'f')
if (yych <= '`') goto basic_json_parser_32; {
if (yych <= 'f') goto basic_json_parser_30; goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
} }
...@@ -11210,14 +11727,14 @@ basic_json_parser_66: ...@@ -11210,14 +11727,14 @@ basic_json_parser_66:
} }
private: private:
friend bool operator==(json_pointer const &lhs, friend bool operator==(json_pointer const& lhs,
json_pointer const &rhs) noexcept json_pointer const& rhs) noexcept
{ {
return lhs.reference_tokens == rhs.reference_tokens; return lhs.reference_tokens == rhs.reference_tokens;
} }
friend bool operator!=(json_pointer const &lhs, friend bool operator!=(json_pointer const& lhs,
json_pointer const &rhs) noexcept json_pointer const& rhs) noexcept
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
...@@ -11908,7 +12425,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept ...@@ -11908,7 +12425,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2, // integer 2, // integer
2, // unsigned 2, // unsigned
2, // float 2, // float
}}; }
};
// discarded values are not comparable // discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded) if (lhs == value_t::discarded or rhs == value_t::discarded)
...@@ -11943,25 +12461,25 @@ using json = basic_json<>; ...@@ -11943,25 +12461,25 @@ using json = basic_json<>;
// specialization of std::swap, and std::hash // specialization of std::swap, and std::hash
namespace std namespace std
{ {
/*! /*!
@brief exchanges the values of two JSON objects @brief exchanges the values of two JSON objects
@since version 1.0.0 @since version 1.0.0
*/ */
template<> template<>
inline void swap(nlohmann::json& j1, inline void swap(nlohmann::json& j1,
nlohmann::json& j2) noexcept( nlohmann::json& j2) noexcept(
is_nothrow_move_constructible<nlohmann::json>::value and is_nothrow_move_constructible<nlohmann::json>::value and
is_nothrow_move_assignable<nlohmann::json>::value is_nothrow_move_assignable<nlohmann::json>::value
) )
{ {
j1.swap(j2); j1.swap(j2);
} }
/// hash value for JSON objects /// hash value for JSON objects
template<> template<>
struct hash<nlohmann::json> struct hash<nlohmann::json>
{ {
/*! /*!
@brief return a hash value for a JSON object @brief return a hash value for a JSON object
...@@ -11973,7 +12491,7 @@ namespace std ...@@ -11973,7 +12491,7 @@ namespace std
const auto& h = hash<nlohmann::json::string_t>(); const auto& h = hash<nlohmann::json::string_t>();
return h(j.dump()); return h(j.dump());
} }
}; };
} // namespace std } // namespace std
/*! /*!
......
...@@ -168,7 +168,7 @@ using is_unscoped_enum = ...@@ -168,7 +168,7 @@ using is_unscoped_enum =
namespace detail namespace detail
{ {
template <typename Json> std::string type_name(const Json &j) template <typename Json> std::string type_name(const Json& j)
{ {
switch (j.m_type) switch (j.m_type)
{ {
...@@ -190,7 +190,7 @@ template <typename Json> std::string type_name(const Json &j) ...@@ -190,7 +190,7 @@ template <typename Json> std::string type_name(const Json &j)
} }
// dispatch utility (taken from ranges-v3) // dispatch utility (taken from ranges-v3)
template <unsigned N> struct priority_tag : priority_tag<N - 1> {}; template <unsigned N> struct priority_tag : priority_tag < N - 1 > {};
template <> struct priority_tag<0> {}; template <> struct priority_tag<0> {};
...@@ -202,7 +202,7 @@ template <> ...@@ -202,7 +202,7 @@ template <>
struct external_constructor<value_t::boolean> struct external_constructor<value_t::boolean>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::boolean_t b) noexcept static void construct(Json& j, typename Json::boolean_t b) noexcept
{ {
j.m_type = value_t::boolean; j.m_type = value_t::boolean;
j.m_value = b; j.m_value = b;
...@@ -214,7 +214,7 @@ template <> ...@@ -214,7 +214,7 @@ template <>
struct external_constructor<value_t::string> struct external_constructor<value_t::string>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, const typename Json::string_t& s) static void construct(Json& j, const typename Json::string_t& s)
{ {
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = s; j.m_value = s;
...@@ -226,7 +226,7 @@ template <> ...@@ -226,7 +226,7 @@ template <>
struct external_constructor<value_t::number_float> struct external_constructor<value_t::number_float>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::number_float_t val) noexcept static void construct(Json& j, typename Json::number_float_t val) noexcept
{ {
// replace infinity and NAN by null // replace infinity and NAN by null
if (not std::isfinite(val)) if (not std::isfinite(val))
...@@ -244,7 +244,7 @@ template <> ...@@ -244,7 +244,7 @@ template <>
struct external_constructor<value_t::number_unsigned> struct external_constructor<value_t::number_unsigned>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::number_unsigned_t val) noexcept static void construct(Json& j, typename Json::number_unsigned_t val) noexcept
{ {
j.m_type = value_t::number_unsigned; j.m_type = value_t::number_unsigned;
j.m_value = val; j.m_value = val;
...@@ -256,7 +256,7 @@ template <> ...@@ -256,7 +256,7 @@ template <>
struct external_constructor<value_t::number_integer> struct external_constructor<value_t::number_integer>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, typename Json::number_integer_t val) noexcept static void construct(Json& j, typename Json::number_integer_t val) noexcept
{ {
j.m_type = value_t::number_integer; j.m_type = value_t::number_integer;
j.m_value = val; j.m_value = val;
...@@ -268,7 +268,7 @@ template <> ...@@ -268,7 +268,7 @@ template <>
struct external_constructor<value_t::array> struct external_constructor<value_t::array>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, const typename Json::array_t& arr) static void construct(Json& j, const typename Json::array_t& arr)
{ {
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = arr; j.m_value = arr;
...@@ -279,7 +279,7 @@ struct external_constructor<value_t::array> ...@@ -279,7 +279,7 @@ struct external_constructor<value_t::array>
enable_if_t<not std::is_same<CompatibleArrayType, enable_if_t<not std::is_same<CompatibleArrayType,
typename Json::array_t>::value, typename Json::array_t>::value,
int> = 0> int> = 0>
static void construct(Json &j, const CompatibleArrayType &arr) static void construct(Json& j, const CompatibleArrayType& arr)
{ {
using std::begin; using std::begin;
using std::end; using std::end;
...@@ -294,7 +294,7 @@ template <> ...@@ -294,7 +294,7 @@ template <>
struct external_constructor<value_t::object> struct external_constructor<value_t::object>
{ {
template <typename Json> template <typename Json>
static void construct(Json &j, const typename Json::object_t& obj) static void construct(Json& j, const typename Json::object_t& obj)
{ {
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = obj; j.m_value = obj;
...@@ -305,7 +305,7 @@ struct external_constructor<value_t::object> ...@@ -305,7 +305,7 @@ struct external_constructor<value_t::object>
enable_if_t<not std::is_same<CompatibleObjectType, enable_if_t<not std::is_same<CompatibleObjectType,
typename Json::object_t>::value, typename Json::object_t>::value,
int> = 0> int> = 0>
static void construct(Json &j, const CompatibleObjectType &obj) static void construct(Json& j, const CompatibleObjectType& obj)
{ {
using std::begin; using std::begin;
using std::end; using std::end;
...@@ -380,11 +380,11 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType> ...@@ -380,11 +380,11 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType>
template<class BasicJson, class CompatibleObjectType> template<class BasicJson, class CompatibleObjectType>
struct is_compatible_object_type struct is_compatible_object_type
{ {
static auto constexpr value = is_compatible_object_type_impl< static auto constexpr value = is_compatible_object_type_impl <
conjunction<negation<std::is_same<void, CompatibleObjectType>>, conjunction<negation<std::is_same<void, CompatibleObjectType>>,
has_mapped_type<CompatibleObjectType>, has_mapped_type<CompatibleObjectType>,
has_key_type<CompatibleObjectType>>::value, has_key_type<CompatibleObjectType>>::value,
typename BasicJson::object_t, CompatibleObjectType>::value; typename BasicJson::object_t, CompatibleObjectType >::value;
}; };
template <typename BasicJson, typename T> template <typename BasicJson, typename T>
...@@ -461,15 +461,15 @@ struct has_from_json ...@@ -461,15 +461,15 @@ struct has_from_json
template <typename Json, typename T> template <typename Json, typename T>
struct has_non_default_from_json struct has_non_default_from_json
{ {
private: private:
template < template <
typename U, typename U,
typename = enable_if_t<std::is_same< typename = enable_if_t<std::is_same<
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>> T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value >>
static int detect(U &&); static int detect(U&&);
static void detect(...); static void detect(...);
public: public:
static constexpr bool value = std::is_integral<decltype(detect( static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value; std::declval<typename Json::template json_serializer<T, void>>()))>::value;
}; };
...@@ -478,13 +478,13 @@ public: ...@@ -478,13 +478,13 @@ public:
template <typename Json, typename T> template <typename Json, typename T>
struct has_to_json struct has_to_json
{ {
private: private:
template <typename U, typename = decltype(uncvref_t<U>::to_json( template <typename U, typename = decltype(uncvref_t<U>::to_json(
std::declval<Json &>(), std::declval<T>()))> std::declval<Json&>(), std::declval<T>()))>
static int detect(U &&); static int detect(U&&);
static void detect(...); static void detect(...);
public: public:
static constexpr bool value = std::is_integral<decltype(detect( static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value; std::declval<typename Json::template json_serializer<T, void>>()))>::value;
}; };
...@@ -496,21 +496,29 @@ template <typename Json, typename ArithmeticType, ...@@ -496,21 +496,29 @@ template <typename Json, typename ArithmeticType,
not std::is_same<ArithmeticType, not std::is_same<ArithmeticType,
typename Json::boolean_t>::value, typename Json::boolean_t>::value,
int> = 0> int> = 0>
void get_arithmetic_value(const Json &j, ArithmeticType &val) void get_arithmetic_value(const Json& j, ArithmeticType& val)
{ {
// unsigned must be checked first, since is_number_integer() == true for unsigned // unsigned must be checked first, since is_number_integer() == true for unsigned
if (j.is_number_unsigned()) if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer()) else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float()) else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else else
{
throw std::domain_error("type must be number, but is " + type_name(j)); throw std::domain_error("type must be number, but is " + type_name(j));
}
} }
template <typename Json> template <typename Json>
void to_json(Json &j, typename Json::boolean_t b) noexcept void to_json(Json& j, typename Json::boolean_t b) noexcept
{ {
external_constructor<value_t::boolean>::construct(j, b); external_constructor<value_t::boolean>::construct(j, b);
} }
...@@ -519,14 +527,14 @@ template <typename Json, typename CompatibleString, ...@@ -519,14 +527,14 @@ template <typename Json, typename CompatibleString,
enable_if_t<std::is_constructible<typename Json::string_t, enable_if_t<std::is_constructible<typename Json::string_t,
CompatibleString>::value, CompatibleString>::value,
int> = 0> int> = 0>
void to_json(Json &j, const CompatibleString &s) void to_json(Json& j, const CompatibleString& s)
{ {
external_constructor<value_t::string>::construct(j, s); external_constructor<value_t::string>::construct(j, s);
} }
template <typename Json, typename FloatType, template <typename Json, typename FloatType,
enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
void to_json(Json &j, FloatType val) noexcept void to_json(Json& j, FloatType val) noexcept
{ {
external_constructor<value_t::number_float>::construct(j, static_cast<typename Json::number_float_t>(val)); external_constructor<value_t::number_float>::construct(j, static_cast<typename Json::number_float_t>(val));
} }
...@@ -536,8 +544,8 @@ template < ...@@ -536,8 +544,8 @@ template <
typename Json, typename CompatibleNumberUnsignedType, typename Json, typename CompatibleNumberUnsignedType,
enable_if_t<is_compatible_integer_type<typename Json::number_unsigned_t, enable_if_t<is_compatible_integer_type<typename Json::number_unsigned_t,
CompatibleNumberUnsignedType>::value, CompatibleNumberUnsignedType>::value,
int> = 0> int> = 0 >
void to_json(Json &j, CompatibleNumberUnsignedType val) noexcept void to_json(Json& j, CompatibleNumberUnsignedType val) noexcept
{ {
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename Json::number_unsigned_t>(val)); external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename Json::number_unsigned_t>(val));
} }
...@@ -546,26 +554,26 @@ template < ...@@ -546,26 +554,26 @@ template <
typename Json, typename CompatibleNumberIntegerType, typename Json, typename CompatibleNumberIntegerType,
enable_if_t<is_compatible_integer_type<typename Json::number_integer_t, enable_if_t<is_compatible_integer_type<typename Json::number_integer_t,
CompatibleNumberIntegerType>::value, CompatibleNumberIntegerType>::value,
int> = 0> int> = 0 >
void to_json(Json &j, CompatibleNumberIntegerType val) noexcept void to_json(Json& j, CompatibleNumberIntegerType val) noexcept
{ {
external_constructor<value_t::number_integer>::construct(j, static_cast<typename Json::number_integer_t>(val)); external_constructor<value_t::number_integer>::construct(j, static_cast<typename Json::number_integer_t>(val));
} }
template <typename Json, typename UnscopedEnumType, template <typename Json, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0> enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void to_json(Json &j, UnscopedEnumType e) noexcept void to_json(Json& j, UnscopedEnumType e) noexcept
{ {
external_constructor<value_t::number_integer>::construct(j, e); external_constructor<value_t::number_integer>::construct(j, e);
} }
template < template <
typename Json, typename CompatibleArrayType, typename Json, typename CompatibleArrayType,
enable_if_t< enable_if_t <
is_compatible_array_type<Json, CompatibleArrayType>::value or is_compatible_array_type<Json, CompatibleArrayType>::value or
std::is_same<typename Json::array_t, CompatibleArrayType>::value, std::is_same<typename Json::array_t, CompatibleArrayType>::value,
int> = 0> int > = 0 >
void to_json(Json &j, const CompatibleArrayType &arr) void to_json(Json& j, const CompatibleArrayType& arr)
{ {
external_constructor<value_t::array>::construct(j, arr); external_constructor<value_t::array>::construct(j, arr);
} }
...@@ -573,49 +581,53 @@ void to_json(Json &j, const CompatibleArrayType &arr) ...@@ -573,49 +581,53 @@ void to_json(Json &j, const CompatibleArrayType &arr)
template < template <
typename Json, typename CompatibleObjectType, typename Json, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value, enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value,
int> = 0> int> = 0 >
void to_json(Json &j, const CompatibleObjectType &arr) void to_json(Json& j, const CompatibleObjectType& arr)
{ {
external_constructor<value_t::object>::construct(j, arr); external_constructor<value_t::object>::construct(j, arr);
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::boolean_t& b) void from_json(const Json& j, typename Json::boolean_t& b)
{ {
if (!j.is_boolean()) if (!j.is_boolean())
{
throw std::domain_error("type must be boolean, but is " + type_name(j)); throw std::domain_error("type must be boolean, but is " + type_name(j));
}
b = *j.template get_ptr<const typename Json::boolean_t*>(); b = *j.template get_ptr<const typename Json::boolean_t*>();
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::string_t& s) void from_json(const Json& j, typename Json::string_t& s)
{ {
if (!j.is_string()) if (!j.is_string())
{
throw std::domain_error("type must be string, but is " + type_name(j)); throw std::domain_error("type must be string, but is " + type_name(j));
}
s = *j.template get_ptr<const typename Json::string_t*>(); s = *j.template get_ptr<const typename Json::string_t*>();
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::number_float_t& val) void from_json(const Json& j, typename Json::number_float_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::number_unsigned_t& val) void from_json(const Json& j, typename Json::number_unsigned_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, typename Json::number_integer_t& val) void from_json(const Json& j, typename Json::number_integer_t& val)
{ {
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
} }
template <typename Json, typename UnscopedEnumType, template <typename Json, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0> enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void from_json(const Json &j, UnscopedEnumType& e) void from_json(const Json& j, UnscopedEnumType& e)
{ {
typename std::underlying_type<UnscopedEnumType>::type val = e; typename std::underlying_type<UnscopedEnumType>::type val = e;
get_arithmetic_value(j, val); get_arithmetic_value(j, val);
...@@ -623,38 +635,46 @@ void from_json(const Json &j, UnscopedEnumType& e) ...@@ -623,38 +635,46 @@ void from_json(const Json &j, UnscopedEnumType& e)
} }
template <typename Json> template <typename Json>
void from_json(const Json &j, typename Json::array_t &arr) void from_json(const Json& j, typename Json::array_t& arr)
{ {
if (!j.is_array()) if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
}
arr = *j.template get_ptr<const typename Json::array_t*>(); arr = *j.template get_ptr<const typename Json::array_t*>();
} }
// forward_list doesn't have an insert method, TODO find a way to avoid including forward_list // forward_list doesn't have an insert method, TODO find a way to avoid including forward_list
template <typename Json, typename T, typename Allocator> template <typename Json, typename T, typename Allocator>
void from_json(const Json &j, std::forward_list<T, Allocator>& l) void from_json(const Json& j, std::forward_list<T, Allocator>& l)
{ {
// do not perform the check when user wants to retrieve jsons // do not perform the check when user wants to retrieve jsons
// (except when it's null.. ?) // (except when it's null.. ?)
if (j.is_null()) if (j.is_null())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
}
if (not std::is_same<T, Json>::value) if (not std::is_same<T, Json>::value)
{ {
if (!j.is_array()) if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
} }
}
for (auto it = j.rbegin(), end = j.rend(); it != end; ++it) for (auto it = j.rbegin(), end = j.rend(); it != end; ++it)
{
l.push_front(it->template get<T>()); l.push_front(it->template get<T>());
}
} }
template <typename Json, typename CompatibleArrayType> template <typename Json, typename CompatibleArrayType>
void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag<0>) void from_json_array_impl(const Json& j, CompatibleArrayType& arr, priority_tag<0>)
{ {
using std::begin; using std::begin;
using std::end; using std::end;
std::transform( std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &i) j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json & i)
{ {
// get<Json>() returns *this, this won't call a from_json method when // get<Json>() returns *this, this won't call a from_json method when
// value_type is Json // value_type is Json
...@@ -663,8 +683,8 @@ void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag ...@@ -663,8 +683,8 @@ void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
} }
template <typename Json, typename CompatibleArrayType> template <typename Json, typename CompatibleArrayType>
auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag<1>) auto from_json_array_impl(const Json& j, CompatibleArrayType& arr, priority_tag<1>)
-> decltype( -> decltype(
arr.reserve(std::declval<typename CompatibleArrayType::size_type>()), arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
void()) void())
{ {
...@@ -673,7 +693,7 @@ auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag ...@@ -673,7 +693,7 @@ auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
arr.reserve(j.size()); arr.reserve(j.size());
std::transform( std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &i) j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json & i)
{ {
// get<Json>() returns *this, this won't call a from_json method when // get<Json>() returns *this, this won't call a from_json method when
// value_type is Json // value_type is Json
...@@ -686,29 +706,35 @@ template < ...@@ -686,29 +706,35 @@ template <
enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and
not std::is_same<typename Json::array_t, not std::is_same<typename Json::array_t,
CompatibleArrayType>::value, CompatibleArrayType>::value,
int> = 0> int> = 0 >
void from_json(const Json &j, CompatibleArrayType &arr) void from_json(const Json& j, CompatibleArrayType& arr)
{ {
if (j.is_null()) if (j.is_null())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
}
// when T == Json, do not check if value_t is correct // when T == Json, do not check if value_t is correct
if (not std::is_same<typename CompatibleArrayType::value_type, Json>::value) if (not std::is_same<typename CompatibleArrayType::value_type, Json>::value)
{ {
if (!j.is_array()) if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
} }
from_json_array_impl(j, arr, priority_tag<1>{}); }
from_json_array_impl(j, arr, priority_tag<1> {});
} }
template < template <
typename Json, typename CompatibleObjectType, typename Json, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value, enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value,
int> = 0> int> = 0 >
void from_json(const Json &j, CompatibleObjectType &obj) void from_json(const Json& j, CompatibleObjectType& obj)
{ {
if (!j.is_object()) if (!j.is_object())
{
throw std::domain_error("type must be object, but is " + type_name(j)); throw std::domain_error("type must be object, but is " + type_name(j));
}
auto inner_object = j.template get_ptr<const typename Json::object_t*>(); auto inner_object = j.template get_ptr<const typename Json::object_t*>();
using std::begin; using std::begin;
...@@ -724,25 +750,35 @@ void from_json(const Json &j, CompatibleObjectType &obj) ...@@ -724,25 +750,35 @@ void from_json(const Json &j, CompatibleObjectType &obj)
// in case of a custom BooleanType which is not an arithmetic type? // in case of a custom BooleanType which is not an arithmetic type?
template < template <
typename Json, typename ArithmeticType, typename Json, typename ArithmeticType,
enable_if_t< enable_if_t <
std::is_arithmetic<ArithmeticType>::value and std::is_arithmetic<ArithmeticType>::value and
not std::is_same<ArithmeticType, typename Json::number_unsigned_t>::value and not std::is_same<ArithmeticType, typename Json::number_unsigned_t>::value and
not std::is_same<ArithmeticType, typename Json::number_integer_t>::value and not std::is_same<ArithmeticType, typename Json::number_integer_t>::value and
not std::is_same<ArithmeticType, typename Json::number_float_t>::value and not std::is_same<ArithmeticType, typename Json::number_float_t>::value and
not std::is_same<ArithmeticType, typename Json::boolean_t>::value, not std::is_same<ArithmeticType, typename Json::boolean_t>::value,
int> = 0> int > = 0 >
void from_json(const Json &j, ArithmeticType &val) void from_json(const Json& j, ArithmeticType& val)
{ {
if (j.is_number_unsigned()) if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer()) else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float()) else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else if (j.is_boolean()) else if (j.is_boolean())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::boolean_t*>()); val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::boolean_t*>());
}
else else
{
throw std::domain_error("type must be number, but is " + type_name(j)); throw std::domain_error("type must be number, but is " + type_name(j));
}
} }
struct to_json_fn struct to_json_fn
...@@ -762,20 +798,20 @@ struct to_json_fn ...@@ -762,20 +798,20 @@ struct to_json_fn
static_assert(sizeof(Json) == 0, "to_json method in T's namespace can not be called"); static_assert(sizeof(Json) == 0, "to_json method in T's namespace can not be called");
} }
public: public:
template <typename Json, typename T> template <typename Json, typename T>
void operator()(Json &j, T &&val) const void operator()(Json& j, T&& val) const
noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val), priority_tag<1>{}))) noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val), priority_tag<1> {})))
{ {
return call(j, std::forward<T>(val), priority_tag<1>{}); return call(j, std::forward<T>(val), priority_tag<1> {});
} }
}; };
struct from_json_fn struct from_json_fn
{ {
private: private:
template <typename Json, typename T> template <typename Json, typename T>
auto call(const Json &j, T &val, priority_tag<1>) const auto call(const Json& j, T& val, priority_tag<1>) const
noexcept(noexcept(from_json(j, val))) noexcept(noexcept(from_json(j, val)))
-> decltype(from_json(j, val), void()) -> decltype(from_json(j, val), void())
{ {
...@@ -783,17 +819,17 @@ private: ...@@ -783,17 +819,17 @@ private:
} }
template <typename Json, typename T> template <typename Json, typename T>
void call(const Json &, T&, priority_tag<0>) const noexcept void call(const Json&, T&, priority_tag<0>) const noexcept
{ {
static_assert(sizeof(Json) == 0, "from_json method in T's namespace can not be called"); static_assert(sizeof(Json) == 0, "from_json method in T's namespace can not be called");
} }
public: public:
template <typename Json, typename T> template <typename Json, typename T>
void operator()(const Json &j, T &val) const void operator()(const Json& j, T& val) const
noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1>{}))) noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1> {})))
{ {
return call(j, val, priority_tag<1>{}); return call(j, val, priority_tag<1> {});
} }
}; };
...@@ -830,8 +866,8 @@ struct DecimalSeparator : std::numpunct<char> ...@@ -830,8 +866,8 @@ struct DecimalSeparator : std::numpunct<char>
inline namespace inline namespace
{ {
constexpr const auto & to_json = detail::static_const<detail::to_json_fn>::value; constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
constexpr const auto & from_json = detail::static_const<detail::from_json_fn>::value; constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
} }
// default JSONSerializer template argument, doesn't care about template argument // default JSONSerializer template argument, doesn't care about template argument
...@@ -846,7 +882,7 @@ struct adl_serializer ...@@ -846,7 +882,7 @@ struct adl_serializer
} }
template <typename Json, typename T> template <typename Json, typename T>
static void to_json(Json &j, T &&val) noexcept( static void to_json(Json& j, T&& val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<T>(val)))) noexcept(::nlohmann::to_json(j, std::forward<T>(val))))
{ {
::nlohmann::to_json(j, std::forward<T>(val)); ::nlohmann::to_json(j, std::forward<T>(val));
...@@ -947,7 +983,7 @@ class basic_json ...@@ -947,7 +983,7 @@ class basic_json
{ {
private: private:
template <::nlohmann::value_t> friend struct detail::external_constructor; template <::nlohmann::value_t> friend struct detail::external_constructor;
template <typename Json> friend std::string detail::type_name(const Json &); template <typename Json> friend std::string detail::type_name(const Json&);
/// workaround type for MSVC /// workaround type for MSVC
using basic_json_t = basic_json<ObjectType, ArrayType, StringType, using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
...@@ -1854,8 +1890,8 @@ class basic_json ...@@ -1854,8 +1890,8 @@ class basic_json
basic_json_t, U>::value and basic_json_t, U>::value and
detail::has_to_json<basic_json, U>::value, detail::has_to_json<basic_json, U>::value,
int> = 0> int> = 0>
basic_json(T &&val) noexcept(noexcept(JSONSerializer<U>::to_json( basic_json(T && val) noexcept(noexcept(JSONSerializer<U>::to_json(
std::declval<basic_json_t &>(), std::forward<T>(val)))) std::declval<basic_json_t&>(), std::forward<T>(val))))
{ {
JSONSerializer<U>::to_json(*this, std::forward<T>(val)); JSONSerializer<U>::to_json(*this, std::forward<T>(val));
} }
...@@ -3041,17 +3077,17 @@ class basic_json ...@@ -3041,17 +3077,17 @@ class basic_json
template < template <
typename T, typename T,
typename U = uncvref_t<T>, typename U = uncvref_t<T>,
enable_if_t< enable_if_t <
not std::is_same<basic_json_t, U>::value and not std::is_same<basic_json_t, U>::value and
detail::has_from_json<basic_json_t, U>::value and detail::has_from_json<basic_json_t, U>::value and
not detail::has_non_default_from_json<basic_json_t, not detail::has_non_default_from_json<basic_json_t,
U>::value, U>::value,
int> = 0> int > = 0 >
// do we really want the uncvref ? if a user call get<int &>, shouldn't we // do we really want the uncvref ? if a user call get<int &>, shouldn't we
// static assert ? // static assert ?
// i know there is a special behaviour for boolean_t* and such // i know there is a special behaviour for boolean_t* and such
auto get() const noexcept(noexcept(JSONSerializer<U>::from_json( auto get() const noexcept(noexcept(JSONSerializer<U>::from_json(
std::declval<const basic_json_t &>(), std::declval<U &>()))) std::declval<const basic_json_t&>(), std::declval<U&>())))
-> U -> U
{ {
static_assert(std::is_default_constructible<U>::value and static_assert(std::is_default_constructible<U>::value and
...@@ -3083,8 +3119,8 @@ class basic_json ...@@ -3083,8 +3119,8 @@ class basic_json
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_non_default_from_json<basic_json_t, detail::has_non_default_from_json<basic_json_t,
uncvref_t<T>>::value, uncvref_t<T>>::value,
int> = 0> int> = 0 >
uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<const basic_json_t &>()))) uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<const basic_json_t&>())))
{ {
return JSONSerializer<T>::from_json(*this); return JSONSerializer<T>::from_json(*this);
} }
...@@ -7871,7 +7907,10 @@ class basic_json ...@@ -7871,7 +7907,10 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
std::string type_name() const { return detail::type_name(*this); } std::string type_name() const
{
return detail::type_name(*this);
}
private: private:
/*! /*!
...@@ -10838,14 +10877,14 @@ class basic_json ...@@ -10838,14 +10877,14 @@ class basic_json
} }
private: private:
friend bool operator==(json_pointer const &lhs, friend bool operator==(json_pointer const& lhs,
json_pointer const &rhs) noexcept json_pointer const& rhs) noexcept
{ {
return lhs.reference_tokens == rhs.reference_tokens; return lhs.reference_tokens == rhs.reference_tokens;
} }
friend bool operator!=(json_pointer const &lhs, friend bool operator!=(json_pointer const& lhs,
json_pointer const &rhs) noexcept json_pointer const& rhs) noexcept
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
...@@ -11536,7 +11575,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept ...@@ -11536,7 +11575,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2, // integer 2, // integer
2, // unsigned 2, // unsigned
2, // float 2, // float
}}; }
};
// discarded values are not comparable // discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded) if (lhs == value_t::discarded or rhs == value_t::discarded)
...@@ -11571,25 +11611,25 @@ using json = basic_json<>; ...@@ -11571,25 +11611,25 @@ using json = basic_json<>;
// specialization of std::swap, and std::hash // specialization of std::swap, and std::hash
namespace std namespace std
{ {
/*! /*!
@brief exchanges the values of two JSON objects @brief exchanges the values of two JSON objects
@since version 1.0.0 @since version 1.0.0
*/ */
template<> template<>
inline void swap(nlohmann::json& j1, inline void swap(nlohmann::json& j1,
nlohmann::json& j2) noexcept( nlohmann::json& j2) noexcept(
is_nothrow_move_constructible<nlohmann::json>::value and is_nothrow_move_constructible<nlohmann::json>::value and
is_nothrow_move_assignable<nlohmann::json>::value is_nothrow_move_assignable<nlohmann::json>::value
) )
{ {
j1.swap(j2); j1.swap(j2);
} }
/// hash value for JSON objects /// hash value for JSON objects
template<> template<>
struct hash<nlohmann::json> struct hash<nlohmann::json>
{ {
/*! /*!
@brief return a hash value for a JSON object @brief return a hash value for a JSON object
...@@ -11601,7 +11641,7 @@ namespace std ...@@ -11601,7 +11641,7 @@ namespace std
const auto& h = hash<nlohmann::json::string_t>(); const auto& h = hash<nlohmann::json::string_t>();
return h(j.dump()); return h(j.dump());
} }
}; };
} // namespace std } // namespace std
/*! /*!
......
...@@ -11,8 +11,8 @@ enum test ...@@ -11,8 +11,8 @@ enum test
struct pod {}; struct pod {};
struct pod_bis {}; struct pod_bis {};
void to_json(json &, pod) noexcept; void to_json(json&, pod) noexcept;
void to_json(json &, pod_bis); void to_json(json&, pod_bis);
void from_json(const json&, pod) noexcept; void from_json(const json&, pod) noexcept;
void from_json(const json&, pod_bis); void from_json(const json&, pod_bis);
static json j; static json j;
......
...@@ -63,7 +63,7 @@ TEST_CASE("regression tests") ...@@ -63,7 +63,7 @@ TEST_CASE("regression tests")
SECTION("pull request #71 - handle enum type") SECTION("pull request #71 - handle enum type")
{ {
enum { t = 0 , u = 1}; enum { t = 0, u = 1};
json j = json::array(); json j = json::array();
j.push_back(t); j.push_back(t);
......
...@@ -114,22 +114,22 @@ void to_json(Json& j, country c) ...@@ -114,22 +114,22 @@ void to_json(Json& j, country c)
} }
template <typename Json> template <typename Json>
void to_json(Json& j, const person & p) void to_json(Json& j, const person& p)
{ {
j = Json{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}}; j = Json{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}};
} }
void to_json(nlohmann::json& j, const address & a) void to_json(nlohmann::json& j, const address& a)
{ {
j = a.m_val; j = a.m_val;
} }
void to_json(nlohmann::json& j, const contact & c) void to_json(nlohmann::json& j, const contact& c)
{ {
j = json{{"person", c.m_person}, {"address", c.m_address}}; j = json{{"person", c.m_person}, {"address", c.m_address}};
} }
void to_json(nlohmann::json& j, const contact_book & cb) void to_json(nlohmann::json& j, const contact_book& cb)
{ {
j = json{{"name", cb.m_book_name}, {"contacts", cb.m_contacts}}; j = json{{"name", cb.m_book_name}, {"contacts", cb.m_contacts}};
} }
...@@ -140,28 +140,28 @@ bool operator==(age lhs, age rhs) ...@@ -140,28 +140,28 @@ bool operator==(age lhs, age rhs)
return lhs.m_val == rhs.m_val; return lhs.m_val == rhs.m_val;
} }
bool operator==(const address & lhs, const address & rhs) bool operator==(const address& lhs, const address& rhs)
{ {
return lhs.m_val == rhs.m_val; return lhs.m_val == rhs.m_val;
} }
bool operator==(const name & lhs, const name & rhs) bool operator==(const name& lhs, const name& rhs)
{ {
return lhs.m_val == rhs.m_val; return lhs.m_val == rhs.m_val;
} }
bool operator==(const person & lhs, const person & rhs) bool operator==(const person& lhs, const person& rhs)
{ {
return std::tie(lhs.m_name, lhs.m_age) == std::tie(rhs.m_name, rhs.m_age); return std::tie(lhs.m_name, lhs.m_age) == std::tie(rhs.m_name, rhs.m_age);
} }
bool operator==(const contact & lhs, const contact & rhs) bool operator==(const contact& lhs, const contact& rhs)
{ {
return std::tie(lhs.m_person, lhs.m_address) == return std::tie(lhs.m_person, lhs.m_address) ==
std::tie(rhs.m_person, rhs.m_address); std::tie(rhs.m_person, rhs.m_address);
} }
bool operator==(const contact_book & lhs, const contact_book & rhs) bool operator==(const contact_book& lhs, const contact_book& rhs)
{ {
return std::tie(lhs.m_book_name, lhs.m_contacts) == return std::tie(lhs.m_book_name, lhs.m_contacts) ==
std::tie(rhs.m_book_name, rhs.m_contacts); std::tie(rhs.m_book_name, rhs.m_contacts);
...@@ -172,19 +172,19 @@ bool operator==(const contact_book & lhs, const contact_book & rhs) ...@@ -172,19 +172,19 @@ bool operator==(const contact_book & lhs, const contact_book & rhs)
namespace udt namespace udt
{ {
template <typename Json> template <typename Json>
void from_json(const Json & j, age& a) void from_json(const Json& j, age& a)
{ {
a.m_val = j.template get<int>(); a.m_val = j.template get<int>();
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, name& n) void from_json(const Json& j, name& n)
{ {
n.m_val = j.template get<std::string>(); n.m_val = j.template get<std::string>();
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, country& c) void from_json(const Json& j, country& c)
{ {
const auto str = j.template get<std::string>(); const auto str = j.template get<std::string>();
static const std::map<std::string, country> m = static const std::map<std::string, country> m =
...@@ -200,25 +200,25 @@ void from_json(const Json & j, country& c) ...@@ -200,25 +200,25 @@ void from_json(const Json & j, country& c)
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, person& p) void from_json(const Json& j, person& p)
{ {
p.m_age = j["age"].template get<age>(); p.m_age = j["age"].template get<age>();
p.m_name = j["name"].template get<name>(); p.m_name = j["name"].template get<name>();
p.m_country = j["country"].template get<country>(); p.m_country = j["country"].template get<country>();
} }
void from_json(const nlohmann::json & j, address& a) void from_json(const nlohmann::json& j, address& a)
{ {
a.m_val = j.get<std::string>(); a.m_val = j.get<std::string>();
} }
void from_json(const nlohmann::json & j, contact& c) void from_json(const nlohmann::json& j, contact& c)
{ {
c.m_person = j["person"].get<person>(); c.m_person = j["person"].get<person>();
c.m_address = j["address"].get<address>(); c.m_address = j["address"].get<address>();
} }
void from_json(const nlohmann::json & j, contact_book& cb) void from_json(const nlohmann::json& j, contact_book& cb)
{ {
cb.m_book_name = j["name"].get<name>(); cb.m_book_name = j["name"].get<name>();
cb.m_contacts = j["contacts"].get<std::vector<contact>>(); cb.m_contacts = j["contacts"].get<std::vector<contact>>();
...@@ -297,7 +297,7 @@ namespace nlohmann ...@@ -297,7 +297,7 @@ namespace nlohmann
template <typename T> template <typename T>
struct adl_serializer<std::shared_ptr<T>> struct adl_serializer<std::shared_ptr<T>>
{ {
static void to_json(json& j, const std::shared_ptr<T> & opt) static void to_json(json& j, const std::shared_ptr<T>& opt)
{ {
if (opt) if (opt)
{ {
...@@ -309,7 +309,7 @@ struct adl_serializer<std::shared_ptr<T>> ...@@ -309,7 +309,7 @@ struct adl_serializer<std::shared_ptr<T>>
} }
} }
static void from_json(const json & j, std::shared_ptr<T>& opt) static void from_json(const json& j, std::shared_ptr<T>& opt)
{ {
if (j.is_null()) if (j.is_null())
{ {
...@@ -325,12 +325,12 @@ struct adl_serializer<std::shared_ptr<T>> ...@@ -325,12 +325,12 @@ struct adl_serializer<std::shared_ptr<T>>
template <> template <>
struct adl_serializer<udt::legacy_type> struct adl_serializer<udt::legacy_type>
{ {
static void to_json(json& j, const udt::legacy_type & l) static void to_json(json& j, const udt::legacy_type& l)
{ {
j = std::stoi(l.number); j = std::stoi(l.number);
} }
static void from_json(const json & j, udt::legacy_type& l) static void from_json(const json& j, udt::legacy_type& l)
{ {
l.number = std::to_string(j.get<int>()); l.number = std::to_string(j.get<int>());
} }
...@@ -395,18 +395,18 @@ template <> ...@@ -395,18 +395,18 @@ template <>
struct adl_serializer<std::vector<float>> struct adl_serializer<std::vector<float>>
{ {
using type = std::vector<float>; using type = std::vector<float>;
static void to_json(json& j, const type &) static void to_json(json& j, const type&)
{ {
j = "hijacked!"; j = "hijacked!";
} }
static void from_json(const json &, type& opt) static void from_json(const json&, type& opt)
{ {
opt = {42.0, 42.0, 42.0}; opt = {42.0, 42.0, 42.0};
} }
// preferred version // preferred version
static type from_json(const json &) static type from_json(const json&)
{ {
return {4.0, 5.0, 6.0}; return {4.0, 5.0, 6.0};
} }
...@@ -419,7 +419,7 @@ TEST_CASE("even supported types can be specialized", "[udt]") ...@@ -419,7 +419,7 @@ TEST_CASE("even supported types can be specialized", "[udt]")
CHECK(j.dump() == R"("hijacked!")"); CHECK(j.dump() == R"("hijacked!")");
auto f = j.get<std::vector<float>>(); auto f = j.get<std::vector<float>>();
// the single argument from_json method is preferred // the single argument from_json method is preferred
CHECK((f == std::vector<float>{4.0, 5.0, 6.0})); CHECK((f == std::vector<float> {4.0, 5.0, 6.0}));
} }
namespace nlohmann namespace nlohmann
...@@ -427,7 +427,7 @@ namespace nlohmann ...@@ -427,7 +427,7 @@ namespace nlohmann
template <typename T> template <typename T>
struct adl_serializer<std::unique_ptr<T>> struct adl_serializer<std::unique_ptr<T>>
{ {
static void to_json(json& j, const std::unique_ptr<T> & opt) static void to_json(json& j, const std::unique_ptr<T>& opt)
{ {
if (opt) if (opt)
{ {
...@@ -440,7 +440,7 @@ struct adl_serializer<std::unique_ptr<T>> ...@@ -440,7 +440,7 @@ struct adl_serializer<std::unique_ptr<T>>
} }
// this is the overload needed for non-copyable types, // this is the overload needed for non-copyable types,
static std::unique_ptr<T> from_json(const json & j) static std::unique_ptr<T> from_json(const json& j)
{ {
if (j.is_null()) if (j.is_null())
{ {
...@@ -494,9 +494,9 @@ struct pod_serializer ...@@ -494,9 +494,9 @@ struct pod_serializer
// use adl for non-pods, or scalar types // use adl for non-pods, or scalar types
template < template <
typename Json, typename U = T, typename Json, typename U = T,
typename std::enable_if< typename std::enable_if <
not(std::is_pod<U>::value and std::is_class<U>::value), int>::type = 0> not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 >
static void from_json(const Json &j, U &t) static void from_json(const Json& j, U& t)
{ {
using nlohmann::from_json; using nlohmann::from_json;
from_json(j, t); from_json(j, t);
...@@ -506,7 +506,7 @@ struct pod_serializer ...@@ -506,7 +506,7 @@ struct pod_serializer
template <typename Json, typename U = T, template <typename Json, typename U = T,
typename std::enable_if< typename std::enable_if<
std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0> std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0>
static void from_json(const Json &j, U &t) static void from_json(const Json& j, U& t)
{ {
std::uint64_t value; std::uint64_t value;
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue // TODO The following block is no longer relevant in this serializer, make another one that shows the issue
...@@ -524,15 +524,15 @@ struct pod_serializer ...@@ -524,15 +524,15 @@ struct pod_serializer
// calling get calls from_json, for now, we cannot do this in custom // calling get calls from_json, for now, we cannot do this in custom
// serializers // serializers
nlohmann::from_json(j, value); nlohmann::from_json(j, value);
auto bytes = static_cast<char *>(static_cast<void *>(&value)); auto bytes = static_cast<char*>(static_cast<void*>(&value));
std::memcpy(&t, bytes, sizeof(value)); std::memcpy(&t, bytes, sizeof(value));
} }
template < template <
typename Json, typename U = T, typename Json, typename U = T,
typename std::enable_if< typename std::enable_if <
not(std::is_pod<U>::value and std::is_class<U>::value), int>::type = 0> not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 >
static void to_json(Json &j, const T &t) static void to_json(Json& j, const T& t)
{ {
using nlohmann::to_json; using nlohmann::to_json;
to_json(j, t); to_json(j, t);
...@@ -541,9 +541,9 @@ struct pod_serializer ...@@ -541,9 +541,9 @@ struct pod_serializer
template <typename Json, typename U = T, template <typename Json, typename U = T,
typename std::enable_if< typename std::enable_if<
std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0> std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0>
static void to_json(Json &j, const T &t) noexcept static void to_json(Json& j, const T& t) noexcept
{ {
auto bytes = static_cast< const unsigned char*>(static_cast<const void *>(&t)); auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
std::uint64_t value = bytes[0]; std::uint64_t value = bytes[0];
for (auto i = 1; i < 8; ++i) for (auto i = 1; i < 8; ++i)
value |= std::uint64_t{bytes[i]} << 8 * i; value |= std::uint64_t{bytes[i]} << 8 * i;
...@@ -566,13 +566,13 @@ struct non_pod ...@@ -566,13 +566,13 @@ struct non_pod
}; };
template <typename Json> template <typename Json>
void to_json(Json& j, const non_pod & np) void to_json(Json& j, const non_pod& np)
{ {
j = np.s; j = np.s;
} }
template <typename Json> template <typename Json>
void from_json(const Json & j, non_pod& np) void from_json(const Json& j, non_pod& np)
{ {
np.s = j.template get<std::string>(); np.s = j.template get<std::string>();
} }
...@@ -583,7 +583,7 @@ bool operator==(small_pod lhs, small_pod rhs) noexcept ...@@ -583,7 +583,7 @@ bool operator==(small_pod lhs, small_pod rhs) noexcept
std::tie(rhs.begin, rhs.middle, rhs.end); std::tie(rhs.begin, rhs.middle, rhs.end);
} }
bool operator==(const non_pod &lhs, const non_pod &rhs) noexcept bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept
{ {
return lhs.s == rhs.s; return lhs.s == rhs.s;
} }
...@@ -622,13 +622,13 @@ using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, boo ...@@ -622,13 +622,13 @@ using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, boo
template <typename T, typename> template <typename T, typename>
struct another_adl_serializer struct another_adl_serializer
{ {
static void from_json(const custom_json & j , T& t) static void from_json(const custom_json& j, T& t)
{ {
using nlohmann::from_json; using nlohmann::from_json;
from_json(j, t); from_json(j, t);
} }
static void to_json(custom_json& j , const T & t) static void to_json(custom_json& j, const T& t)
{ {
using nlohmann::to_json; using nlohmann::to_json;
to_json(j, t); to_json(j, t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment