mirror of
https://github.com/nlohmann/json.git
synced 2026-03-18 23:15:59 +00:00
🎨 use Clang-Format
This commit is contained in:
@@ -24,8 +24,7 @@ struct adl_serializer
|
||||
/// @brief convert a JSON value to any value type
|
||||
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
|
||||
template<typename BasicJsonType, typename TargetType = ValueType>
|
||||
static auto from_json(BasicJsonType&& j, TargetType& val) noexcept(
|
||||
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
|
||||
static auto from_json(BasicJsonType&& j, TargetType& val) noexcept(noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
|
||||
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
|
||||
{
|
||||
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
|
||||
@@ -34,8 +33,7 @@ struct adl_serializer
|
||||
/// @brief convert a JSON value to any value type
|
||||
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
|
||||
template<typename BasicJsonType, typename TargetType = ValueType>
|
||||
static auto from_json(BasicJsonType&& j) noexcept(
|
||||
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{})))
|
||||
static auto from_json(BasicJsonType&& j) noexcept(noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{})))
|
||||
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{}))
|
||||
{
|
||||
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType>{});
|
||||
@@ -44,8 +42,7 @@ struct adl_serializer
|
||||
/// @brief convert any value type to a JSON value
|
||||
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
|
||||
template<typename BasicJsonType, typename TargetType = ValueType>
|
||||
static auto to_json(BasicJsonType& j, TargetType&& val) noexcept(
|
||||
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
|
||||
static auto to_json(BasicJsonType& j, TargetType&& val) noexcept(noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
|
||||
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
|
||||
{
|
||||
::nlohmann::to_json(j, std::forward<TargetType>(val));
|
||||
|
||||
@@ -48,51 +48,39 @@
|
||||
|
||||
// Construct the namespace ABI tags component
|
||||
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi##a##b
|
||||
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
|
||||
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
|
||||
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
|
||||
|
||||
#define NLOHMANN_JSON_ABI_TAGS \
|
||||
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
|
||||
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
|
||||
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
|
||||
#define NLOHMANN_JSON_ABI_TAGS NLOHMANN_JSON_ABI_TAGS_CONCAT(NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
|
||||
|
||||
// Construct the namespace version component
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
|
||||
_v##major##_##minor##_##patch
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
|
||||
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) _v##major##_##minor##_##patch
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
|
||||
|
||||
#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION
|
||||
#else
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION \
|
||||
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
|
||||
NLOHMANN_JSON_VERSION_MINOR, \
|
||||
NLOHMANN_JSON_VERSION_PATCH)
|
||||
#define NLOHMANN_JSON_NAMESPACE_VERSION \
|
||||
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, NLOHMANN_JSON_VERSION_PATCH)
|
||||
#endif
|
||||
|
||||
// Combine namespace components
|
||||
#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a##b
|
||||
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
|
||||
NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
|
||||
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
|
||||
|
||||
#ifndef NLOHMANN_JSON_NAMESPACE
|
||||
#define NLOHMANN_JSON_NAMESPACE \
|
||||
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
|
||||
NLOHMANN_JSON_ABI_TAGS, \
|
||||
NLOHMANN_JSON_NAMESPACE_VERSION)
|
||||
#define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT(NLOHMANN_JSON_ABI_TAGS, NLOHMANN_JSON_NAMESPACE_VERSION)
|
||||
#endif
|
||||
|
||||
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
||||
namespace nlohmann { \
|
||||
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
|
||||
NLOHMANN_JSON_ABI_TAGS, \
|
||||
NLOHMANN_JSON_NAMESPACE_VERSION) {
|
||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
||||
namespace nlohmann \
|
||||
{ \
|
||||
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT(NLOHMANN_JSON_ABI_TAGS, NLOHMANN_JSON_NAMESPACE_VERSION) \
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef NLOHMANN_JSON_NAMESPACE_END
|
||||
#define NLOHMANN_JSON_NAMESPACE_END \
|
||||
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \
|
||||
#define NLOHMANN_JSON_NAMESPACE_END \
|
||||
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \
|
||||
} // namespace nlohmann
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename BasicJsonType>
|
||||
inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
||||
@@ -43,7 +44,9 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
||||
}
|
||||
|
||||
// overloads for basic_json template parameters
|
||||
template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename ArithmeticType,
|
||||
enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0>
|
||||
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
||||
{
|
||||
switch (static_cast<value_t>(j))
|
||||
@@ -96,12 +99,12 @@ inline void from_json(const BasicJsonType& j, typename BasicJsonType::string_t&
|
||||
s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
||||
}
|
||||
|
||||
template<
|
||||
typename BasicJsonType,
|
||||
typename StringType,
|
||||
enable_if_t<
|
||||
std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value && !std::is_same<typename BasicJsonType::string_t, StringType>::value && !is_json_ref<StringType>::value,
|
||||
int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename StringType,
|
||||
enable_if_t<std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value &&
|
||||
is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value &&
|
||||
!std::is_same<typename BasicJsonType::string_t, StringType>::value && !is_json_ref<StringType>::value,
|
||||
int> = 0>
|
||||
inline void from_json(const BasicJsonType& j, StringType& s)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
||||
@@ -185,8 +188,7 @@ inline void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType:
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename T, std::size_t N>
|
||||
auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> /*unused*/)
|
||||
-> decltype(j.template get<T>(), void())
|
||||
auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> /*unused*/) -> decltype(j.template get<T>(), void())
|
||||
{
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -194,11 +196,11 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priorit
|
||||
}
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename ConstructibleArrayType,
|
||||
enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0>
|
||||
auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)
|
||||
-> decltype(arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
|
||||
j.template get<typename ConstructibleArrayType::value_type>(),
|
||||
void())
|
||||
-> decltype(arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), j.template get<typename ConstructibleArrayType::value_type>(), void())
|
||||
{
|
||||
using std::end;
|
||||
|
||||
@@ -212,29 +214,31 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
|
||||
arr = std::move(ret);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename ConstructibleArrayType,
|
||||
enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, int> = 0>
|
||||
inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<0> /*unused*/)
|
||||
{
|
||||
using std::end;
|
||||
|
||||
ConstructibleArrayType ret;
|
||||
std::transform(
|
||||
j.begin(),
|
||||
j.end(),
|
||||
std::inserter(ret, end(ret)),
|
||||
[](const BasicJsonType& i) {
|
||||
// get<BasicJsonType>() returns *this, this won't call a from_json
|
||||
// method when value_type is BasicJsonType
|
||||
return i.template get<typename ConstructibleArrayType::value_type>();
|
||||
});
|
||||
std::transform(j.begin(), j.end(), std::inserter(ret, end(ret)), [](const BasicJsonType& i) {
|
||||
// get<BasicJsonType>() returns *this, this won't call a from_json
|
||||
// method when value_type is BasicJsonType
|
||||
return i.template get<typename ConstructibleArrayType::value_type>();
|
||||
});
|
||||
arr = std::move(ret);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType, enable_if_t<is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value && !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value && !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value && !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value && !is_basic_json<ConstructibleArrayType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename ConstructibleArrayType,
|
||||
enable_if_t<is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value &&
|
||||
!is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value &&
|
||||
!is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value &&
|
||||
!std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value && !is_basic_json<ConstructibleArrayType>::value,
|
||||
int> = 0>
|
||||
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
|
||||
-> decltype(from_json_array_impl(j, arr, priority_tag<3>{}),
|
||||
j.template get<typename ConstructibleArrayType::value_type>(),
|
||||
void())
|
||||
-> decltype(from_json_array_impl(j, arr, priority_tag<3>{}), j.template get<typename ConstructibleArrayType::value_type>(), void())
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||
{
|
||||
@@ -245,9 +249,8 @@ auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename T, std::size_t... Idx>
|
||||
std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
|
||||
identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/,
|
||||
index_sequence<Idx...> /*unused*/)
|
||||
std::array<T, sizeof...(Idx)>
|
||||
from_json_inplace_array_impl(BasicJsonType&& j, identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
|
||||
{
|
||||
return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}};
|
||||
}
|
||||
@@ -275,7 +278,9 @@ inline void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t&
|
||||
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleObjectType, enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename ConstructibleObjectType,
|
||||
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
|
||||
inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
|
||||
@@ -286,13 +291,9 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
ConstructibleObjectType ret;
|
||||
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
||||
using value_type = typename ConstructibleObjectType::value_type;
|
||||
std::transform(
|
||||
inner_object->begin(),
|
||||
inner_object->end(),
|
||||
std::inserter(ret, ret.begin()),
|
||||
[](typename BasicJsonType::object_t::value_type const& p) {
|
||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
});
|
||||
std::transform(inner_object->begin(), inner_object->end(), std::inserter(ret, ret.begin()), [](typename BasicJsonType::object_t::value_type const& p) {
|
||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
});
|
||||
obj = std::move(ret);
|
||||
}
|
||||
|
||||
@@ -300,7 +301,13 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
// (BooleanType, etc..); note: Is it really necessary to provide explicit
|
||||
// overloads for boolean_t etc. in case of a custom BooleanType which is not
|
||||
// an arithmetic type?
|
||||
template<typename BasicJsonType, typename ArithmeticType, enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value && !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename ArithmeticType,
|
||||
enable_if_t<std::is_arithmetic<ArithmeticType>::value && !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value &&
|
||||
!std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value &&
|
||||
!std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value &&
|
||||
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
|
||||
int> = 0>
|
||||
inline void from_json(const BasicJsonType& j, ArithmeticType& val)
|
||||
{
|
||||
switch (static_cast<value_t>(j))
|
||||
@@ -346,8 +353,7 @@ std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<
|
||||
template<typename BasicJsonType, class A1, class A2>
|
||||
std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
|
||||
{
|
||||
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
|
||||
std::forward<BasicJsonType>(j).at(1).template get<A2>()};
|
||||
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>()};
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename A1, typename A2>
|
||||
@@ -380,7 +386,12 @@ auto from_json(BasicJsonType&& j, TupleRelated&& t)
|
||||
return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3>{});
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
|
||||
template<typename BasicJsonType,
|
||||
typename Key,
|
||||
typename Value,
|
||||
typename Compare,
|
||||
typename Allocator,
|
||||
typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
|
||||
inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||
@@ -398,7 +409,13 @@ inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allo
|
||||
}
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
|
||||
template<typename BasicJsonType,
|
||||
typename Key,
|
||||
typename Value,
|
||||
typename Hash,
|
||||
typename KeyEqual,
|
||||
typename Allocator,
|
||||
typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
|
||||
inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||
@@ -431,9 +448,8 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p)
|
||||
struct from_json_fn
|
||||
{
|
||||
template<typename BasicJsonType, typename T>
|
||||
auto operator()(const BasicJsonType& j, T&& val) const
|
||||
noexcept(noexcept(from_json(j, std::forward<T>(val))))
|
||||
-> decltype(from_json(j, std::forward<T>(val)))
|
||||
auto operator()(const BasicJsonType& j, T&& val) const noexcept(noexcept(from_json(j, std::forward<T>(val))))
|
||||
-> decltype(from_json(j, std::forward<T>(val)))
|
||||
{
|
||||
return from_json(j, std::forward<T>(val));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*!
|
||||
@brief implements the Grisu2 algorithm for binary to decimal floating-point
|
||||
@@ -40,7 +41,8 @@ For a detailed description of the algorithm see:
|
||||
Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language
|
||||
Design and Implementation, PLDI 1996
|
||||
*/
|
||||
namespace dtoa_impl {
|
||||
namespace dtoa_impl
|
||||
{
|
||||
|
||||
template<typename Target, typename Source>
|
||||
Target reinterpret_bits(const Source source)
|
||||
@@ -199,8 +201,7 @@ boundaries compute_boundaries(FloatType value)
|
||||
// If v is normalized:
|
||||
// value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1))
|
||||
|
||||
static_assert(std::numeric_limits<FloatType>::is_iec559,
|
||||
"internal error: dtoa_short requires an IEEE-754 floating-point implementation");
|
||||
static_assert(std::numeric_limits<FloatType>::is_iec559, "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
|
||||
|
||||
constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
|
||||
constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
|
||||
@@ -214,9 +215,7 @@ boundaries compute_boundaries(FloatType value)
|
||||
const std::uint64_t F = bits & (kHiddenBit - 1);
|
||||
|
||||
const bool is_denormal = E == 0;
|
||||
const diyfp v = is_denormal
|
||||
? diyfp(F, kMinExp)
|
||||
: diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
|
||||
const diyfp v = is_denormal ? diyfp(F, kMinExp) : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
|
||||
|
||||
// Compute the boundaries m- and m+ of the floating-point value
|
||||
// v = f * 2^e.
|
||||
@@ -241,9 +240,8 @@ boundaries compute_boundaries(FloatType value)
|
||||
|
||||
const bool lower_boundary_is_closer = F == 0 && E > 1;
|
||||
const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
|
||||
const diyfp m_minus = lower_boundary_is_closer
|
||||
? diyfp(4 * v.f - 1, v.e - 2) // (B)
|
||||
: diyfp(2 * v.f - 1, v.e - 1); // (A)
|
||||
const diyfp m_minus = lower_boundary_is_closer ? diyfp(4 * v.f - 1, v.e - 2) // (B)
|
||||
: diyfp(2 * v.f - 1, v.e - 1); // (A)
|
||||
|
||||
// Determine the normalized w+ = m+.
|
||||
const diyfp w_plus = diyfp::normalize(m_plus);
|
||||
@@ -381,89 +379,28 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
|
||||
constexpr int kCachedPowersMinDecExp = -300;
|
||||
constexpr int kCachedPowersDecStep = 8;
|
||||
|
||||
static constexpr std::array<cached_power, 79> kCachedPowers =
|
||||
{
|
||||
{
|
||||
{0xAB70FE17C79AC6CA, -1060, -300},
|
||||
{0xFF77B1FCBEBCDC4F, -1034, -292},
|
||||
{0xBE5691EF416BD60C, -1007, -284},
|
||||
{0x8DD01FAD907FFC3C, -980, -276},
|
||||
{0xD3515C2831559A83, -954, -268},
|
||||
{0x9D71AC8FADA6C9B5, -927, -260},
|
||||
{0xEA9C227723EE8BCB, -901, -252},
|
||||
{0xAECC49914078536D, -874, -244},
|
||||
{0x823C12795DB6CE57, -847, -236},
|
||||
{0xC21094364DFB5637, -821, -228},
|
||||
{0x9096EA6F3848984F, -794, -220},
|
||||
{0xD77485CB25823AC7, -768, -212},
|
||||
{0xA086CFCD97BF97F4, -741, -204},
|
||||
{0xEF340A98172AACE5, -715, -196},
|
||||
{0xB23867FB2A35B28E, -688, -188},
|
||||
{0x84C8D4DFD2C63F3B, -661, -180},
|
||||
{0xC5DD44271AD3CDBA, -635, -172},
|
||||
{0x936B9FCEBB25C996, -608, -164},
|
||||
{0xDBAC6C247D62A584, -582, -156},
|
||||
{0xA3AB66580D5FDAF6, -555, -148},
|
||||
{0xF3E2F893DEC3F126, -529, -140},
|
||||
{0xB5B5ADA8AAFF80B8, -502, -132},
|
||||
{0x87625F056C7C4A8B, -475, -124},
|
||||
{0xC9BCFF6034C13053, -449, -116},
|
||||
{0x964E858C91BA2655, -422, -108},
|
||||
{0xDFF9772470297EBD, -396, -100},
|
||||
{0xA6DFBD9FB8E5B88F, -369, -92},
|
||||
{0xF8A95FCF88747D94, -343, -84},
|
||||
{0xB94470938FA89BCF, -316, -76},
|
||||
{0x8A08F0F8BF0F156B, -289, -68},
|
||||
{0xCDB02555653131B6, -263, -60},
|
||||
{0x993FE2C6D07B7FAC, -236, -52},
|
||||
{0xE45C10C42A2B3B06, -210, -44},
|
||||
{0xAA242499697392D3, -183, -36},
|
||||
{0xFD87B5F28300CA0E, -157, -28},
|
||||
{0xBCE5086492111AEB, -130, -20},
|
||||
{0x8CBCCC096F5088CC, -103, -12},
|
||||
{0xD1B71758E219652C, -77, -4},
|
||||
{0x9C40000000000000, -50, 4},
|
||||
{0xE8D4A51000000000, -24, 12},
|
||||
{0xAD78EBC5AC620000, 3, 20},
|
||||
{0x813F3978F8940984, 30, 28},
|
||||
{0xC097CE7BC90715B3, 56, 36},
|
||||
{0x8F7E32CE7BEA5C70, 83, 44},
|
||||
{0xD5D238A4ABE98068, 109, 52},
|
||||
{0x9F4F2726179A2245, 136, 60},
|
||||
{0xED63A231D4C4FB27, 162, 68},
|
||||
{0xB0DE65388CC8ADA8, 189, 76},
|
||||
{0x83C7088E1AAB65DB, 216, 84},
|
||||
{0xC45D1DF942711D9A, 242, 92},
|
||||
{0x924D692CA61BE758, 269, 100},
|
||||
{0xDA01EE641A708DEA, 295, 108},
|
||||
{0xA26DA3999AEF774A, 322, 116},
|
||||
{0xF209787BB47D6B85, 348, 124},
|
||||
{0xB454E4A179DD1877, 375, 132},
|
||||
{0x865B86925B9BC5C2, 402, 140},
|
||||
{0xC83553C5C8965D3D, 428, 148},
|
||||
{0x952AB45CFA97A0B3, 455, 156},
|
||||
{0xDE469FBD99A05FE3, 481, 164},
|
||||
{0xA59BC234DB398C25, 508, 172},
|
||||
{0xF6C69A72A3989F5C, 534, 180},
|
||||
{0xB7DCBF5354E9BECE, 561, 188},
|
||||
{0x88FCF317F22241E2, 588, 196},
|
||||
{0xCC20CE9BD35C78A5, 614, 204},
|
||||
{0x98165AF37B2153DF, 641, 212},
|
||||
{0xE2A0B5DC971F303A, 667, 220},
|
||||
{0xA8D9D1535CE3B396, 694, 228},
|
||||
{0xFB9B7CD9A4A7443C, 720, 236},
|
||||
{0xBB764C4CA7A44410, 747, 244},
|
||||
{0x8BAB8EEFB6409C1A, 774, 252},
|
||||
{0xD01FEF10A657842C, 800, 260},
|
||||
{0x9B10A4E5E9913129, 827, 268},
|
||||
{0xE7109BFBA19C0C9D, 853, 276},
|
||||
{0xAC2820D9623BF429, 880, 284},
|
||||
{0x80444B5E7AA7CF85, 907, 292},
|
||||
{0xBF21E44003ACDD2D, 933, 300},
|
||||
{0x8E679C2F5E44FF8F, 960, 308},
|
||||
{0xD433179D9C8CB841, 986, 316},
|
||||
{0x9E19DB92B4E31BA9, 1013, 324},
|
||||
}};
|
||||
static constexpr std::array<cached_power, 79> kCachedPowers = {{
|
||||
{0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292}, {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
|
||||
{0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260}, {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
|
||||
{0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228}, {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
|
||||
{0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196}, {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
|
||||
{0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164}, {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
|
||||
{0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132}, {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
|
||||
{0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100}, {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
|
||||
{0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68}, {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
|
||||
{0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36}, {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
|
||||
{0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4}, {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
|
||||
{0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28}, {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
|
||||
{0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60}, {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
|
||||
{0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92}, {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
|
||||
{0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124}, {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
|
||||
{0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156}, {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
|
||||
{0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188}, {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
|
||||
{0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220}, {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
|
||||
{0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252}, {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
|
||||
{0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284}, {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
|
||||
{0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316}, {0x9E19DB92B4E31BA9, 1013, 324},
|
||||
}};
|
||||
|
||||
// This computation gives exactly the same results for k as
|
||||
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
|
||||
@@ -882,8 +819,7 @@ template<typename FloatType>
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
|
||||
{
|
||||
static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
|
||||
"internal error: not enough precision");
|
||||
static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3, "internal error: not enough precision");
|
||||
|
||||
JSON_ASSERT(std::isfinite(value));
|
||||
JSON_ASSERT(value > 0);
|
||||
@@ -1055,8 +991,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
|
||||
*/
|
||||
template<typename FloatType>
|
||||
JSON_HEDLEY_NON_NULL(1, 2)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
char* to_chars(char* first, const char* last, FloatType value)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL char* to_chars(char* first, const char* last, FloatType value)
|
||||
{
|
||||
static_cast<void>(last); // maybe unused - fix warning
|
||||
JSON_ASSERT(std::isfinite(value));
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
//////////////////
|
||||
// constructors //
|
||||
@@ -75,7 +76,9 @@ struct external_constructor<value_t::string>
|
||||
j.assert_invariant();
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleStringType, enable_if_t<!std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleStringType,
|
||||
enable_if_t<!std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, int> = 0>
|
||||
static void construct(BasicJsonType& j, const CompatibleStringType& str)
|
||||
{
|
||||
j.m_data.m_value.destroy(j.m_data.m_type);
|
||||
@@ -169,7 +172,9 @@ struct external_constructor<value_t::array>
|
||||
j.assert_invariant();
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<!std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleArrayType,
|
||||
enable_if_t<!std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, int> = 0>
|
||||
static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
|
||||
{
|
||||
using std::begin;
|
||||
@@ -236,7 +241,9 @@ struct external_constructor<value_t::object>
|
||||
j.assert_invariant();
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<!std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleObjectType,
|
||||
enable_if_t<!std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int> = 0>
|
||||
static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
|
||||
{
|
||||
using std::begin;
|
||||
@@ -260,13 +267,22 @@ inline void to_json(BasicJsonType& j, T b) noexcept
|
||||
external_constructor<value_t::boolean>::construct(j, b);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename BoolRef, enable_if_t<((std::is_same<std::vector<bool>::reference, BoolRef>::value && !std::is_same<std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value && !std::is_same<detail::uncvref_t<std::vector<bool>::const_reference>, typename BasicJsonType::boolean_t>::value)) && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename BoolRef,
|
||||
enable_if_t<((std::is_same<std::vector<bool>::reference, BoolRef>::value &&
|
||||
!std::is_same<std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) ||
|
||||
(std::is_same<std::vector<bool>::const_reference, BoolRef>::value &&
|
||||
!std::is_same<detail::uncvref_t<std::vector<bool>::const_reference>, typename BasicJsonType::boolean_t>::value)) &&
|
||||
std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
|
||||
int> = 0>
|
||||
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept
|
||||
{
|
||||
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleString, enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleString,
|
||||
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
|
||||
inline void to_json(BasicJsonType& j, const CompatibleString& s)
|
||||
{
|
||||
external_constructor<value_t::string>::construct(j, s);
|
||||
@@ -284,13 +300,17 @@ inline void to_json(BasicJsonType& j, FloatType val) noexcept
|
||||
external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleNumberUnsignedType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleNumberUnsignedType,
|
||||
enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
|
||||
inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
|
||||
{
|
||||
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleNumberIntegerType, enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleNumberIntegerType,
|
||||
enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
|
||||
inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
|
||||
{
|
||||
external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
|
||||
@@ -311,7 +331,13 @@ inline void to_json(BasicJsonType& j, const std::vector<bool>& e)
|
||||
external_constructor<value_t::array>::construct(j, e);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleArrayType, enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value && !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value && !is_basic_json<CompatibleArrayType>::value, int> = 0>
|
||||
template<
|
||||
typename BasicJsonType,
|
||||
typename CompatibleArrayType,
|
||||
enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value && !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value &&
|
||||
!is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value &&
|
||||
!std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value && !is_basic_json<CompatibleArrayType>::value,
|
||||
int> = 0>
|
||||
inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
|
||||
{
|
||||
external_constructor<value_t::array>::construct(j, arr);
|
||||
@@ -335,7 +361,9 @@ inline void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
|
||||
external_constructor<value_t::array>::construct(j, std::move(arr));
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleObjectType, enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value && !is_basic_json<CompatibleObjectType>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename CompatibleObjectType,
|
||||
enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value && !is_basic_json<CompatibleObjectType>::value, int> = 0>
|
||||
inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
|
||||
{
|
||||
external_constructor<value_t::object>::construct(j, obj);
|
||||
@@ -347,19 +375,21 @@ inline void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
|
||||
external_constructor<value_t::object>::construct(j, std::move(obj));
|
||||
}
|
||||
|
||||
template<
|
||||
typename BasicJsonType,
|
||||
typename T,
|
||||
std::size_t N,
|
||||
enable_if_t<!std::is_constructible<typename BasicJsonType::string_t,
|
||||
const T (&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename T,
|
||||
std::size_t N,
|
||||
enable_if_t<!std::is_constructible<typename BasicJsonType::string_t,
|
||||
const T (&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
int> = 0>
|
||||
inline void to_json(BasicJsonType& j, const T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
{
|
||||
external_constructor<value_t::array>::construct(j, arr);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename T1, typename T2, enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0>
|
||||
template<typename BasicJsonType,
|
||||
typename T1,
|
||||
typename T2,
|
||||
enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0>
|
||||
inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
|
||||
{
|
||||
j = {p.first, p.second};
|
||||
@@ -395,8 +425,7 @@ inline void to_json(BasicJsonType& j, const std_fs::path& p)
|
||||
struct to_json_fn
|
||||
{
|
||||
template<typename BasicJsonType, typename T>
|
||||
auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val))))
|
||||
-> decltype(to_json(j, std::forward<T>(val)), void())
|
||||
auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val)))) -> decltype(to_json(j, std::forward<T>(val)), void())
|
||||
{
|
||||
return to_json(j, std::forward<T>(val));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////
|
||||
// exceptions //
|
||||
@@ -155,7 +156,12 @@ class parse_error : public exception
|
||||
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
|
||||
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context)
|
||||
{
|
||||
const std::string w = concat(exception::name("parse_error", id_), "parse error", (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), ": ", exception::diagnostics(context), what_arg);
|
||||
const std::string w = concat(exception::name("parse_error", id_),
|
||||
"parse error",
|
||||
(byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""),
|
||||
": ",
|
||||
exception::diagnostics(context),
|
||||
what_arg);
|
||||
return {id_, byte_, w.c_str()};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// boost::hash_combine
|
||||
inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/// how to treat CBOR tags
|
||||
enum class cbor_tag_handler_t
|
||||
@@ -102,10 +103,7 @@ class binary_reader
|
||||
@return whether parsing was successful
|
||||
*/
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
bool sax_parse(const input_format_t format,
|
||||
json_sax_t* sax_,
|
||||
const bool strict = true,
|
||||
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
|
||||
bool sax_parse(const input_format_t format, json_sax_t* sax_, const bool strict = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
|
||||
{
|
||||
sax = sax_;
|
||||
bool result = false;
|
||||
@@ -148,7 +146,13 @@ class binary_reader
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof()))
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(110,
|
||||
chars_read,
|
||||
exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"),
|
||||
nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +228,13 @@ class binary_reader
|
||||
if (JSON_HEDLEY_UNLIKELY(len < 1))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112,
|
||||
chars_read,
|
||||
exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof();
|
||||
@@ -245,7 +255,13 @@ class binary_reader
|
||||
if (JSON_HEDLEY_UNLIKELY(len < 0))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112,
|
||||
chars_read,
|
||||
exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
// All BSON binary values have a subtype
|
||||
@@ -266,8 +282,7 @@ class binary_reader
|
||||
Unsupported BSON record type 0x...
|
||||
@return whether a valid BSON-object/array was passed to the SAX parser
|
||||
*/
|
||||
bool parse_bson_element_internal(const char_int_type element_type,
|
||||
const std::size_t element_type_parse_position)
|
||||
bool parse_bson_element_internal(const char_int_type element_type, const std::size_t element_type_parse_position)
|
||||
{
|
||||
switch (element_type)
|
||||
{
|
||||
@@ -326,9 +341,14 @@ class binary_reader
|
||||
default: // anything else not supported (yet)
|
||||
{
|
||||
std::array<char, 3> cr{{}};
|
||||
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<void>((std::snprintf)(cr.data(),
|
||||
cr.size(),
|
||||
"%.2hhX",
|
||||
static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
const std::string cr_str{cr.data()};
|
||||
return sax->parse_error(element_type_parse_position, cr_str, parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
|
||||
return sax->parse_error(element_type_parse_position,
|
||||
cr_str,
|
||||
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,8 +433,7 @@ class binary_reader
|
||||
|
||||
@return whether a valid CBOR value was passed to the SAX parser
|
||||
*/
|
||||
bool parse_cbor_internal(const bool get_char,
|
||||
const cbor_tag_handler_t tag_handler)
|
||||
bool parse_cbor_internal(const bool get_char, const cbor_tag_handler_t tag_handler)
|
||||
{
|
||||
switch (get_char ? get() : current)
|
||||
{
|
||||
@@ -521,7 +540,8 @@ class binary_reader
|
||||
case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows)
|
||||
{
|
||||
std::uint64_t number{};
|
||||
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number));
|
||||
return get_number(input_format_t::cbor, number) &&
|
||||
sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number));
|
||||
}
|
||||
|
||||
// Binary data (0x00..0x17 bytes follow)
|
||||
@@ -619,9 +639,7 @@ class binary_reader
|
||||
case 0x95:
|
||||
case 0x96:
|
||||
case 0x97:
|
||||
return get_cbor_array(
|
||||
conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu),
|
||||
tag_handler);
|
||||
return get_cbor_array(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
|
||||
|
||||
case 0x98: // array (one-byte uint8_t for n follows)
|
||||
{
|
||||
@@ -729,7 +747,12 @@ class binary_reader
|
||||
case cbor_tag_handler_t::error:
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
last_token,
|
||||
parse_error::create(112,
|
||||
chars_read,
|
||||
exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
case cbor_tag_handler_t::ignore:
|
||||
@@ -858,17 +881,12 @@ class binary_reader
|
||||
case 0:
|
||||
return std::ldexp(mant, -24);
|
||||
case 31:
|
||||
return (mant == 0)
|
||||
? std::numeric_limits<double>::infinity()
|
||||
: std::numeric_limits<double>::quiet_NaN();
|
||||
return (mant == 0) ? std::numeric_limits<double>::infinity() : std::numeric_limits<double>::quiet_NaN();
|
||||
default:
|
||||
return std::ldexp(mant + 1024, exp - 25);
|
||||
}
|
||||
}();
|
||||
return sax->number_float((half & 0x8000u) != 0
|
||||
? static_cast<number_float_t>(-val)
|
||||
: static_cast<number_float_t>(val),
|
||||
"");
|
||||
return sax->number_float((half & 0x8000u) != 0 ? static_cast<number_float_t>(-val) : static_cast<number_float_t>(val), "");
|
||||
}
|
||||
|
||||
case 0xFA: // Single-Precision Float (four-byte IEEE 754)
|
||||
@@ -886,7 +904,10 @@ class binary_reader
|
||||
default: // anything else (0xFF is handled inside the other types)
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112, chars_read, exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -981,7 +1002,16 @@ class binary_reader
|
||||
default:
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(
|
||||
113,
|
||||
chars_read,
|
||||
exception_message(input_format_t::cbor,
|
||||
concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
|
||||
"string"),
|
||||
nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1038,29 +1068,25 @@ class binary_reader
|
||||
case 0x58: // Binary data (one-byte uint8_t for n follows)
|
||||
{
|
||||
std::uint8_t len{};
|
||||
return get_number(input_format_t::cbor, len) &&
|
||||
get_binary(input_format_t::cbor, len, result);
|
||||
return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result);
|
||||
}
|
||||
|
||||
case 0x59: // Binary data (two-byte uint16_t for n follow)
|
||||
{
|
||||
std::uint16_t len{};
|
||||
return get_number(input_format_t::cbor, len) &&
|
||||
get_binary(input_format_t::cbor, len, result);
|
||||
return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result);
|
||||
}
|
||||
|
||||
case 0x5A: // Binary data (four-byte uint32_t for n follow)
|
||||
{
|
||||
std::uint32_t len{};
|
||||
return get_number(input_format_t::cbor, len) &&
|
||||
get_binary(input_format_t::cbor, len, result);
|
||||
return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result);
|
||||
}
|
||||
|
||||
case 0x5B: // Binary data (eight-byte uint64_t for n follow)
|
||||
{
|
||||
std::uint64_t len{};
|
||||
return get_number(input_format_t::cbor, len) &&
|
||||
get_binary(input_format_t::cbor, len, result);
|
||||
return get_number(input_format_t::cbor, len) && get_binary(input_format_t::cbor, len, result);
|
||||
}
|
||||
|
||||
case 0x5F: // Binary data (indefinite length)
|
||||
@@ -1080,7 +1106,16 @@ class binary_reader
|
||||
default:
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(
|
||||
113,
|
||||
chars_read,
|
||||
exception_message(input_format_t::cbor,
|
||||
concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token),
|
||||
"binary"),
|
||||
nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1091,8 +1126,7 @@ class binary_reader
|
||||
@param[in] tag_handler how CBOR tags should be treated
|
||||
@return whether array creation completed
|
||||
*/
|
||||
bool get_cbor_array(const std::size_t len,
|
||||
const cbor_tag_handler_t tag_handler)
|
||||
bool get_cbor_array(const std::size_t len, const cbor_tag_handler_t tag_handler)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
|
||||
{
|
||||
@@ -1129,8 +1163,7 @@ class binary_reader
|
||||
@param[in] tag_handler how CBOR tags should be treated
|
||||
@return whether object creation completed
|
||||
*/
|
||||
bool get_cbor_object(const std::size_t len,
|
||||
const cbor_tag_handler_t tag_handler)
|
||||
bool get_cbor_object(const std::size_t len, const cbor_tag_handler_t tag_handler)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
|
||||
{
|
||||
@@ -1550,7 +1583,10 @@ class binary_reader
|
||||
default: // anything else
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1632,7 +1668,15 @@ class binary_reader
|
||||
default:
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(113,
|
||||
chars_read,
|
||||
exception_message(input_format_t::msgpack,
|
||||
concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
|
||||
"string"),
|
||||
nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1660,92 +1704,73 @@ class binary_reader
|
||||
case 0xC4: // bin 8
|
||||
{
|
||||
std::uint8_t len{};
|
||||
return get_number(input_format_t::msgpack, len) &&
|
||||
get_binary(input_format_t::msgpack, len, result);
|
||||
return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result);
|
||||
}
|
||||
|
||||
case 0xC5: // bin 16
|
||||
{
|
||||
std::uint16_t len{};
|
||||
return get_number(input_format_t::msgpack, len) &&
|
||||
get_binary(input_format_t::msgpack, len, result);
|
||||
return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result);
|
||||
}
|
||||
|
||||
case 0xC6: // bin 32
|
||||
{
|
||||
std::uint32_t len{};
|
||||
return get_number(input_format_t::msgpack, len) &&
|
||||
get_binary(input_format_t::msgpack, len, result);
|
||||
return get_number(input_format_t::msgpack, len) && get_binary(input_format_t::msgpack, len, result);
|
||||
}
|
||||
|
||||
case 0xC7: // ext 8
|
||||
{
|
||||
std::uint8_t len{};
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, len) &&
|
||||
get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, len, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, len) && get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, len, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xC8: // ext 16
|
||||
{
|
||||
std::uint16_t len{};
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, len) &&
|
||||
get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, len, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, len) && get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, len, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xC9: // ext 32
|
||||
{
|
||||
std::uint32_t len{};
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, len) &&
|
||||
get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, len, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, len) && get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, len, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xD4: // fixext 1
|
||||
{
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, 1, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, subtype) && get_binary(input_format_t::msgpack, 1, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xD5: // fixext 2
|
||||
{
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, 2, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, subtype) && get_binary(input_format_t::msgpack, 2, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xD6: // fixext 4
|
||||
{
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, 4, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, subtype) && get_binary(input_format_t::msgpack, 4, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xD7: // fixext 8
|
||||
{
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, 8, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, subtype) && get_binary(input_format_t::msgpack, 8, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
case 0xD8: // fixext 16
|
||||
{
|
||||
std::int8_t subtype{};
|
||||
return get_number(input_format_t::msgpack, subtype) &&
|
||||
get_binary(input_format_t::msgpack, 16, result) &&
|
||||
assign_and_return_true(subtype);
|
||||
return get_number(input_format_t::msgpack, subtype) && get_binary(input_format_t::msgpack, 16, result) && assign_and_return_true(subtype);
|
||||
}
|
||||
|
||||
default: // LCOV_EXCL_LINE
|
||||
@@ -2024,7 +2049,12 @@ class binary_reader
|
||||
}
|
||||
if (number < 0)
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(113,
|
||||
chars_read,
|
||||
exception_message(input_format, "count in an optimized container must be positive", "size"),
|
||||
nullptr));
|
||||
}
|
||||
result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char
|
||||
return true;
|
||||
@@ -2039,7 +2069,12 @@ class binary_reader
|
||||
}
|
||||
if (number < 0)
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(113,
|
||||
chars_read,
|
||||
exception_message(input_format, "count in an optimized container must be positive", "size"),
|
||||
nullptr));
|
||||
}
|
||||
result = static_cast<std::size_t>(number);
|
||||
return true;
|
||||
@@ -2054,7 +2089,12 @@ class binary_reader
|
||||
}
|
||||
if (number < 0)
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(113,
|
||||
chars_read,
|
||||
exception_message(input_format, "count in an optimized container must be positive", "size"),
|
||||
nullptr));
|
||||
}
|
||||
result = static_cast<std::size_t>(number);
|
||||
return true;
|
||||
@@ -2069,11 +2109,18 @@ class binary_reader
|
||||
}
|
||||
if (number < 0)
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(113,
|
||||
chars_read,
|
||||
exception_message(input_format, "count in an optimized container must be positive", "size"),
|
||||
nullptr));
|
||||
}
|
||||
if (!value_in_range_of<std::size_t>(number))
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
get_token_string(),
|
||||
out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr));
|
||||
}
|
||||
result = static_cast<std::size_t>(number);
|
||||
return true;
|
||||
@@ -2122,7 +2169,9 @@ class binary_reader
|
||||
}
|
||||
if (!value_in_range_of<std::size_t>(number))
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
get_token_string(),
|
||||
out_of_range::create(408, exception_message(input_format, "integer value overflow", "size"), nullptr));
|
||||
}
|
||||
result = detail::conditional_static_cast<std::size_t>(number);
|
||||
return true;
|
||||
@@ -2136,7 +2185,10 @@ class binary_reader
|
||||
}
|
||||
if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr));
|
||||
}
|
||||
std::vector<size_t> dim;
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
|
||||
@@ -2168,9 +2220,14 @@ class binary_reader
|
||||
for (auto i : dim)
|
||||
{
|
||||
result *= i;
|
||||
if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type()
|
||||
if (result == 0 ||
|
||||
result ==
|
||||
npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type()
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
get_token_string(),
|
||||
out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
|
||||
}
|
||||
if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(static_cast<number_unsigned_t>(i))))
|
||||
{
|
||||
@@ -2223,10 +2280,17 @@ class binary_reader
|
||||
if (current == '$')
|
||||
{
|
||||
result.second = get(); // must not ignore 'N', because 'N' maybe the type
|
||||
if (input_format == input_format_t::bjdata && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
|
||||
if (input_format == input_format_t::bjdata &&
|
||||
JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112,
|
||||
chars_read,
|
||||
exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type")))
|
||||
@@ -2242,7 +2306,13 @@ class binary_reader
|
||||
return false;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112,
|
||||
chars_read,
|
||||
exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||
@@ -2250,7 +2320,10 @@ class binary_reader
|
||||
{
|
||||
if (inside_ndarray)
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, exception_message(input_format, "ndarray can not be recursive", "size"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(112, chars_read, exception_message(input_format, "ndarray can not be recursive", "size"), nullptr));
|
||||
}
|
||||
result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters
|
||||
}
|
||||
@@ -2262,7 +2335,10 @@ class binary_reader
|
||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||
if (input_format == input_format_t::bjdata && is_ndarray)
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
get_token_string(),
|
||||
parse_error::create(112, chars_read, exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
||||
}
|
||||
return is_error;
|
||||
}
|
||||
@@ -2388,17 +2464,12 @@ class binary_reader
|
||||
case 0:
|
||||
return std::ldexp(mant, -24);
|
||||
case 31:
|
||||
return (mant == 0)
|
||||
? std::numeric_limits<double>::infinity()
|
||||
: std::numeric_limits<double>::quiet_NaN();
|
||||
return (mant == 0) ? std::numeric_limits<double>::infinity() : std::numeric_limits<double>::quiet_NaN();
|
||||
default:
|
||||
return std::ldexp(mant + 1024, exp - 25);
|
||||
}
|
||||
}();
|
||||
return sax->number_float((half & 0x8000u) != 0
|
||||
? static_cast<number_float_t>(-val)
|
||||
: static_cast<number_float_t>(val),
|
||||
"");
|
||||
return sax->number_float((half & 0x8000u) != 0 ? static_cast<number_float_t>(-val) : static_cast<number_float_t>(val), "");
|
||||
}
|
||||
|
||||
case 'd':
|
||||
@@ -2428,7 +2499,14 @@ class binary_reader
|
||||
if (JSON_HEDLEY_UNLIKELY(current > 127))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(
|
||||
113,
|
||||
chars_read,
|
||||
exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"),
|
||||
nullptr));
|
||||
}
|
||||
string_t s(1, static_cast<typename string_t::value_type>(current));
|
||||
return sax->string(s);
|
||||
@@ -2450,7 +2528,9 @@ class binary_reader
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "value"), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
last_token,
|
||||
parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "value"), nullptr));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -2477,7 +2557,10 @@ class binary_reader
|
||||
if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr));
|
||||
}
|
||||
|
||||
string_t type = it->second; // sax->string() takes a reference
|
||||
@@ -2574,7 +2657,13 @@ class binary_reader
|
||||
if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
|
||||
{
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
last_token,
|
||||
parse_error::create(112,
|
||||
chars_read,
|
||||
exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
string_t key;
|
||||
@@ -2678,7 +2767,13 @@ class binary_reader
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
|
||||
{
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
number_string,
|
||||
parse_error::create(115,
|
||||
chars_read,
|
||||
exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
switch (result_number)
|
||||
@@ -2704,7 +2799,14 @@ class binary_reader
|
||||
case token_type::end_of_input:
|
||||
case token_type::literal_or_value:
|
||||
default:
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
|
||||
return sax->parse_error(
|
||||
chars_read,
|
||||
number_string,
|
||||
parse_error::create(
|
||||
115,
|
||||
chars_read,
|
||||
exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"),
|
||||
nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2799,9 +2901,7 @@ class binary_reader
|
||||
the input before we run out of string memory.
|
||||
*/
|
||||
template<typename NumberType>
|
||||
bool get_string(const input_format_t format,
|
||||
const NumberType len,
|
||||
string_t& result)
|
||||
bool get_string(const input_format_t format, const NumberType len, string_t& result)
|
||||
{
|
||||
bool success = true;
|
||||
for (NumberType i = 0; i < len; i++)
|
||||
@@ -2832,9 +2932,7 @@ class binary_reader
|
||||
the input before we run out of memory.
|
||||
*/
|
||||
template<typename NumberType>
|
||||
bool get_binary(const input_format_t format,
|
||||
const NumberType len,
|
||||
binary_t& result)
|
||||
bool get_binary(const input_format_t format, const NumberType len, binary_t& result)
|
||||
{
|
||||
bool success = true;
|
||||
for (NumberType i = 0; i < len; i++)
|
||||
@@ -2860,7 +2958,9 @@ class binary_reader
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
|
||||
{
|
||||
return sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
|
||||
return sax->parse_error(chars_read,
|
||||
"<end of file>",
|
||||
parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -2871,7 +2971,8 @@ class binary_reader
|
||||
std::string get_token_string() const
|
||||
{
|
||||
std::array<char, 3> cr{{}};
|
||||
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<void>(
|
||||
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
return std::string{cr.data()};
|
||||
}
|
||||
|
||||
@@ -2881,9 +2982,7 @@ class binary_reader
|
||||
@param[in] context further context information
|
||||
@return a message string to use in the parse_error exceptions
|
||||
*/
|
||||
std::string exception_message(const input_format_t format,
|
||||
const std::string& detail,
|
||||
const std::string& context) const
|
||||
std::string exception_message(const input_format_t format, const std::string& detail, const std::string& context) const
|
||||
{
|
||||
std::string error_msg = "syntax error while parsing ";
|
||||
|
||||
@@ -2939,33 +3038,29 @@ class binary_reader
|
||||
json_sax_t* sax = nullptr;
|
||||
|
||||
// excluded markers in bjdata optimized type
|
||||
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
|
||||
make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
|
||||
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
|
||||
|
||||
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
|
||||
make_array<bjd_type>( \
|
||||
bjd_type{'C', "char"}, \
|
||||
bjd_type{'D', "double"}, \
|
||||
bjd_type{'I', "int16"}, \
|
||||
bjd_type{'L', "int64"}, \
|
||||
bjd_type{'M', "uint64"}, \
|
||||
bjd_type{'U', "uint8"}, \
|
||||
bjd_type{'d', "single"}, \
|
||||
bjd_type{'i', "int8"}, \
|
||||
bjd_type{'l', "int32"}, \
|
||||
bjd_type{'m', "uint32"}, \
|
||||
bjd_type{'u', "uint16"})
|
||||
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
|
||||
make_array<bjd_type>(bjd_type{'C', "char"}, \
|
||||
bjd_type{'D', "double"}, \
|
||||
bjd_type{'I', "int16"}, \
|
||||
bjd_type{'L', "int64"}, \
|
||||
bjd_type{'M', "uint64"}, \
|
||||
bjd_type{'U', "uint8"}, \
|
||||
bjd_type{'d', "single"}, \
|
||||
bjd_type{'i', "int8"}, \
|
||||
bjd_type{'l', "int32"}, \
|
||||
bjd_type{'m', "uint32"}, \
|
||||
bjd_type{'u', "uint16"})
|
||||
|
||||
JSON_PRIVATE_UNLESS_TESTED :
|
||||
// lookup tables
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
|
||||
JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
|
||||
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
|
||||
|
||||
using bjd_type = std::pair<char_int_type, string_t>;
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
|
||||
JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
|
||||
const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map = JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
|
||||
|
||||
#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
|
||||
#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/// the supported input formats
|
||||
enum class input_format_t
|
||||
@@ -187,10 +188,8 @@ template<typename BaseInputAdapter>
|
||||
struct wide_string_input_helper<BaseInputAdapter, 4>
|
||||
{
|
||||
// UTF-32
|
||||
static void fill_buffer(BaseInputAdapter& input,
|
||||
std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
|
||||
size_t& utf8_bytes_index,
|
||||
size_t& utf8_bytes_filled)
|
||||
static void
|
||||
fill_buffer(BaseInputAdapter& input, std::array<std::char_traits<char>::int_type, 4>& utf8_bytes, size_t& utf8_bytes_index, size_t& utf8_bytes_filled)
|
||||
{
|
||||
utf8_bytes_index = 0;
|
||||
|
||||
@@ -245,10 +244,8 @@ template<typename BaseInputAdapter>
|
||||
struct wide_string_input_helper<BaseInputAdapter, 2>
|
||||
{
|
||||
// UTF-16
|
||||
static void fill_buffer(BaseInputAdapter& input,
|
||||
std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
|
||||
size_t& utf8_bytes_index,
|
||||
size_t& utf8_bytes_filled)
|
||||
static void
|
||||
fill_buffer(BaseInputAdapter& input, std::array<std::char_traits<char>::int_type, 4>& utf8_bytes, size_t& utf8_bytes_index, size_t& utf8_bytes_filled)
|
||||
{
|
||||
utf8_bytes_index = 0;
|
||||
|
||||
@@ -398,7 +395,8 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
|
||||
// Enables ADL on begin(container) and end(container)
|
||||
// Encloses the using declarations in namespace for not to leak them to outside scope
|
||||
|
||||
namespace container_input_adapter_factory_impl {
|
||||
namespace container_input_adapter_factory_impl
|
||||
{
|
||||
|
||||
using std::begin;
|
||||
using std::end;
|
||||
@@ -408,8 +406,7 @@ struct container_input_adapter_factory
|
||||
{};
|
||||
|
||||
template<typename ContainerType>
|
||||
struct container_input_adapter_factory<ContainerType,
|
||||
void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
|
||||
struct container_input_adapter_factory<ContainerType, void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
|
||||
{
|
||||
using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
|
||||
|
||||
@@ -448,13 +445,11 @@ inline input_stream_adapter input_adapter(std::istream&& stream)
|
||||
using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
|
||||
|
||||
// Null-delimited strings, and the like.
|
||||
template<typename CharT,
|
||||
typename std::enable_if<
|
||||
std::is_pointer<CharT>::value &&
|
||||
!std::is_array<CharT>::value &&
|
||||
std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
|
||||
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
||||
int>::type = 0>
|
||||
template<
|
||||
typename CharT,
|
||||
typename std::enable_if<std::is_pointer<CharT>::value && !std::is_array<CharT>::value &&
|
||||
std::is_integral<typename std::remove_pointer<CharT>::type>::value && sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
||||
int>::type = 0>
|
||||
contiguous_bytes_input_adapter input_adapter(CharT b)
|
||||
{
|
||||
auto length = std::strlen(reinterpret_cast<const char*>(b));
|
||||
@@ -463,7 +458,8 @@ contiguous_bytes_input_adapter input_adapter(CharT b)
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
auto input_adapter(T (&array)[N])
|
||||
-> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
{
|
||||
return input_adapter(array, array + N);
|
||||
}
|
||||
@@ -475,19 +471,16 @@ class span_input_adapter
|
||||
{
|
||||
public:
|
||||
template<typename CharT,
|
||||
typename std::enable_if<
|
||||
std::is_pointer<CharT>::value &&
|
||||
std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
|
||||
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
||||
int>::type = 0>
|
||||
typename std::enable_if<std::is_pointer<CharT>::value && std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
|
||||
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
||||
int>::type = 0>
|
||||
span_input_adapter(CharT b, std::size_t l)
|
||||
: ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l)
|
||||
{}
|
||||
|
||||
template<class IteratorType,
|
||||
typename std::enable_if<
|
||||
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
|
||||
int>::type = 0>
|
||||
template<
|
||||
class IteratorType,
|
||||
typename std::enable_if<std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value, int>::type = 0>
|
||||
span_input_adapter(IteratorType first, IteratorType last)
|
||||
: ia(input_adapter(first, last))
|
||||
{}
|
||||
|
||||
@@ -130,9 +130,7 @@ struct json_sax
|
||||
@param[in] ex an exception object describing the error
|
||||
@return whether parsing should proceed (must return false)
|
||||
*/
|
||||
virtual bool parse_error(std::size_t position,
|
||||
const std::string& last_token,
|
||||
const detail::exception& ex) = 0;
|
||||
virtual bool parse_error(std::size_t position, const std::string& last_token, const detail::exception& ex) = 0;
|
||||
|
||||
json_sax() = default;
|
||||
json_sax(const json_sax&) = default;
|
||||
@@ -142,7 +140,8 @@ struct json_sax
|
||||
virtual ~json_sax() = default;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
/*!
|
||||
@brief SAX implementation to create a JSON value from SAX events
|
||||
|
||||
@@ -304,9 +303,7 @@ class json_sax_dom_parser
|
||||
object to which we can add elements
|
||||
*/
|
||||
template<typename Value>
|
||||
JSON_HEDLEY_RETURNS_NON_NULL
|
||||
BasicJsonType*
|
||||
handle_value(Value&& v)
|
||||
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType* handle_value(Value&& v)
|
||||
{
|
||||
if (ref_stack.empty())
|
||||
{
|
||||
@@ -352,9 +349,7 @@ class json_sax_dom_callback_parser
|
||||
using parser_callback_t = typename BasicJsonType::parser_callback_t;
|
||||
using parse_event_t = typename BasicJsonType::parse_event_t;
|
||||
|
||||
json_sax_dom_callback_parser(BasicJsonType& r,
|
||||
const parser_callback_t cb,
|
||||
const bool allow_exceptions_ = true)
|
||||
json_sax_dom_callback_parser(BasicJsonType& r, const parser_callback_t cb, const bool allow_exceptions_ = true)
|
||||
: root(r)
|
||||
, callback(cb)
|
||||
, allow_exceptions(allow_exceptions_)
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
///////////
|
||||
// lexer //
|
||||
@@ -1184,8 +1185,7 @@ scan_number_exponent:
|
||||
|
||||
default:
|
||||
{
|
||||
error_message =
|
||||
"invalid number; expected '+', '-', or digit after exponent";
|
||||
error_message = "invalid number; expected '+', '-', or digit after exponent";
|
||||
return token_type::parse_error;
|
||||
}
|
||||
}
|
||||
@@ -1454,7 +1454,8 @@ scan_number_done:
|
||||
{
|
||||
// escape control characters
|
||||
std::array<char, 9> cs{{}};
|
||||
static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<void>((
|
||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
result += cs.data();
|
||||
}
|
||||
else
|
||||
@@ -1547,17 +1548,23 @@ scan_number_done:
|
||||
// literals
|
||||
case 't':
|
||||
{
|
||||
std::array<char_type, 4> true_literal = {{static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')}};
|
||||
std::array<char_type, 4> true_literal = {
|
||||
{static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')}};
|
||||
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
std::array<char_type, 5> false_literal = {{static_cast<char_type>('f'), static_cast<char_type>('a'), static_cast<char_type>('l'), static_cast<char_type>('s'), static_cast<char_type>('e')}};
|
||||
std::array<char_type, 5> false_literal = {{static_cast<char_type>('f'),
|
||||
static_cast<char_type>('a'),
|
||||
static_cast<char_type>('l'),
|
||||
static_cast<char_type>('s'),
|
||||
static_cast<char_type>('e')}};
|
||||
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
|
||||
}
|
||||
case 'n':
|
||||
{
|
||||
std::array<char_type, 4> null_literal = {{static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')}};
|
||||
std::array<char_type, 4> null_literal = {
|
||||
{static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')}};
|
||||
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
////////////
|
||||
// parser //
|
||||
////////////
|
||||
@@ -47,8 +48,7 @@ enum class parse_event_t : std::uint8_t
|
||||
};
|
||||
|
||||
template<typename BasicJsonType>
|
||||
using parser_callback_t =
|
||||
std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>;
|
||||
using parser_callback_t = std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>;
|
||||
|
||||
/*!
|
||||
@brief syntax analysis
|
||||
@@ -210,9 +210,10 @@ class parser
|
||||
// parse key
|
||||
if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
|
||||
}
|
||||
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
|
||||
{
|
||||
@@ -222,9 +223,10 @@ class parser
|
||||
// parse separator (:)
|
||||
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
|
||||
}
|
||||
|
||||
// remember we are now inside an object
|
||||
@@ -335,22 +337,28 @@ class parser
|
||||
case token_type::parse_error:
|
||||
{
|
||||
// using "uninitialized" to avoid "expected" message
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr));
|
||||
}
|
||||
case token_type::end_of_input:
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101,
|
||||
m_lexer.get_position(),
|
||||
"attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
nullptr));
|
||||
}
|
||||
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr));
|
||||
}
|
||||
case token_type::uninitialized:
|
||||
case token_type::end_array:
|
||||
@@ -360,9 +368,10 @@ class parser
|
||||
case token_type::literal_or_value:
|
||||
default: // the last token was unexpected
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,9 +428,10 @@ class parser
|
||||
// parse key
|
||||
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
|
||||
}
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
|
||||
@@ -432,9 +442,10 @@ class parser
|
||||
// parse separator (:)
|
||||
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
|
||||
{
|
||||
return sax->parse_error(m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
|
||||
return sax->parse_error(
|
||||
m_lexer.get_position(),
|
||||
m_lexer.get_token_string(),
|
||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
|
||||
}
|
||||
|
||||
// parse values
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/// struct to capture the start position of the current token
|
||||
struct position_t
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <nlohmann/detail/iterators/primitive_iterator.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*!
|
||||
@brief an iterator value
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// forward declare, to be able to friend it later on
|
||||
template<typename IteratorType>
|
||||
@@ -48,7 +49,8 @@ template<typename BasicJsonType>
|
||||
class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
|
||||
{
|
||||
/// the iterator with BasicJsonType of different const-ness
|
||||
using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
|
||||
using other_iter_impl =
|
||||
iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
|
||||
/// allow basic_json to access private members
|
||||
friend other_iter_impl;
|
||||
friend BasicJsonType;
|
||||
@@ -58,10 +60,10 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
using object_t = typename BasicJsonType::object_t;
|
||||
using array_t = typename BasicJsonType::array_t;
|
||||
// make sure BasicJsonType is basic_json or const basic_json
|
||||
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
|
||||
"iter_impl only accepts (const) basic_json");
|
||||
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, "iter_impl only accepts (const) basic_json");
|
||||
// superficial check for the LegacyBidirectionalIterator named requirement
|
||||
static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
|
||||
static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value &&
|
||||
std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
|
||||
"basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
|
||||
|
||||
public:
|
||||
@@ -77,14 +79,11 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
/// a type to represent differences between iterators
|
||||
using difference_type = typename BasicJsonType::difference_type;
|
||||
/// defines a pointer to the type iterated over (value_type)
|
||||
using pointer = typename std::conditional<std::is_const<BasicJsonType>::value,
|
||||
typename BasicJsonType::const_pointer,
|
||||
typename BasicJsonType::pointer>::type;
|
||||
using pointer =
|
||||
typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer>::type;
|
||||
/// defines a reference to the type iterated over (value_type)
|
||||
using reference =
|
||||
typename std::conditional<std::is_const<BasicJsonType>::value,
|
||||
typename BasicJsonType::const_reference,
|
||||
typename BasicJsonType::reference>::type;
|
||||
typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference>::type;
|
||||
|
||||
iter_impl() = default;
|
||||
~iter_impl() = default;
|
||||
@@ -469,7 +468,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
@brief comparison: equal
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
template<typename IterImpl, detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr>
|
||||
template<typename IterImpl,
|
||||
detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr>
|
||||
bool operator==(const IterImpl& other) const
|
||||
{
|
||||
// if objects are not the same, the comparison is undefined
|
||||
@@ -505,7 +505,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
@brief comparison: not equal
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
template<typename IterImpl, detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr>
|
||||
template<typename IterImpl,
|
||||
detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t> = nullptr>
|
||||
bool operator!=(const IterImpl& other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename string_type>
|
||||
void int_to_string(string_type& target, std::size_t value)
|
||||
@@ -57,7 +58,8 @@ class iteration_proxy_value
|
||||
|
||||
public:
|
||||
explicit iteration_proxy_value() = default;
|
||||
explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) noexcept(std::is_nothrow_move_constructible<IteratorType>::value && std::is_nothrow_default_constructible<string_type>::value)
|
||||
explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) noexcept(std::is_nothrow_move_constructible<IteratorType>::value &&
|
||||
std::is_nothrow_default_constructible<string_type>::value)
|
||||
: anchor(std::move(it))
|
||||
, array_index(array_index_)
|
||||
{}
|
||||
@@ -65,8 +67,12 @@ class iteration_proxy_value
|
||||
iteration_proxy_value(iteration_proxy_value const&) = default;
|
||||
iteration_proxy_value& operator=(iteration_proxy_value const&) = default;
|
||||
// older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions
|
||||
iteration_proxy_value(iteration_proxy_value&&) noexcept(std::is_nothrow_move_constructible<IteratorType>::value && std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations)
|
||||
iteration_proxy_value& operator=(iteration_proxy_value&&) noexcept(std::is_nothrow_move_assignable<IteratorType>::value && std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations)
|
||||
iteration_proxy_value(iteration_proxy_value&&) noexcept(std::is_nothrow_move_constructible<IteratorType>::value &&
|
||||
std::is_nothrow_move_constructible<string_type>::value) =
|
||||
default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations)
|
||||
iteration_proxy_value& operator=(iteration_proxy_value&&) noexcept(std::is_nothrow_move_assignable<IteratorType>::value &&
|
||||
std::is_nothrow_move_assignable<string_type>::value) =
|
||||
default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations)
|
||||
~iteration_proxy_value() = default;
|
||||
|
||||
/// dereference operator (needed for range-based for)
|
||||
@@ -206,7 +212,8 @@ NLOHMANN_JSON_NAMESPACE_END
|
||||
// Structured Bindings Support to the iteration_proxy_value class
|
||||
// For further reference see https://blog.tartanllama.xyz/structured-bindings/
|
||||
// And see https://github.com/nlohmann/json/pull/1391
|
||||
namespace std {
|
||||
namespace std
|
||||
{
|
||||
|
||||
#if defined(__clang__)
|
||||
// Fix: https://github.com/nlohmann/json/issues/1401
|
||||
@@ -222,8 +229,7 @@ template<std::size_t N, typename IteratorType>
|
||||
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
|
||||
{
|
||||
public:
|
||||
using type = decltype(get<N>(std::declval<
|
||||
::nlohmann::detail::iteration_proxy_value<IteratorType>>()));
|
||||
using type = decltype(get<N>(std::declval<::nlohmann::detail::iteration_proxy_value<IteratorType>>()));
|
||||
};
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#include <nlohmann/detail/meta/void_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename It, typename = void>
|
||||
struct iterator_types
|
||||
@@ -37,14 +38,11 @@ struct iterator_types<
|
||||
// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.
|
||||
template<typename T, typename = void>
|
||||
struct iterator_traits
|
||||
{
|
||||
};
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct iterator_traits<T, enable_if_t<!std::is_pointer<T>::value>>
|
||||
: iterator_types<T>
|
||||
{
|
||||
};
|
||||
struct iterator_traits<T, enable_if_t<!std::is_pointer<T>::value>> : iterator_types<T>
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
//////////////////////
|
||||
// reverse_iterator //
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*
|
||||
@brief an iterator for primitive JSON types
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*!
|
||||
@brief Default base class of the @ref basic_json class.
|
||||
@@ -29,10 +30,7 @@ struct json_default_base
|
||||
{};
|
||||
|
||||
template<class T>
|
||||
using json_base_class = typename std::conditional<
|
||||
std::is_same<T, void>::value,
|
||||
json_default_base,
|
||||
T>::type;
|
||||
using json_base_class = typename std::conditional<std::is_same<T, void>::value, json_default_base, T>::type;
|
||||
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
@@ -94,9 +94,7 @@ class json_pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/
|
||||
json_pointer& operator/=(const json_pointer& ptr)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.end(),
|
||||
ptr.reference_tokens.begin(),
|
||||
ptr.reference_tokens.end());
|
||||
reference_tokens.insert(reference_tokens.end(), ptr.reference_tokens.begin(), ptr.reference_tokens.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -117,8 +115,7 @@ class json_pointer
|
||||
|
||||
/// @brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/
|
||||
friend json_pointer operator/(const json_pointer& lhs,
|
||||
const json_pointer& rhs)
|
||||
friend json_pointer operator/(const json_pointer& lhs, const json_pointer& rhs)
|
||||
{
|
||||
return json_pointer(lhs) /= rhs;
|
||||
}
|
||||
@@ -355,15 +352,12 @@ class json_pointer
|
||||
if (ptr->is_null())
|
||||
{
|
||||
// check if reference token is a number
|
||||
const bool nums =
|
||||
std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) {
|
||||
return std::isdigit(x);
|
||||
});
|
||||
const bool nums = std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) {
|
||||
return std::isdigit(x);
|
||||
});
|
||||
|
||||
// change value to array for numbers or "-" or to object otherwise
|
||||
*ptr = (nums || reference_token == "-")
|
||||
? detail::value_t::array
|
||||
: detail::value_t::object;
|
||||
*ptr = (nums || reference_token == "-") ? detail::value_t::array : detail::value_t::object;
|
||||
}
|
||||
|
||||
switch (ptr->type())
|
||||
@@ -431,7 +425,10 @@ class json_pointer
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||
{
|
||||
// "-" always fails the range check
|
||||
JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr));
|
||||
JSON_THROW(detail::out_of_range::create(
|
||||
402,
|
||||
detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"),
|
||||
ptr));
|
||||
}
|
||||
|
||||
// note: at performs range check
|
||||
@@ -487,7 +484,10 @@ class json_pointer
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||
{
|
||||
// "-" cannot be used for const access
|
||||
JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr));
|
||||
JSON_THROW(detail::out_of_range::create(
|
||||
402,
|
||||
detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"),
|
||||
ptr));
|
||||
}
|
||||
|
||||
// use unchecked array access
|
||||
@@ -536,7 +536,10 @@ class json_pointer
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
|
||||
{
|
||||
// "-" always fails the range check
|
||||
JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr));
|
||||
JSON_THROW(detail::out_of_range::create(
|
||||
402,
|
||||
detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"),
|
||||
ptr));
|
||||
}
|
||||
|
||||
// note: at performs range check
|
||||
@@ -666,7 +669,8 @@ class json_pointer
|
||||
// check if nonempty reference string begins with slash
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr));
|
||||
JSON_THROW(
|
||||
detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr));
|
||||
}
|
||||
|
||||
// extract the reference tokens:
|
||||
@@ -690,16 +694,12 @@ class json_pointer
|
||||
auto reference_token = reference_string.substr(start, slash - start);
|
||||
|
||||
// check reference tokens are properly escaped
|
||||
for (std::size_t pos = reference_token.find_first_of('~');
|
||||
pos != string_t::npos;
|
||||
pos = reference_token.find_first_of('~', pos + 1))
|
||||
for (std::size_t pos = reference_token.find_first_of('~'); pos != string_t::npos; pos = reference_token.find_first_of('~', pos + 1))
|
||||
{
|
||||
JSON_ASSERT(reference_token[pos] == '~');
|
||||
|
||||
// ~ must be followed by 0 or 1
|
||||
if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
|
||||
(reference_token[pos + 1] != '0' &&
|
||||
reference_token[pos + 1] != '1')))
|
||||
if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 || (reference_token[pos + 1] != '0' && reference_token[pos + 1] != '1')))
|
||||
{
|
||||
JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", nullptr));
|
||||
}
|
||||
@@ -722,9 +722,7 @@ class json_pointer
|
||||
@note Empty objects or arrays are flattened to `null`.
|
||||
*/
|
||||
template<typename BasicJsonType>
|
||||
static void flatten(const string_t& reference_string,
|
||||
const BasicJsonType& value,
|
||||
BasicJsonType& result)
|
||||
static void flatten(const string_t& reference_string, const BasicJsonType& value, BasicJsonType& result)
|
||||
{
|
||||
switch (value.type())
|
||||
{
|
||||
@@ -740,9 +738,7 @@ class json_pointer
|
||||
// iterate array and use index as reference string
|
||||
for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
|
||||
{
|
||||
flatten(detail::concat(reference_string, '/', std::to_string(i)),
|
||||
value.m_data.m_value.array->operator[](i),
|
||||
result);
|
||||
flatten(detail::concat(reference_string, '/', std::to_string(i)), value.m_data.m_value.array->operator[](i), result);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -794,8 +790,7 @@ class json_pointer
|
||||
@throw type_error.313 if value cannot be unflattened
|
||||
*/
|
||||
template<typename BasicJsonType>
|
||||
static BasicJsonType
|
||||
unflatten(const BasicJsonType& value)
|
||||
static BasicJsonType unflatten(const BasicJsonType& value)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
|
||||
{
|
||||
@@ -866,49 +861,42 @@ class json_pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
|
||||
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs) noexcept;
|
||||
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs, const json_pointer<RefStringTypeRhs>& rhs) noexcept;
|
||||
|
||||
/// @brief compares JSON pointer and string for equality
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
|
||||
template<typename RefStringTypeLhs, typename StringType>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const StringType& rhs);
|
||||
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs, const StringType& rhs);
|
||||
|
||||
/// @brief compares string and JSON pointer for equality
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
|
||||
template<typename RefStringTypeRhs, typename StringType>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator==(const StringType& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs);
|
||||
friend bool operator==(const StringType& lhs, const json_pointer<RefStringTypeRhs>& rhs);
|
||||
|
||||
/// @brief compares two JSON pointers for inequality
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/
|
||||
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs) noexcept;
|
||||
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, const json_pointer<RefStringTypeRhs>& rhs) noexcept;
|
||||
|
||||
/// @brief compares JSON pointer and string for inequality
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/
|
||||
template<typename RefStringTypeLhs, typename StringType>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const StringType& rhs);
|
||||
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, const StringType& rhs);
|
||||
|
||||
/// @brief compares string and JSON pointer for inequality
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/
|
||||
template<typename RefStringTypeRhs, typename StringType>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator!=(const StringType& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs);
|
||||
friend bool operator!=(const StringType& lhs, const json_pointer<RefStringTypeRhs>& rhs);
|
||||
|
||||
/// @brief compares two JSON pointer for less-than
|
||||
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
friend bool operator<(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs) noexcept;
|
||||
friend bool operator<(const json_pointer<RefStringTypeLhs>& lhs, const json_pointer<RefStringTypeRhs>& rhs) noexcept;
|
||||
#endif
|
||||
|
||||
private:
|
||||
@@ -919,58 +907,47 @@ class json_pointer
|
||||
#if !JSON_HAS_THREE_WAY_COMPARISON
|
||||
// functions cannot be defined inside class due to ODR violations
|
||||
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs) noexcept
|
||||
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs, const json_pointer<RefStringTypeRhs>& rhs) noexcept
|
||||
{
|
||||
return lhs.reference_tokens == rhs.reference_tokens;
|
||||
}
|
||||
|
||||
template<typename RefStringTypeLhs,
|
||||
typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>
|
||||
template<typename RefStringTypeLhs, typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>
|
||||
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))
|
||||
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const StringType& rhs)
|
||||
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs, const StringType& rhs)
|
||||
{
|
||||
return lhs == json_pointer<RefStringTypeLhs>(rhs);
|
||||
}
|
||||
|
||||
template<typename RefStringTypeRhs,
|
||||
typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>
|
||||
template<typename RefStringTypeRhs, typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>
|
||||
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))
|
||||
inline bool operator==(const StringType& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs)
|
||||
inline bool operator==(const StringType& lhs, const json_pointer<RefStringTypeRhs>& rhs)
|
||||
{
|
||||
return json_pointer<RefStringTypeRhs>(lhs) == rhs;
|
||||
}
|
||||
|
||||
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs) noexcept
|
||||
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, const json_pointer<RefStringTypeRhs>& rhs) noexcept
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename RefStringTypeLhs,
|
||||
typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>
|
||||
template<typename RefStringTypeLhs, typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>
|
||||
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer))
|
||||
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const StringType& rhs)
|
||||
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, const StringType& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename RefStringTypeRhs,
|
||||
typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>
|
||||
template<typename RefStringTypeRhs, typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>
|
||||
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer))
|
||||
inline bool operator!=(const StringType& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs)
|
||||
inline bool operator!=(const StringType& lhs, const json_pointer<RefStringTypeRhs>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||
inline bool operator<(const json_pointer<RefStringTypeLhs>& lhs,
|
||||
const json_pointer<RefStringTypeRhs>& rhs) noexcept
|
||||
inline bool operator<(const json_pointer<RefStringTypeLhs>& lhs, const json_pointer<RefStringTypeRhs>& rhs) noexcept
|
||||
{
|
||||
return lhs.reference_tokens < rhs.reference_tokens;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename BasicJsonType>
|
||||
class json_ref
|
||||
@@ -35,9 +36,7 @@ class json_ref
|
||||
: owned_value(init)
|
||||
{}
|
||||
|
||||
template<
|
||||
class... Args,
|
||||
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0>
|
||||
template<class... Args, enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0>
|
||||
json_ref(Args&&... args)
|
||||
: owned_value(std::forward<Args>(args)...)
|
||||
{}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,8 @@
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
||||
@@ -78,7 +79,8 @@ struct integer_sequence
|
||||
template<size_t... Ints>
|
||||
using index_sequence = integer_sequence<size_t, Ints...>;
|
||||
|
||||
namespace utility_internal {
|
||||
namespace utility_internal
|
||||
{
|
||||
|
||||
template<typename Seq, size_t SeqSize, size_t Rem>
|
||||
struct Extend;
|
||||
@@ -101,8 +103,7 @@ struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
|
||||
template<typename T, size_t N>
|
||||
struct Gen
|
||||
{
|
||||
using type =
|
||||
typename Extend<typename Gen<T, N / 2>::type, N / 2, N % 2>::type;
|
||||
using type = typename Extend<typename Gen<T, N / 2>::type, N / 2, N % 2>::type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include <nlohmann/detail/meta/void_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// https://en.cppreference.com/w/cpp/experimental/is_detected
|
||||
struct nonesuch
|
||||
@@ -26,11 +27,7 @@ struct nonesuch
|
||||
void operator=(nonesuch&&) = delete;
|
||||
};
|
||||
|
||||
template<class Default,
|
||||
class AlwaysVoid,
|
||||
template<class...>
|
||||
class Op,
|
||||
class... Args>
|
||||
template<class Default, class AlwaysVoid, template<class...> class Op, class... Args>
|
||||
struct detector
|
||||
{
|
||||
using value_t = std::false_type;
|
||||
@@ -64,8 +61,7 @@ template<class Expected, template<class...> class Op, class... Args>
|
||||
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
|
||||
|
||||
template<class To, template<class...> class Op, class... Args>
|
||||
using is_detected_convertible =
|
||||
std::is_convertible<detected_t<Op, Args...>, To>;
|
||||
using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>;
|
||||
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// dispatching helper struct
|
||||
template<class T>
|
||||
|
||||
@@ -17,66 +17,54 @@
|
||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
using null_function_t = decltype(std::declval<T&>().null());
|
||||
|
||||
template<typename T>
|
||||
using boolean_function_t =
|
||||
decltype(std::declval<T&>().boolean(std::declval<bool>()));
|
||||
using boolean_function_t = decltype(std::declval<T&>().boolean(std::declval<bool>()));
|
||||
|
||||
template<typename T, typename Integer>
|
||||
using number_integer_function_t =
|
||||
decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
|
||||
using number_integer_function_t = decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
|
||||
|
||||
template<typename T, typename Unsigned>
|
||||
using number_unsigned_function_t =
|
||||
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
|
||||
using number_unsigned_function_t = decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
|
||||
|
||||
template<typename T, typename Float, typename String>
|
||||
using number_float_function_t = decltype(std::declval<T&>().number_float(
|
||||
std::declval<Float>(),
|
||||
std::declval<const String&>()));
|
||||
using number_float_function_t = decltype(std::declval<T&>().number_float(std::declval<Float>(), std::declval<const String&>()));
|
||||
|
||||
template<typename T, typename String>
|
||||
using string_function_t =
|
||||
decltype(std::declval<T&>().string(std::declval<String&>()));
|
||||
using string_function_t = decltype(std::declval<T&>().string(std::declval<String&>()));
|
||||
|
||||
template<typename T, typename Binary>
|
||||
using binary_function_t =
|
||||
decltype(std::declval<T&>().binary(std::declval<Binary&>()));
|
||||
using binary_function_t = decltype(std::declval<T&>().binary(std::declval<Binary&>()));
|
||||
|
||||
template<typename T>
|
||||
using start_object_function_t =
|
||||
decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
|
||||
using start_object_function_t = decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
|
||||
|
||||
template<typename T, typename String>
|
||||
using key_function_t =
|
||||
decltype(std::declval<T&>().key(std::declval<String&>()));
|
||||
using key_function_t = decltype(std::declval<T&>().key(std::declval<String&>()));
|
||||
|
||||
template<typename T>
|
||||
using end_object_function_t = decltype(std::declval<T&>().end_object());
|
||||
|
||||
template<typename T>
|
||||
using start_array_function_t =
|
||||
decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
|
||||
using start_array_function_t = decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
|
||||
|
||||
template<typename T>
|
||||
using end_array_function_t = decltype(std::declval<T&>().end_array());
|
||||
|
||||
template<typename T, typename Exception>
|
||||
using parse_error_function_t = decltype(std::declval<T&>().parse_error(
|
||||
std::declval<std::size_t>(),
|
||||
std::declval<const std::string&>(),
|
||||
std::declval<const Exception&>()));
|
||||
using parse_error_function_t =
|
||||
decltype(std::declval<T&>().parse_error(std::declval<std::size_t>(), std::declval<const std::string&>(), std::declval<const Exception&>()));
|
||||
|
||||
template<typename SAX, typename BasicJsonType>
|
||||
struct is_sax
|
||||
{
|
||||
private:
|
||||
static_assert(is_basic_json<BasicJsonType>::value,
|
||||
"BasicJsonType must be of type basic_json<...>");
|
||||
static_assert(is_basic_json<BasicJsonType>::value, "BasicJsonType must be of type basic_json<...>");
|
||||
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
|
||||
@@ -87,27 +75,21 @@ struct is_sax
|
||||
|
||||
public:
|
||||
static constexpr bool value =
|
||||
is_detected_exact<bool, null_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, boolean_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, null_function_t, SAX>::value && is_detected_exact<bool, boolean_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
|
||||
is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
|
||||
is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
|
||||
is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
|
||||
is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
|
||||
is_detected_exact<bool, start_object_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
|
||||
is_detected_exact<bool, end_object_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, start_array_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, end_array_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
|
||||
is_detected_exact<bool, string_function_t, SAX, string_t>::value && is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
|
||||
is_detected_exact<bool, start_object_function_t, SAX>::value && is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
|
||||
is_detected_exact<bool, end_object_function_t, SAX>::value && is_detected_exact<bool, start_array_function_t, SAX>::value &&
|
||||
is_detected_exact<bool, end_array_function_t, SAX>::value && is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
|
||||
};
|
||||
|
||||
template<typename SAX, typename BasicJsonType>
|
||||
struct is_sax_static_asserts
|
||||
{
|
||||
private:
|
||||
static_assert(is_basic_json<BasicJsonType>::value,
|
||||
"BasicJsonType must be of type basic_json<...>");
|
||||
static_assert(is_basic_json<BasicJsonType>::value, "BasicJsonType must be of type basic_json<...>");
|
||||
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
|
||||
@@ -117,40 +99,25 @@ struct is_sax_static_asserts
|
||||
using exception_t = typename BasicJsonType::exception;
|
||||
|
||||
public:
|
||||
static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool null()");
|
||||
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool boolean(bool)");
|
||||
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool boolean(bool)");
|
||||
static_assert(
|
||||
is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value,
|
||||
"Missing/invalid function: bool number_integer(number_integer_t)");
|
||||
static_assert(
|
||||
is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value,
|
||||
"Missing/invalid function: bool number_unsigned(number_unsigned_t)");
|
||||
static_assert(is_detected_exact<bool, null_function_t, SAX>::value, "Missing/invalid function: bool null()");
|
||||
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, "Missing/invalid function: bool boolean(bool)");
|
||||
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, "Missing/invalid function: bool boolean(bool)");
|
||||
static_assert(is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value,
|
||||
"Missing/invalid function: bool number_integer(number_integer_t)");
|
||||
static_assert(is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value,
|
||||
"Missing/invalid function: bool number_unsigned(number_unsigned_t)");
|
||||
static_assert(is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value,
|
||||
"Missing/invalid function: bool number_float(number_float_t, const string_t&)");
|
||||
static_assert(
|
||||
is_detected_exact<bool, string_function_t, SAX, string_t>::value,
|
||||
"Missing/invalid function: bool string(string_t&)");
|
||||
static_assert(
|
||||
is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
|
||||
"Missing/invalid function: bool binary(binary_t&)");
|
||||
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool start_object(std::size_t)");
|
||||
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
|
||||
"Missing/invalid function: bool key(string_t&)");
|
||||
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool end_object()");
|
||||
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool start_array(std::size_t)");
|
||||
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
|
||||
"Missing/invalid function: bool end_array()");
|
||||
static_assert(
|
||||
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
|
||||
"Missing/invalid function: bool parse_error(std::size_t, const "
|
||||
"std::string&, const exception&)");
|
||||
static_assert(is_detected_exact<bool, string_function_t, SAX, string_t>::value, "Missing/invalid function: bool string(string_t&)");
|
||||
static_assert(is_detected_exact<bool, binary_function_t, SAX, binary_t>::value, "Missing/invalid function: bool binary(binary_t&)");
|
||||
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value, "Missing/invalid function: bool start_object(std::size_t)");
|
||||
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value, "Missing/invalid function: bool key(string_t&)");
|
||||
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value, "Missing/invalid function: bool end_object()");
|
||||
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value, "Missing/invalid function: bool start_array(std::size_t)");
|
||||
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value, "Missing/invalid function: bool end_array()");
|
||||
static_assert(is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
|
||||
"Missing/invalid function: bool parse_error(std::size_t, const "
|
||||
"std::string&, const exception&)");
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -13,14 +13,16 @@
|
||||
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||
#include <experimental/filesystem>
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
namespace std_fs = std::experimental::filesystem;
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
#elif JSON_HAS_FILESYSTEM
|
||||
#include <filesystem>
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
namespace std_fs = std::filesystem;
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
@@ -31,7 +31,8 @@ implementations of some @ref basic_json methods, and meta-programming helpers.
|
||||
|
||||
@since version 2.1.0
|
||||
*/
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/////////////
|
||||
// helpers //
|
||||
@@ -58,8 +59,10 @@ struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type
|
||||
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t
|
||||
// false_type otherwise
|
||||
template<typename BasicJsonContext>
|
||||
struct is_basic_json_context : std::integral_constant<bool,
|
||||
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value || std::is_same<BasicJsonContext, std::nullptr_t>::value>
|
||||
struct is_basic_json_context
|
||||
: std::integral_constant<bool,
|
||||
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value ||
|
||||
std::is_same<BasicJsonContext, std::nullptr_t>::value>
|
||||
{};
|
||||
|
||||
//////////////////////
|
||||
@@ -131,8 +134,7 @@ struct has_from_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>>
|
||||
{
|
||||
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
||||
|
||||
static constexpr bool value =
|
||||
is_detected_exact<void, from_json_function, serializer, const BasicJsonType&, T&>::value;
|
||||
static constexpr bool value = is_detected_exact<void, from_json_function, serializer, const BasicJsonType&, T&>::value;
|
||||
};
|
||||
|
||||
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
||||
@@ -146,8 +148,7 @@ struct has_non_default_from_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>
|
||||
{
|
||||
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
||||
|
||||
static constexpr bool value =
|
||||
is_detected_exact<T, from_json_function, serializer, const BasicJsonType&>::value;
|
||||
static constexpr bool value = is_detected_exact<T, from_json_function, serializer, const BasicJsonType&>::value;
|
||||
};
|
||||
|
||||
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
|
||||
@@ -161,8 +162,7 @@ struct has_to_json<BasicJsonType, T, enable_if_t<!is_basic_json<T>::value>>
|
||||
{
|
||||
using serializer = typename BasicJsonType::template json_serializer<T, void>;
|
||||
|
||||
static constexpr bool value =
|
||||
is_detected_exact<void, to_json_function, serializer, BasicJsonType&, T>::value;
|
||||
static constexpr bool value = is_detected_exact<void, to_json_function, serializer, BasicJsonType&, T>::value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -178,9 +178,7 @@ struct actual_object_comparator
|
||||
{
|
||||
using object_t = typename BasicJsonType::object_t;
|
||||
using object_comparator_t = typename BasicJsonType::default_object_comparator_t;
|
||||
using type = typename std::conditional<has_key_compare<object_t>::value,
|
||||
typename object_t::key_compare,
|
||||
object_comparator_t>::type;
|
||||
using type = typename std::conditional<has_key_compare<object_t>::value, typename object_t::key_compare, object_comparator_t>::type;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType>
|
||||
@@ -255,8 +253,7 @@ template<class B>
|
||||
struct conjunction<B> : B
|
||||
{};
|
||||
template<class B, class... Bn>
|
||||
struct conjunction<B, Bn...>
|
||||
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type
|
||||
struct conjunction<B, Bn...> : std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type
|
||||
{};
|
||||
|
||||
// https://en.cppreference.com/w/cpp/types/negation
|
||||
@@ -272,23 +269,19 @@ struct is_default_constructible : std::is_default_constructible<T>
|
||||
{};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
struct is_default_constructible<std::pair<T1, T2>>
|
||||
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>>
|
||||
struct is_default_constructible<std::pair<T1, T2>> : conjunction<is_default_constructible<T1>, is_default_constructible<T2>>
|
||||
{};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
struct is_default_constructible<const std::pair<T1, T2>>
|
||||
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>>
|
||||
struct is_default_constructible<const std::pair<T1, T2>> : conjunction<is_default_constructible<T1>, is_default_constructible<T2>>
|
||||
{};
|
||||
|
||||
template<typename... Ts>
|
||||
struct is_default_constructible<std::tuple<Ts...>>
|
||||
: conjunction<is_default_constructible<Ts>...>
|
||||
struct is_default_constructible<std::tuple<Ts...>> : conjunction<is_default_constructible<Ts>...>
|
||||
{};
|
||||
|
||||
template<typename... Ts>
|
||||
struct is_default_constructible<const std::tuple<Ts...>>
|
||||
: conjunction<is_default_constructible<Ts>...>
|
||||
struct is_default_constructible<const std::tuple<Ts...>> : conjunction<is_default_constructible<Ts>...>
|
||||
{};
|
||||
|
||||
template<typename T, typename... Args>
|
||||
@@ -322,12 +315,9 @@ struct is_iterator_traits<iterator_traits<T>>
|
||||
using traits = iterator_traits<T>;
|
||||
|
||||
public:
|
||||
static constexpr auto value =
|
||||
is_detected<value_type_t, traits>::value &&
|
||||
is_detected<difference_type_t, traits>::value &&
|
||||
is_detected<pointer_t, traits>::value &&
|
||||
is_detected<iterator_category_t, traits>::value &&
|
||||
is_detected<reference_t, traits>::value;
|
||||
static constexpr auto value = is_detected<value_type_t, traits>::value && is_detected<difference_type_t, traits>::value &&
|
||||
is_detected<pointer_t, traits>::value && is_detected<iterator_category_t, traits>::value &&
|
||||
is_detected<reference_t, traits>::value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -342,8 +332,7 @@ struct is_range
|
||||
// to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator
|
||||
// and https://en.cppreference.com/w/cpp/iterator/sentinel_for
|
||||
// but reimplementing these would be too much work, as a lot of other concepts are used underneath
|
||||
static constexpr auto is_iterator_begin =
|
||||
is_iterator_traits<iterator_traits<iterator>>::value;
|
||||
static constexpr auto is_iterator_begin = is_iterator_traits<iterator_traits<iterator>>::value;
|
||||
|
||||
public:
|
||||
static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
|
||||
@@ -375,22 +364,17 @@ template<typename BasicJsonType, typename CompatibleObjectType>
|
||||
struct is_compatible_object_type_impl<
|
||||
BasicJsonType,
|
||||
CompatibleObjectType,
|
||||
enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value &&
|
||||
is_detected<key_type_t, CompatibleObjectType>::value>>
|
||||
enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value && is_detected<key_type_t, CompatibleObjectType>::value>>
|
||||
{
|
||||
using object_t = typename BasicJsonType::object_t;
|
||||
|
||||
// macOS's is_constructible does not play well with nonesuch...
|
||||
static constexpr bool value =
|
||||
is_constructible<typename object_t::key_type,
|
||||
typename CompatibleObjectType::key_type>::value &&
|
||||
is_constructible<typename object_t::mapped_type,
|
||||
typename CompatibleObjectType::mapped_type>::value;
|
||||
static constexpr bool value = is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value &&
|
||||
is_constructible<typename object_t::mapped_type, typename CompatibleObjectType::mapped_type>::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleObjectType>
|
||||
struct is_compatible_object_type
|
||||
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType>
|
||||
struct is_compatible_object_type : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType>
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleObjectType, typename = void>
|
||||
@@ -401,38 +385,26 @@ template<typename BasicJsonType, typename ConstructibleObjectType>
|
||||
struct is_constructible_object_type_impl<
|
||||
BasicJsonType,
|
||||
ConstructibleObjectType,
|
||||
enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value &&
|
||||
is_detected<key_type_t, ConstructibleObjectType>::value>>
|
||||
enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value && is_detected<key_type_t, ConstructibleObjectType>::value>>
|
||||
{
|
||||
using object_t = typename BasicJsonType::object_t;
|
||||
|
||||
static constexpr bool value =
|
||||
(is_default_constructible<ConstructibleObjectType>::value &&
|
||||
(std::is_move_assignable<ConstructibleObjectType>::value ||
|
||||
std::is_copy_assignable<ConstructibleObjectType>::value) &&
|
||||
(is_constructible<typename ConstructibleObjectType::key_type,
|
||||
typename object_t::key_type>::value &&
|
||||
std::is_same<
|
||||
typename object_t::mapped_type,
|
||||
typename ConstructibleObjectType::mapped_type>::value)) ||
|
||||
(has_from_json<BasicJsonType,
|
||||
typename ConstructibleObjectType::mapped_type>::value ||
|
||||
has_non_default_from_json<
|
||||
BasicJsonType,
|
||||
typename ConstructibleObjectType::mapped_type>::value);
|
||||
static constexpr bool value = (is_default_constructible<ConstructibleObjectType>::value &&
|
||||
(std::is_move_assignable<ConstructibleObjectType>::value || std::is_copy_assignable<ConstructibleObjectType>::value) &&
|
||||
(is_constructible<typename ConstructibleObjectType::key_type, typename object_t::key_type>::value &&
|
||||
std::is_same<typename object_t::mapped_type, typename ConstructibleObjectType::mapped_type>::value)) ||
|
||||
(has_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type>::value ||
|
||||
has_non_default_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type>::value);
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleObjectType>
|
||||
struct is_constructible_object_type
|
||||
: is_constructible_object_type_impl<BasicJsonType,
|
||||
ConstructibleObjectType>
|
||||
struct is_constructible_object_type : is_constructible_object_type_impl<BasicJsonType, ConstructibleObjectType>
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleStringType>
|
||||
struct is_compatible_string_type
|
||||
{
|
||||
static constexpr auto value =
|
||||
is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
|
||||
static constexpr auto value = is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleStringType>
|
||||
@@ -445,12 +417,8 @@ struct is_constructible_string_type
|
||||
using laundered_type = ConstructibleStringType;
|
||||
#endif
|
||||
|
||||
static constexpr auto value =
|
||||
conjunction<
|
||||
is_constructible<laundered_type, typename BasicJsonType::string_t>,
|
||||
is_detected_exact<typename BasicJsonType::string_t::value_type,
|
||||
value_type_t,
|
||||
laundered_type>>::value;
|
||||
static constexpr auto value = conjunction<is_constructible<laundered_type, typename BasicJsonType::string_t>,
|
||||
is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, laundered_type>>::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
|
||||
@@ -458,24 +426,19 @@ struct is_compatible_array_type_impl : std::false_type
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleArrayType>
|
||||
struct is_compatible_array_type_impl<
|
||||
BasicJsonType,
|
||||
CompatibleArrayType,
|
||||
enable_if_t<
|
||||
is_detected<iterator_t, CompatibleArrayType>::value &&
|
||||
is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value &&
|
||||
// special case for types like std::filesystem::path whose iterator's value_type are themselves
|
||||
// c.f. https://github.com/nlohmann/json/pull/3073
|
||||
!std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value>>
|
||||
struct is_compatible_array_type_impl<BasicJsonType,
|
||||
CompatibleArrayType,
|
||||
enable_if_t<is_detected<iterator_t, CompatibleArrayType>::value &&
|
||||
is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value &&
|
||||
// special case for types like std::filesystem::path whose iterator's value_type are themselves
|
||||
// c.f. https://github.com/nlohmann/json/pull/3073
|
||||
!std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value>>
|
||||
{
|
||||
static constexpr bool value =
|
||||
is_constructible<BasicJsonType,
|
||||
range_value_t<CompatibleArrayType>>::value;
|
||||
static constexpr bool value = is_constructible<BasicJsonType, range_value_t<CompatibleArrayType>>::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleArrayType>
|
||||
struct is_compatible_array_type
|
||||
: is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType>
|
||||
struct is_compatible_array_type : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType>
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
|
||||
@@ -483,48 +446,34 @@ struct is_constructible_array_type_impl : std::false_type
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||
struct is_constructible_array_type_impl<
|
||||
BasicJsonType,
|
||||
ConstructibleArrayType,
|
||||
enable_if_t<std::is_same<ConstructibleArrayType,
|
||||
typename BasicJsonType::value_type>::value>>
|
||||
: std::true_type
|
||||
struct is_constructible_array_type_impl<BasicJsonType,
|
||||
ConstructibleArrayType,
|
||||
enable_if_t<std::is_same<ConstructibleArrayType, typename BasicJsonType::value_type>::value>> : std::true_type
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||
struct is_constructible_array_type_impl<
|
||||
BasicJsonType,
|
||||
ConstructibleArrayType,
|
||||
enable_if_t<!std::is_same<ConstructibleArrayType,
|
||||
typename BasicJsonType::value_type>::value &&
|
||||
!is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value &&
|
||||
is_default_constructible<ConstructibleArrayType>::value &&
|
||||
(std::is_move_assignable<ConstructibleArrayType>::value ||
|
||||
std::is_copy_assignable<ConstructibleArrayType>::value) &&
|
||||
enable_if_t<!std::is_same<ConstructibleArrayType, typename BasicJsonType::value_type>::value &&
|
||||
!is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value && is_default_constructible<ConstructibleArrayType>::value &&
|
||||
(std::is_move_assignable<ConstructibleArrayType>::value || std::is_copy_assignable<ConstructibleArrayType>::value) &&
|
||||
is_detected<iterator_t, ConstructibleArrayType>::value &&
|
||||
is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value &&
|
||||
is_detected<range_value_t, ConstructibleArrayType>::value &&
|
||||
// special case for types like std::filesystem::path whose iterator's value_type are themselves
|
||||
// c.f. https://github.com/nlohmann/json/pull/3073
|
||||
!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value &&
|
||||
is_complete_type<
|
||||
detected_t<range_value_t, ConstructibleArrayType>>::value>>
|
||||
is_complete_type<detected_t<range_value_t, ConstructibleArrayType>>::value>>
|
||||
{
|
||||
using value_type = range_value_t<ConstructibleArrayType>;
|
||||
|
||||
static constexpr bool value =
|
||||
std::is_same<value_type,
|
||||
typename BasicJsonType::array_t::value_type>::value ||
|
||||
has_from_json<BasicJsonType,
|
||||
value_type>::value ||
|
||||
has_non_default_from_json<
|
||||
BasicJsonType,
|
||||
value_type>::value;
|
||||
static constexpr bool value = std::is_same<value_type, typename BasicJsonType::array_t::value_type>::value ||
|
||||
has_from_json<BasicJsonType, value_type>::value || has_non_default_from_json<BasicJsonType, value_type>::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||
struct is_constructible_array_type
|
||||
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType>
|
||||
struct is_constructible_array_type : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType>
|
||||
{};
|
||||
|
||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType, typename = void>
|
||||
@@ -532,28 +481,21 @@ struct is_compatible_integer_type_impl : std::false_type
|
||||
{};
|
||||
|
||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
||||
struct is_compatible_integer_type_impl<
|
||||
RealIntegerType,
|
||||
CompatibleNumberIntegerType,
|
||||
enable_if_t<std::is_integral<RealIntegerType>::value &&
|
||||
std::is_integral<CompatibleNumberIntegerType>::value &&
|
||||
!std::is_same<bool, CompatibleNumberIntegerType>::value>>
|
||||
struct is_compatible_integer_type_impl<RealIntegerType,
|
||||
CompatibleNumberIntegerType,
|
||||
enable_if_t<std::is_integral<RealIntegerType>::value && std::is_integral<CompatibleNumberIntegerType>::value &&
|
||||
!std::is_same<bool, CompatibleNumberIntegerType>::value>>
|
||||
{
|
||||
// is there an assert somewhere on overflows?
|
||||
using RealLimits = std::numeric_limits<RealIntegerType>;
|
||||
using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
|
||||
|
||||
static constexpr auto value =
|
||||
is_constructible<RealIntegerType,
|
||||
CompatibleNumberIntegerType>::value &&
|
||||
CompatibleLimits::is_integer &&
|
||||
RealLimits::is_signed == CompatibleLimits::is_signed;
|
||||
static constexpr auto value = is_constructible<RealIntegerType, CompatibleNumberIntegerType>::value && CompatibleLimits::is_integer &&
|
||||
RealLimits::is_signed == CompatibleLimits::is_signed;
|
||||
};
|
||||
|
||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
||||
struct is_compatible_integer_type
|
||||
: is_compatible_integer_type_impl<RealIntegerType,
|
||||
CompatibleNumberIntegerType>
|
||||
struct is_compatible_integer_type : is_compatible_integer_type_impl<RealIntegerType, CompatibleNumberIntegerType>
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleType, typename = void>
|
||||
@@ -561,18 +503,13 @@ struct is_compatible_type_impl : std::false_type
|
||||
{};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleType>
|
||||
struct is_compatible_type_impl<
|
||||
BasicJsonType,
|
||||
CompatibleType,
|
||||
enable_if_t<is_complete_type<CompatibleType>::value>>
|
||||
struct is_compatible_type_impl<BasicJsonType, CompatibleType, enable_if_t<is_complete_type<CompatibleType>::value>>
|
||||
{
|
||||
static constexpr bool value =
|
||||
has_to_json<BasicJsonType, CompatibleType>::value;
|
||||
static constexpr bool value = has_to_json<BasicJsonType, CompatibleType>::value;
|
||||
};
|
||||
|
||||
template<typename BasicJsonType, typename CompatibleType>
|
||||
struct is_compatible_type
|
||||
: is_compatible_type_impl<BasicJsonType, CompatibleType>
|
||||
struct is_compatible_type : is_compatible_type_impl<BasicJsonType, CompatibleType>
|
||||
{};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
@@ -613,7 +550,12 @@ struct is_comparable : std::false_type
|
||||
{};
|
||||
|
||||
template<typename Compare, typename A, typename B>
|
||||
struct is_comparable<Compare, A, B, void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>> : std::true_type
|
||||
struct is_comparable<
|
||||
Compare,
|
||||
A,
|
||||
B,
|
||||
void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>>
|
||||
: std::true_type
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
@@ -621,11 +563,18 @@ using detect_is_transparent = typename T::is_transparent;
|
||||
|
||||
// type trait to check if KeyType can be used as object key (without a BasicJsonType)
|
||||
// see is_usable_as_basic_json_key_type below
|
||||
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
||||
using is_usable_as_key_type = typename std::conditional<
|
||||
is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value && !(ExcludeObjectKeyType && std::is_same<KeyType, ObjectKeyType>::value) && (!RequireTransparentComparator || is_detected<detect_is_transparent, Comparator>::value) && !is_json_pointer<KeyType>::value,
|
||||
std::true_type,
|
||||
std::false_type>::type;
|
||||
template<typename Comparator,
|
||||
typename ObjectKeyType,
|
||||
typename KeyTypeCVRef,
|
||||
bool RequireTransparentComparator = true,
|
||||
bool ExcludeObjectKeyType = RequireTransparentComparator,
|
||||
typename KeyType = uncvref_t<KeyTypeCVRef>>
|
||||
using is_usable_as_key_type =
|
||||
typename std::conditional<is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value &&
|
||||
!(ExcludeObjectKeyType && std::is_same<KeyType, ObjectKeyType>::value) &&
|
||||
(!RequireTransparentComparator || is_detected<detect_is_transparent, Comparator>::value) && !is_json_pointer<KeyType>::value,
|
||||
std::true_type,
|
||||
std::false_type>::type;
|
||||
|
||||
// type trait to check if KeyType can be used as object key
|
||||
// true if:
|
||||
@@ -633,29 +582,27 @@ using is_usable_as_key_type = typename std::conditional<
|
||||
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type
|
||||
// - the comparator is transparent or RequireTransparentComparator is false
|
||||
// - KeyType is not a JSON iterator or json_pointer
|
||||
template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
|
||||
using is_usable_as_basic_json_key_type = typename std::conditional<
|
||||
is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
||||
typename BasicJsonType::object_t::key_type,
|
||||
KeyTypeCVRef,
|
||||
RequireTransparentComparator,
|
||||
ExcludeObjectKeyType>::value &&
|
||||
!is_json_iterator_of<BasicJsonType, KeyType>::value,
|
||||
std::true_type,
|
||||
std::false_type>::type;
|
||||
template<typename BasicJsonType,
|
||||
typename KeyTypeCVRef,
|
||||
bool RequireTransparentComparator = true,
|
||||
bool ExcludeObjectKeyType = RequireTransparentComparator,
|
||||
typename KeyType = uncvref_t<KeyTypeCVRef>>
|
||||
using is_usable_as_basic_json_key_type = typename std::conditional<is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
||||
typename BasicJsonType::object_t::key_type,
|
||||
KeyTypeCVRef,
|
||||
RequireTransparentComparator,
|
||||
ExcludeObjectKeyType>::value &&
|
||||
!is_json_iterator_of<BasicJsonType, KeyType>::value,
|
||||
std::true_type,
|
||||
std::false_type>::type;
|
||||
|
||||
template<typename ObjectType, typename KeyType>
|
||||
using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
|
||||
|
||||
// type trait to check if object_t has an erase() member functions accepting KeyType
|
||||
template<typename BasicJsonType, typename KeyType>
|
||||
using has_erase_with_key_type = typename std::conditional<
|
||||
is_detected<
|
||||
detect_erase_with_key_type,
|
||||
typename BasicJsonType::object_t,
|
||||
KeyType>::value,
|
||||
std::true_type,
|
||||
std::false_type>::type;
|
||||
using has_erase_with_key_type =
|
||||
typename std::conditional<is_detected<detect_erase_with_key_type, typename BasicJsonType::object_t, KeyType>::value, std::true_type, std::false_type>::type;
|
||||
|
||||
// a naive helper to check if a type is an ordered_map (exploits the fact that
|
||||
// ordered_map inherits capacity() from std::vector)
|
||||
@@ -704,12 +651,12 @@ using all_unsigned = conjunction<std::is_unsigned<Types>...>;
|
||||
|
||||
// there's a disjunction trait in another PR; replace when merged
|
||||
template<typename... Types>
|
||||
using same_sign = std::integral_constant<bool,
|
||||
all_signed<Types...>::value || all_unsigned<Types...>::value>;
|
||||
using same_sign = std::integral_constant<bool, all_signed<Types...>::value || all_unsigned<Types...>::value>;
|
||||
|
||||
template<typename OfType, typename T>
|
||||
using never_out_of_range = std::integral_constant<bool,
|
||||
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T))>;
|
||||
using never_out_of_range =
|
||||
std::integral_constant<bool,
|
||||
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) || (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T))>;
|
||||
|
||||
template<typename OfType, typename T, bool OfTypeSigned = std::is_signed<OfType>::value, bool TSigned = std::is_signed<T>::value>
|
||||
struct value_in_range_of_impl2;
|
||||
@@ -750,11 +697,15 @@ struct value_in_range_of_impl2<OfType, T, true, true>
|
||||
static constexpr bool test(T val)
|
||||
{
|
||||
using CommonType = typename std::common_type<OfType, T>::type;
|
||||
return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
||||
return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) &&
|
||||
static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename OfType, typename T, bool NeverOutOfRange = never_out_of_range<OfType, T>::value, typename = detail::enable_if_t<all_integral<OfType, T>::value>>
|
||||
template<typename OfType,
|
||||
typename T,
|
||||
bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
|
||||
typename = detail::enable_if_t<all_integral<OfType, T>::value>>
|
||||
struct value_in_range_of_impl1;
|
||||
|
||||
template<typename OfType, typename T>
|
||||
@@ -788,7 +739,8 @@ using bool_constant = std::integral_constant<bool, Value>;
|
||||
// is_c_string
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace impl {
|
||||
namespace impl
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_c_string()
|
||||
@@ -814,7 +766,8 @@ using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
|
||||
// is_transparent
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace impl {
|
||||
namespace impl
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_transparent()
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename... Ts>
|
||||
struct make_void
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
#include <nlohmann/detail/string_concat.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
///////////////////
|
||||
// binary writer //
|
||||
@@ -98,9 +99,7 @@ class binary_writer
|
||||
|
||||
case value_t::boolean:
|
||||
{
|
||||
oa->write_character(j.m_data.m_value.boolean
|
||||
? to_char_type(0xF5)
|
||||
: to_char_type(0xF4));
|
||||
oa->write_character(j.m_data.m_value.boolean ? to_char_type(0xF5) : to_char_type(0xF4));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -253,9 +252,7 @@ class binary_writer
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
// step 2: write the string
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()),
|
||||
j.m_data.m_value.string->size());
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()), j.m_data.m_value.string->size());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -354,9 +351,7 @@ class binary_writer
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
// step 2: write each element
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()),
|
||||
N);
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()), N);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -422,9 +417,7 @@ class binary_writer
|
||||
|
||||
case value_t::boolean: // true and false
|
||||
{
|
||||
oa->write_character(j.m_data.m_value.boolean
|
||||
? to_char_type(0xC3)
|
||||
: to_char_type(0xC2));
|
||||
oa->write_character(j.m_data.m_value.boolean ? to_char_type(0xC3) : to_char_type(0xC2));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -573,9 +566,7 @@ class binary_writer
|
||||
}
|
||||
|
||||
// step 2: write the string
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()),
|
||||
j.m_data.m_value.string->size());
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()), j.m_data.m_value.string->size());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -660,18 +651,16 @@ class binary_writer
|
||||
}
|
||||
else if (N <= (std::numeric_limits<std::uint16_t>::max)())
|
||||
{
|
||||
const std::uint8_t output_type = use_ext
|
||||
? 0xC8 // ext 16
|
||||
: 0xC5; // bin 16
|
||||
const std::uint8_t output_type = use_ext ? 0xC8 // ext 16
|
||||
: 0xC5; // bin 16
|
||||
|
||||
oa->write_character(to_char_type(output_type));
|
||||
write_number(static_cast<std::uint16_t>(N));
|
||||
}
|
||||
else if (N <= (std::numeric_limits<std::uint32_t>::max)())
|
||||
{
|
||||
const std::uint8_t output_type = use_ext
|
||||
? 0xC9 // ext 32
|
||||
: 0xC6; // bin 32
|
||||
const std::uint8_t output_type = use_ext ? 0xC9 // ext 32
|
||||
: 0xC6; // bin 32
|
||||
|
||||
oa->write_character(to_char_type(output_type));
|
||||
write_number(static_cast<std::uint32_t>(N));
|
||||
@@ -684,9 +673,7 @@ class binary_writer
|
||||
}
|
||||
|
||||
// step 2: write the byte string
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()),
|
||||
N);
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()), N);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -752,9 +739,7 @@ class binary_writer
|
||||
{
|
||||
if (add_prefix)
|
||||
{
|
||||
oa->write_character(j.m_data.m_value.boolean
|
||||
? to_char_type('T')
|
||||
: to_char_type('F'));
|
||||
oa->write_character(j.m_data.m_value.boolean ? to_char_type('T') : to_char_type('F'));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -784,9 +769,7 @@ class binary_writer
|
||||
oa->write_character(to_char_type('S'));
|
||||
}
|
||||
write_number_with_ubjson_prefix(j.m_data.m_value.string->size(), true, use_bjdata);
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()),
|
||||
j.m_data.m_value.string->size());
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()), j.m_data.m_value.string->size());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -857,9 +840,7 @@ class binary_writer
|
||||
|
||||
if (use_type)
|
||||
{
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()),
|
||||
j.m_data.m_value.binary->size());
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()), j.m_data.m_value.binary->size());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -880,9 +861,13 @@ class binary_writer
|
||||
|
||||
case value_t::object:
|
||||
{
|
||||
if (use_bjdata && j.m_data.m_value.object->size() == 3 && j.m_data.m_value.object->find("_ArrayType_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find("_ArraySize_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find("_ArrayData_") != j.m_data.m_value.object->end())
|
||||
if (use_bjdata && j.m_data.m_value.object->size() == 3 && j.m_data.m_value.object->find("_ArrayType_") != j.m_data.m_value.object->end() &&
|
||||
j.m_data.m_value.object->find("_ArraySize_") != j.m_data.m_value.object->end() &&
|
||||
j.m_data.m_value.object->find("_ArrayData_") != j.m_data.m_value.object->end())
|
||||
{
|
||||
if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type)) // decode bjdata ndarray in the JData format (https://github.com/NeuroJSON/jdata)
|
||||
if (!write_bjdata_ndarray(*j.m_data.m_value.object,
|
||||
use_count,
|
||||
use_type)) // decode bjdata ndarray in the JData format (https://github.com/NeuroJSON/jdata)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -921,9 +906,7 @@ class binary_writer
|
||||
for (const auto& el : *j.m_data.m_value.object)
|
||||
{
|
||||
write_number_with_ubjson_prefix(el.first.size(), true, use_bjdata);
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(el.first.c_str()),
|
||||
el.first.size());
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(el.first.c_str()), el.first.size());
|
||||
write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
|
||||
}
|
||||
|
||||
@@ -965,20 +948,16 @@ class binary_writer
|
||||
/*!
|
||||
@brief Writes the given @a element_type and @a name to the output adapter
|
||||
*/
|
||||
void write_bson_entry_header(const string_t& name,
|
||||
const std::uint8_t element_type)
|
||||
void write_bson_entry_header(const string_t& name, const std::uint8_t element_type)
|
||||
{
|
||||
oa->write_character(to_char_type(element_type)); // boolean
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(name.c_str()),
|
||||
name.size() + 1u);
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(name.c_str()), name.size() + 1u);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and boolean value @a value
|
||||
*/
|
||||
void write_bson_boolean(const string_t& name,
|
||||
const bool value)
|
||||
void write_bson_boolean(const string_t& name, const bool value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x08);
|
||||
oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
|
||||
@@ -987,8 +966,7 @@ class binary_writer
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and double value @a value
|
||||
*/
|
||||
void write_bson_double(const string_t& name,
|
||||
const double value)
|
||||
void write_bson_double(const string_t& name, const double value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x01);
|
||||
write_number<double>(value, true);
|
||||
@@ -1005,15 +983,12 @@ class binary_writer
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and string value @a value
|
||||
*/
|
||||
void write_bson_string(const string_t& name,
|
||||
const string_t& value)
|
||||
void write_bson_string(const string_t& name, const string_t& value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x02);
|
||||
|
||||
write_number<std::int32_t>(static_cast<std::int32_t>(value.size() + 1ul), true);
|
||||
oa->write_characters(
|
||||
reinterpret_cast<const CharType*>(value.c_str()),
|
||||
value.size() + 1);
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(value.c_str()), value.size() + 1);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1029,16 +1004,14 @@ class binary_writer
|
||||
*/
|
||||
static std::size_t calc_bson_integer_size(const std::int64_t value)
|
||||
{
|
||||
return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
|
||||
? sizeof(std::int32_t)
|
||||
: sizeof(std::int64_t);
|
||||
return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)() ? sizeof(std::int32_t)
|
||||
: sizeof(std::int64_t);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and integer @a value
|
||||
*/
|
||||
void write_bson_integer(const string_t& name,
|
||||
const std::int64_t value)
|
||||
void write_bson_integer(const string_t& name, const std::int64_t value)
|
||||
{
|
||||
if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
|
||||
{
|
||||
@@ -1057,16 +1030,13 @@ class binary_writer
|
||||
*/
|
||||
static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
|
||||
{
|
||||
return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
|
||||
? sizeof(std::int32_t)
|
||||
: sizeof(std::int64_t);
|
||||
return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) ? sizeof(std::int32_t) : sizeof(std::int64_t);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and unsigned @a value
|
||||
*/
|
||||
void write_bson_unsigned(const string_t& name,
|
||||
const BasicJsonType& j)
|
||||
void write_bson_unsigned(const string_t& name, const BasicJsonType& j)
|
||||
{
|
||||
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
|
||||
{
|
||||
@@ -1080,15 +1050,17 @@ class binary_writer
|
||||
}
|
||||
else
|
||||
{
|
||||
JSON_THROW(out_of_range::create(407, concat("integer number ", std::to_string(j.m_data.m_value.number_unsigned), " cannot be represented by BSON as it does not fit int64"), &j));
|
||||
JSON_THROW(out_of_range::create(
|
||||
407,
|
||||
concat("integer number ", std::to_string(j.m_data.m_value.number_unsigned), " cannot be represented by BSON as it does not fit int64"),
|
||||
&j));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and object @a value
|
||||
*/
|
||||
void write_bson_object_entry(const string_t& name,
|
||||
const typename BasicJsonType::object_t& value)
|
||||
void write_bson_object_entry(const string_t& name, const typename BasicJsonType::object_t& value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x03); // object
|
||||
write_bson_object(value);
|
||||
@@ -1101,9 +1073,12 @@ class binary_writer
|
||||
{
|
||||
std::size_t array_index = 0ul;
|
||||
|
||||
const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type& el) {
|
||||
return result + calc_bson_element_size(std::to_string(array_index++), el);
|
||||
});
|
||||
const std::size_t embedded_document_size = std::accumulate(std::begin(value),
|
||||
std::end(value),
|
||||
static_cast<std::size_t>(0),
|
||||
[&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type& el) {
|
||||
return result + calc_bson_element_size(std::to_string(array_index++), el);
|
||||
});
|
||||
|
||||
return sizeof(std::int32_t) + embedded_document_size + 1ul;
|
||||
}
|
||||
@@ -1119,8 +1094,7 @@ class binary_writer
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and array @a value
|
||||
*/
|
||||
void write_bson_array(const string_t& name,
|
||||
const typename BasicJsonType::array_t& value)
|
||||
void write_bson_array(const string_t& name, const typename BasicJsonType::array_t& value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x04); // array
|
||||
write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_array_size(value)), true);
|
||||
@@ -1138,8 +1112,7 @@ class binary_writer
|
||||
/*!
|
||||
@brief Writes a BSON element with key @a name and binary value @a value
|
||||
*/
|
||||
void write_bson_binary(const string_t& name,
|
||||
const binary_t& value)
|
||||
void write_bson_binary(const string_t& name, const binary_t& value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x05);
|
||||
|
||||
@@ -1153,8 +1126,7 @@ class binary_writer
|
||||
@brief Calculates the size necessary to serialize the JSON value @a j with its @a name
|
||||
@return The calculated size for the BSON document entry for @a j with the given @a name.
|
||||
*/
|
||||
static std::size_t calc_bson_element_size(const string_t& name,
|
||||
const BasicJsonType& j)
|
||||
static std::size_t calc_bson_element_size(const string_t& name, const BasicJsonType& j)
|
||||
{
|
||||
const auto header_size = calc_bson_entry_header_size(name, j);
|
||||
switch (j.type())
|
||||
@@ -1201,8 +1173,7 @@ class binary_writer
|
||||
@param name The name to associate with the JSON entity @a j within the
|
||||
current BSON document
|
||||
*/
|
||||
void write_bson_element(const string_t& name,
|
||||
const BasicJsonType& j)
|
||||
void write_bson_element(const string_t& name, const BasicJsonType& j)
|
||||
{
|
||||
switch (j.type())
|
||||
{
|
||||
@@ -1250,9 +1221,10 @@ class binary_writer
|
||||
*/
|
||||
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
|
||||
{
|
||||
const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), [](size_t result, const typename BasicJsonType::object_t::value_type& el) {
|
||||
return result += calc_bson_element_size(el.first, el.second);
|
||||
});
|
||||
const std::size_t document_size =
|
||||
std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), [](size_t result, const typename BasicJsonType::object_t::value_type& el) {
|
||||
return result += calc_bson_element_size(el.first, el.second);
|
||||
});
|
||||
|
||||
return sizeof(std::int32_t) + document_size + 1ul;
|
||||
}
|
||||
@@ -1307,9 +1279,7 @@ class binary_writer
|
||||
|
||||
// UBJSON: write number (floating point)
|
||||
template<typename NumberType, typename std::enable_if<std::is_floating_point<NumberType>::value, int>::type = 0>
|
||||
void write_number_with_ubjson_prefix(const NumberType n,
|
||||
const bool add_prefix,
|
||||
const bool use_bjdata)
|
||||
void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata)
|
||||
{
|
||||
if (add_prefix)
|
||||
{
|
||||
@@ -1320,9 +1290,7 @@ class binary_writer
|
||||
|
||||
// UBJSON: write number (unsigned integer)
|
||||
template<typename NumberType, typename std::enable_if<std::is_unsigned<NumberType>::value, int>::type = 0>
|
||||
void write_number_with_ubjson_prefix(const NumberType n,
|
||||
const bool add_prefix,
|
||||
const bool use_bjdata)
|
||||
void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata)
|
||||
{
|
||||
if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
|
||||
{
|
||||
@@ -1406,9 +1374,7 @@ class binary_writer
|
||||
|
||||
// UBJSON: write number (signed integer)
|
||||
template<typename NumberType, typename std::enable_if<std::is_signed<NumberType>::value && !std::is_floating_point<NumberType>::value, int>::type = 0>
|
||||
void write_number_with_ubjson_prefix(const NumberType n,
|
||||
const bool add_prefix,
|
||||
const bool use_bjdata)
|
||||
void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix, const bool use_bjdata)
|
||||
{
|
||||
if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
|
||||
{
|
||||
@@ -1418,7 +1384,8 @@ class binary_writer
|
||||
}
|
||||
write_number(static_cast<std::int8_t>(n), use_bjdata);
|
||||
}
|
||||
else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))
|
||||
else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n &&
|
||||
n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))
|
||||
{
|
||||
if (add_prefix)
|
||||
{
|
||||
@@ -1434,7 +1401,8 @@ class binary_writer
|
||||
}
|
||||
write_number(static_cast<std::int16_t>(n), use_bjdata);
|
||||
}
|
||||
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::max)())))
|
||||
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::min)()) <= n &&
|
||||
n <= static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::max)())))
|
||||
{
|
||||
if (add_prefix)
|
||||
{
|
||||
@@ -1450,7 +1418,8 @@ class binary_writer
|
||||
}
|
||||
write_number(static_cast<std::int32_t>(n), use_bjdata);
|
||||
}
|
||||
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::max)())))
|
||||
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::min)()) <= n &&
|
||||
n <= static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::max)())))
|
||||
{
|
||||
if (add_prefix)
|
||||
{
|
||||
@@ -1499,31 +1468,38 @@ class binary_writer
|
||||
|
||||
case value_t::number_integer:
|
||||
{
|
||||
if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
|
||||
if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
|
||||
{
|
||||
return 'i';
|
||||
}
|
||||
if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
|
||||
if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
|
||||
{
|
||||
return 'U';
|
||||
}
|
||||
if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
|
||||
if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
|
||||
{
|
||||
return 'I';
|
||||
}
|
||||
if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))
|
||||
if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))
|
||||
{
|
||||
return 'u';
|
||||
}
|
||||
if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
|
||||
if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
|
||||
{
|
||||
return 'l';
|
||||
}
|
||||
if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))
|
||||
if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))
|
||||
{
|
||||
return 'm';
|
||||
}
|
||||
if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
|
||||
if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer &&
|
||||
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
|
||||
{
|
||||
return 'L';
|
||||
}
|
||||
@@ -1603,7 +1579,17 @@ class binary_writer
|
||||
*/
|
||||
bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)
|
||||
{
|
||||
std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'}, {"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'}};
|
||||
std::map<string_t, CharType> bjdtype = {{"uint8", 'U'},
|
||||
{"int8", 'i'},
|
||||
{"uint16", 'u'},
|
||||
{"int16", 'I'},
|
||||
{"uint32", 'm'},
|
||||
{"int32", 'l'},
|
||||
{"uint64", 'M'},
|
||||
{"int64", 'L'},
|
||||
{"single", 'd'},
|
||||
{"double", 'D'},
|
||||
{"char", 'C'}};
|
||||
|
||||
string_t key = "_ArrayType_";
|
||||
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
||||
@@ -1752,16 +1738,13 @@ class binary_writer
|
||||
static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
|
||||
static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
|
||||
{
|
||||
oa->write_character(format == detail::input_format_t::cbor
|
||||
? get_cbor_float_prefix(static_cast<float>(n))
|
||||
: get_msgpack_float_prefix(static_cast<float>(n)));
|
||||
oa->write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(static_cast<float>(n))
|
||||
: get_msgpack_float_prefix(static_cast<float>(n)));
|
||||
write_number(static_cast<float>(n));
|
||||
}
|
||||
else
|
||||
{
|
||||
oa->write_character(format == detail::input_format_t::cbor
|
||||
? get_cbor_float_prefix(n)
|
||||
: get_msgpack_float_prefix(n));
|
||||
oa->write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(n) : get_msgpack_float_prefix(n));
|
||||
write_number(n);
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
@@ -1774,15 +1757,13 @@ class binary_writer
|
||||
// between uint8_t and CharType. In case CharType is not unsigned,
|
||||
// such a conversion is required to allow values greater than 128.
|
||||
// See <https://github.com/nlohmann/json/issues/1286> for a discussion.
|
||||
template<typename C = CharType,
|
||||
enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value>* = nullptr>
|
||||
template<typename C = CharType, enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value>* = nullptr>
|
||||
static constexpr CharType to_char_type(std::uint8_t x) noexcept
|
||||
{
|
||||
return *reinterpret_cast<char*>(&x);
|
||||
}
|
||||
|
||||
template<typename C = CharType,
|
||||
enable_if_t<std::is_signed<C>::value && std::is_unsigned<char>::value>* = nullptr>
|
||||
template<typename C = CharType, enable_if_t<std::is_signed<C>::value && std::is_unsigned<char>::value>* = nullptr>
|
||||
static CharType to_char_type(std::uint8_t x) noexcept
|
||||
{
|
||||
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
|
||||
@@ -1792,14 +1773,16 @@ class binary_writer
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename C = CharType,
|
||||
enable_if_t<std::is_unsigned<C>::value>* = nullptr>
|
||||
template<typename C = CharType, enable_if_t<std::is_unsigned<C>::value>* = nullptr>
|
||||
static constexpr CharType to_char_type(std::uint8_t x) noexcept
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template<typename InputCharType, typename C = CharType, enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value && std::is_same<char, typename std::remove_cv<InputCharType>::type>::value>* = nullptr>
|
||||
template<typename InputCharType,
|
||||
typename C = CharType,
|
||||
enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value && std::is_same<char, typename std::remove_cv<InputCharType>::type>::value>* =
|
||||
nullptr>
|
||||
static constexpr CharType to_char_type(InputCharType x) noexcept
|
||||
{
|
||||
return x;
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include <nlohmann/detail/macro_scope.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/// abstract output adapter interface
|
||||
template<typename CharType>
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
///////////////////
|
||||
// serialization //
|
||||
@@ -102,11 +103,7 @@ class serializer
|
||||
@param[in] indent_step the indent level
|
||||
@param[in] current_indent the current indent level (only used internally)
|
||||
*/
|
||||
void dump(const BasicJsonType& val,
|
||||
const bool pretty_print,
|
||||
const bool ensure_ascii,
|
||||
const unsigned int indent_step,
|
||||
const unsigned int current_indent = 0)
|
||||
void dump(const BasicJsonType& val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent = 0)
|
||||
{
|
||||
switch (val.m_data.m_type)
|
||||
{
|
||||
@@ -203,9 +200,7 @@ class serializer
|
||||
}
|
||||
|
||||
// first n-1 elements
|
||||
for (auto i = val.m_data.m_value.array->cbegin();
|
||||
i != val.m_data.m_value.array->cend() - 1;
|
||||
++i)
|
||||
for (auto i = val.m_data.m_value.array->cbegin(); i != val.m_data.m_value.array->cend() - 1; ++i)
|
||||
{
|
||||
o->write_characters(indent_string.c_str(), new_indent);
|
||||
dump(*i, true, ensure_ascii, indent_step, new_indent);
|
||||
@@ -226,9 +221,7 @@ class serializer
|
||||
o->write_character('[');
|
||||
|
||||
// first n-1 elements
|
||||
for (auto i = val.m_data.m_value.array->cbegin();
|
||||
i != val.m_data.m_value.array->cend() - 1;
|
||||
++i)
|
||||
for (auto i = val.m_data.m_value.array->cbegin(); i != val.m_data.m_value.array->cend() - 1; ++i)
|
||||
{
|
||||
dump(*i, false, ensure_ascii, indent_step, current_indent);
|
||||
o->write_character(',');
|
||||
@@ -271,9 +264,7 @@ class serializer
|
||||
|
||||
if (!val.m_data.m_value.binary->empty())
|
||||
{
|
||||
for (auto i = val.m_data.m_value.binary->cbegin();
|
||||
i != val.m_data.m_value.binary->cend() - 1;
|
||||
++i)
|
||||
for (auto i = val.m_data.m_value.binary->cbegin(); i != val.m_data.m_value.binary->cend() - 1; ++i)
|
||||
{
|
||||
dump_integer(*i);
|
||||
o->write_characters(", ", 2);
|
||||
@@ -303,9 +294,7 @@ class serializer
|
||||
|
||||
if (!val.m_data.m_value.binary->empty())
|
||||
{
|
||||
for (auto i = val.m_data.m_value.binary->cbegin();
|
||||
i != val.m_data.m_value.binary->cend() - 1;
|
||||
++i)
|
||||
for (auto i = val.m_data.m_value.binary->cbegin(); i != val.m_data.m_value.binary->cend() - 1; ++i)
|
||||
{
|
||||
dump_integer(*i);
|
||||
o->write_character(',');
|
||||
@@ -475,7 +464,11 @@ class serializer
|
||||
else
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))));
|
||||
static_cast<void>((std::snprintf)(string_buffer.data() + bytes,
|
||||
13,
|
||||
"\\u%04x\\u%04x",
|
||||
static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
|
||||
static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))));
|
||||
bytes += 12;
|
||||
}
|
||||
}
|
||||
@@ -510,7 +503,8 @@ class serializer
|
||||
{
|
||||
case error_handler_t::strict:
|
||||
{
|
||||
JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr));
|
||||
JSON_THROW(
|
||||
type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr));
|
||||
}
|
||||
|
||||
case error_handler_t::ignore:
|
||||
@@ -602,7 +596,8 @@ class serializer
|
||||
{
|
||||
case error_handler_t::strict:
|
||||
{
|
||||
JSON_THROW(type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", hex_bytes(static_cast<std::uint8_t>(s.back() | 0))), nullptr));
|
||||
JSON_THROW(
|
||||
type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", hex_bytes(static_cast<std::uint8_t>(s.back() | 0))), nullptr));
|
||||
}
|
||||
|
||||
case error_handler_t::ignore:
|
||||
@@ -705,112 +700,24 @@ class serializer
|
||||
@param[in] x integer number (signed or unsigned) to dump
|
||||
@tparam NumberType either @a number_integer_t or @a number_unsigned_t
|
||||
*/
|
||||
template<typename NumberType, detail::enable_if_t<std::is_integral<NumberType>::value || std::is_same<NumberType, number_unsigned_t>::value || std::is_same<NumberType, number_integer_t>::value || std::is_same<NumberType, binary_char_t>::value, int> = 0>
|
||||
template<typename NumberType,
|
||||
detail::enable_if_t<std::is_integral<NumberType>::value || std::is_same<NumberType, number_unsigned_t>::value ||
|
||||
std::is_same<NumberType, number_integer_t>::value || std::is_same<NumberType, binary_char_t>::value,
|
||||
int> = 0>
|
||||
void dump_integer(NumberType x)
|
||||
{
|
||||
static constexpr std::array<std::array<char, 2>, 100> digits_to_99{
|
||||
{
|
||||
{{'0', '0'}},
|
||||
{{'0', '1'}},
|
||||
{{'0', '2'}},
|
||||
{{'0', '3'}},
|
||||
{{'0', '4'}},
|
||||
{{'0', '5'}},
|
||||
{{'0', '6'}},
|
||||
{{'0', '7'}},
|
||||
{{'0', '8'}},
|
||||
{{'0', '9'}},
|
||||
{{'1', '0'}},
|
||||
{{'1', '1'}},
|
||||
{{'1', '2'}},
|
||||
{{'1', '3'}},
|
||||
{{'1', '4'}},
|
||||
{{'1', '5'}},
|
||||
{{'1', '6'}},
|
||||
{{'1', '7'}},
|
||||
{{'1', '8'}},
|
||||
{{'1', '9'}},
|
||||
{{'2', '0'}},
|
||||
{{'2', '1'}},
|
||||
{{'2', '2'}},
|
||||
{{'2', '3'}},
|
||||
{{'2', '4'}},
|
||||
{{'2', '5'}},
|
||||
{{'2', '6'}},
|
||||
{{'2', '7'}},
|
||||
{{'2', '8'}},
|
||||
{{'2', '9'}},
|
||||
{{'3', '0'}},
|
||||
{{'3', '1'}},
|
||||
{{'3', '2'}},
|
||||
{{'3', '3'}},
|
||||
{{'3', '4'}},
|
||||
{{'3', '5'}},
|
||||
{{'3', '6'}},
|
||||
{{'3', '7'}},
|
||||
{{'3', '8'}},
|
||||
{{'3', '9'}},
|
||||
{{'4', '0'}},
|
||||
{{'4', '1'}},
|
||||
{{'4', '2'}},
|
||||
{{'4', '3'}},
|
||||
{{'4', '4'}},
|
||||
{{'4', '5'}},
|
||||
{{'4', '6'}},
|
||||
{{'4', '7'}},
|
||||
{{'4', '8'}},
|
||||
{{'4', '9'}},
|
||||
{{'5', '0'}},
|
||||
{{'5', '1'}},
|
||||
{{'5', '2'}},
|
||||
{{'5', '3'}},
|
||||
{{'5', '4'}},
|
||||
{{'5', '5'}},
|
||||
{{'5', '6'}},
|
||||
{{'5', '7'}},
|
||||
{{'5', '8'}},
|
||||
{{'5', '9'}},
|
||||
{{'6', '0'}},
|
||||
{{'6', '1'}},
|
||||
{{'6', '2'}},
|
||||
{{'6', '3'}},
|
||||
{{'6', '4'}},
|
||||
{{'6', '5'}},
|
||||
{{'6', '6'}},
|
||||
{{'6', '7'}},
|
||||
{{'6', '8'}},
|
||||
{{'6', '9'}},
|
||||
{{'7', '0'}},
|
||||
{{'7', '1'}},
|
||||
{{'7', '2'}},
|
||||
{{'7', '3'}},
|
||||
{{'7', '4'}},
|
||||
{{'7', '5'}},
|
||||
{{'7', '6'}},
|
||||
{{'7', '7'}},
|
||||
{{'7', '8'}},
|
||||
{{'7', '9'}},
|
||||
{{'8', '0'}},
|
||||
{{'8', '1'}},
|
||||
{{'8', '2'}},
|
||||
{{'8', '3'}},
|
||||
{{'8', '4'}},
|
||||
{{'8', '5'}},
|
||||
{{'8', '6'}},
|
||||
{{'8', '7'}},
|
||||
{{'8', '8'}},
|
||||
{{'8', '9'}},
|
||||
{{'9', '0'}},
|
||||
{{'9', '1'}},
|
||||
{{'9', '2'}},
|
||||
{{'9', '3'}},
|
||||
{{'9', '4'}},
|
||||
{{'9', '5'}},
|
||||
{{'9', '6'}},
|
||||
{{'9', '7'}},
|
||||
{{'9', '8'}},
|
||||
{{'9', '9'}},
|
||||
}};
|
||||
static constexpr std::array<std::array<char, 2>, 100> digits_to_99{{
|
||||
{{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
|
||||
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
|
||||
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
|
||||
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
|
||||
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
|
||||
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
|
||||
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
|
||||
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
|
||||
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
|
||||
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
|
||||
}};
|
||||
|
||||
// special case for "0"
|
||||
if (x == 0)
|
||||
@@ -893,8 +800,10 @@ class serializer
|
||||
// guaranteed to round-trip, using strtof and strtod, resp.
|
||||
//
|
||||
// NB: The test below works if <long double> == <double>.
|
||||
static constexpr bool is_ieee_single_or_double = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
|
||||
(std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
|
||||
static constexpr bool is_ieee_single_or_double = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 &&
|
||||
std::numeric_limits<number_float_t>::max_exponent == 128) ||
|
||||
(std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 &&
|
||||
std::numeric_limits<number_float_t>::max_exponent == 1024);
|
||||
|
||||
dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
|
||||
}
|
||||
@@ -945,10 +854,9 @@ class serializer
|
||||
o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
|
||||
|
||||
// determine if we need to append ".0"
|
||||
const bool value_is_int_like =
|
||||
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) {
|
||||
return c == '.' || c == 'e';
|
||||
});
|
||||
const bool value_is_int_like = std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) {
|
||||
return c == '.' || c == 'e';
|
||||
});
|
||||
|
||||
if (value_is_int_like)
|
||||
{
|
||||
@@ -979,417 +887,41 @@ class serializer
|
||||
*/
|
||||
static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
|
||||
{
|
||||
static const std::array<std::uint8_t, 400> utf8d =
|
||||
{
|
||||
{
|
||||
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, // 00..1F
|
||||
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, // 20..3F
|
||||
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, // 40..5F
|
||||
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, // 60..7F
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9,
|
||||
9, // 80..9F
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7,
|
||||
7, // A0..BF
|
||||
8,
|
||||
8,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2, // C0..DF
|
||||
0xA,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x3,
|
||||
0x4,
|
||||
0x3,
|
||||
0x3, // E0..EF
|
||||
0xB,
|
||||
0x6,
|
||||
0x6,
|
||||
0x6,
|
||||
0x5,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8,
|
||||
0x8, // F0..FF
|
||||
0x0,
|
||||
0x1,
|
||||
0x2,
|
||||
0x3,
|
||||
0x5,
|
||||
0x8,
|
||||
0x7,
|
||||
0x1,
|
||||
0x1,
|
||||
0x1,
|
||||
0x4,
|
||||
0x6,
|
||||
0x1,
|
||||
0x1,
|
||||
0x1,
|
||||
0x1, // s0..s0
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // s1..s2
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // s3..s4
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1, // s5..s6
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1 // s7..s8
|
||||
}};
|
||||
static const std::array<std::uint8_t, 400> utf8d = {{
|
||||
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, // 00..1F
|
||||
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, // 20..3F
|
||||
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, // 40..5F
|
||||
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, // 60..7F
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, // 80..9F
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, // A0..BF
|
||||
8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, // C0..DF
|
||||
0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3,
|
||||
0x3, // E0..EF
|
||||
0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
|
||||
0x8, // F0..FF
|
||||
0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1,
|
||||
0x1, // s0..s0
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
|
||||
1, // s1..s2
|
||||
1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, // s3..s4
|
||||
1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1,
|
||||
1, // s5..s6
|
||||
1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1 // s7..s8
|
||||
}};
|
||||
|
||||
JSON_ASSERT(byte < utf8d.size());
|
||||
const std::uint8_t type = utf8d[byte];
|
||||
|
||||
codep = (state != UTF8_ACCEPT)
|
||||
? (byte & 0x3fu) | (codep << 6u)
|
||||
: (0xFFu >> type) & (byte);
|
||||
codep = (state != UTF8_ACCEPT) ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte);
|
||||
|
||||
const std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);
|
||||
JSON_ASSERT(index < utf8d.size());
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
#include <nlohmann/detail/meta/detected.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline std::size_t concat_length()
|
||||
{
|
||||
@@ -76,13 +77,26 @@ using string_can_append_data = decltype(std::declval<StringType&>().append(std::
|
||||
template<typename StringType, typename Arg>
|
||||
using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int> = 0>
|
||||
template<typename OutStringType,
|
||||
typename Arg,
|
||||
typename... Args,
|
||||
enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int> = 0>
|
||||
inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest);
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && detect_string_can_append_iter<OutStringType, Arg>::value, int> = 0>
|
||||
template<typename OutStringType,
|
||||
typename Arg,
|
||||
typename... Args,
|
||||
enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value &&
|
||||
detect_string_can_append_iter<OutStringType, Arg>::value,
|
||||
int> = 0>
|
||||
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest);
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && !detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value, int> = 0>
|
||||
template<typename OutStringType,
|
||||
typename Arg,
|
||||
typename... Args,
|
||||
enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value &&
|
||||
!detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value,
|
||||
int> = 0>
|
||||
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest);
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0>
|
||||
@@ -92,21 +106,34 @@ inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest)
|
||||
concat_into(out, std::forward<Args>(rest)...);
|
||||
}
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int>>
|
||||
template<typename OutStringType,
|
||||
typename Arg,
|
||||
typename... Args,
|
||||
enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && detect_string_can_append_op<OutStringType, Arg>::value, int>>
|
||||
inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest)
|
||||
{
|
||||
out += std::forward<Arg>(arg);
|
||||
concat_into(out, std::forward<Args>(rest)...);
|
||||
}
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && detect_string_can_append_iter<OutStringType, Arg>::value, int>>
|
||||
template<typename OutStringType,
|
||||
typename Arg,
|
||||
typename... Args,
|
||||
enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value &&
|
||||
detect_string_can_append_iter<OutStringType, Arg>::value,
|
||||
int>>
|
||||
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest)
|
||||
{
|
||||
out.append(arg.begin(), arg.end());
|
||||
concat_into(out, std::forward<Args>(rest)...);
|
||||
}
|
||||
|
||||
template<typename OutStringType, typename Arg, typename... Args, enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value && !detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value, int>>
|
||||
template<typename OutStringType,
|
||||
typename Arg,
|
||||
typename... Args,
|
||||
enable_if_t<!detect_string_can_append<OutStringType, Arg>::value && !detect_string_can_append_op<OutStringType, Arg>::value &&
|
||||
!detect_string_can_append_iter<OutStringType, Arg>::value && detect_string_can_append_data<OutStringType, Arg>::value,
|
||||
int>>
|
||||
inline void concat_into(OutStringType& out, const Arg& arg, Args&&... rest)
|
||||
{
|
||||
out.append(arg.data(), arg.size());
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*!
|
||||
@brief replace all occurrences of a substring by another string
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#endif
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
///////////////////////////
|
||||
// JSON type enumeration //
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,8 +36,7 @@ struct adl_serializer;
|
||||
|
||||
/// a class to store JSON values
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/
|
||||
template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||
std::map,
|
||||
template<template<typename U, typename V, typename... Args> class ObjectType = std::map,
|
||||
template<typename U, typename... Args> class ArrayType = std::vector,
|
||||
class StringType = std::string,
|
||||
class BooleanType = bool,
|
||||
@@ -45,8 +44,7 @@ template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||
class NumberUnsignedType = std::uint64_t,
|
||||
class NumberFloatType = double,
|
||||
template<typename U> class AllocatorType = std::allocator,
|
||||
template<typename T, typename SFINAE = void> class JSONSerializer =
|
||||
adl_serializer,
|
||||
template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer,
|
||||
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
||||
class CustomBaseClass = void>
|
||||
class basic_json;
|
||||
|
||||
@@ -337,8 +337,8 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
||||
}
|
||||
|
||||
template<typename InputIt>
|
||||
using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
|
||||
std::input_iterator_tag>::value>::type;
|
||||
using require_input_iter =
|
||||
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category, std::input_iterator_tag>::value>::type;
|
||||
|
||||
template<typename InputIt, typename = require_input_iter<InputIt>>
|
||||
void insert(InputIt first, InputIt last)
|
||||
|
||||
749
include/nlohmann/thirdparty/hedley/hedley.hpp
vendored
749
include/nlohmann/thirdparty/hedley/hedley.hpp
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user