29 #ifndef NLOHMANN_JSON_HPP 30 #define NLOHMANN_JSON_HPP 42 #include <forward_list> 44 #include <initializer_list> 55 #include <type_traits> 60 #if defined(__clang__) 61 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 62 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" 64 #elif defined(__GNUC__) 65 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900 66 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" 71 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 72 #pragma GCC diagnostic push 73 #pragma GCC diagnostic ignored "-Wfloat-equal" 77 #if defined(__clang__) 78 #pragma GCC diagnostic push 79 #pragma GCC diagnostic ignored "-Wdocumentation" 83 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 84 #define JSON_DEPRECATED __attribute__((deprecated)) 85 #elif defined(_MSC_VER) 86 #define JSON_DEPRECATED __declspec(deprecated) 88 #define JSON_DEPRECATED 92 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION) 93 #define JSON_THROW(exception) throw exception 95 #define JSON_CATCH(exception) catch(exception) 97 #define JSON_THROW(exception) std::abort() 98 #define JSON_TRY if(true) 99 #define JSON_CATCH(exception) if(false) 103 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 104 #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) 105 #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) 107 #define JSON_LIKELY(x) x 108 #define JSON_UNLIKELY(x) x 149 virtual const char*
what() const noexcept
override 159 :
id(id_),
m(what_arg)
164 return "[json.exception." + ename +
"." +
std::to_string(
id) +
"] ";
169 std::runtime_error
m;
433 static constexpr std::array<uint8_t, 8> order = {{
451 return order[
static_cast<std::size_t
>(lhs)] <
452 order[static_cast<std::size_t>(rhs)];
461 template<
bool B,
typename T =
void>
482 template<
class B1,
class... Bn>
483 struct conjunction<B1, Bn...> : std::conditional<bool(B1::value), conjunction<Bn...>, B1>
::type {};
485 template<
class B>
struct negation : std::integral_constant < bool, !B::value > {};
501 template<
typename BasicJsonType>
502 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t
b) noexcept
506 j.assert_invariant();
513 template<
typename BasicJsonType>
514 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t&
s)
518 j.assert_invariant();
525 template<
typename BasicJsonType>
526 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val) noexcept
530 j.assert_invariant();
537 template<
typename BasicJsonType>
538 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val) noexcept
542 j.assert_invariant();
549 template<
typename BasicJsonType>
550 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val) noexcept
554 j.assert_invariant();
561 template<
typename BasicJsonType>
562 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
566 j.assert_invariant();
569 template<
typename BasicJsonType,
typename CompatibleArrayType,
571 typename BasicJsonType::array_t>::value,
573 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
578 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
579 j.assert_invariant();
582 template<
typename BasicJsonType>
583 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
587 j.m_value.array->reserve(arr.size());
590 j.m_value.array->push_back(x);
592 j.assert_invariant();
599 template<
typename BasicJsonType>
600 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
604 j.assert_invariant();
607 template<
typename BasicJsonType,
typename CompatibleObjectType,
609 typename BasicJsonType::object_t>::value,
611 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
617 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
618 j.assert_invariant();
637 #define NLOHMANN_JSON_HAS_HELPER(type) \ 638 template<typename T> struct has_##type { \ 640 template<typename U, typename = typename U::type> \ 641 static int detect(U &&); \ 642 static void detect(...); \ 644 static constexpr bool value = \ 645 std::is_integral<decltype(detect(std::declval<T>()))>::value; \ 653 #undef NLOHMANN_JSON_HAS_HELPER 656 template<
bool B,
class RealType,
class CompatibleObjectType>
659 template<
class RealType,
class CompatibleObjectType>
662 static constexpr
auto value =
663 std::is_constructible<
typename RealType::key_type,
664 typename CompatibleObjectType::key_type>::value and
665 std::is_constructible<
typename RealType::mapped_type,
666 typename CompatibleObjectType::mapped_type>::value;
669 template<
class BasicJsonType,
class CompatibleObjectType>
674 has_mapped_type<CompatibleObjectType>,
675 has_key_type<CompatibleObjectType>>
::value,
676 typename BasicJsonType::object_t, CompatibleObjectType >
::value;
679 template<
typename BasicJsonType,
typename T>
682 static auto constexpr
value = std::is_same<T, typename BasicJsonType::iterator>::value or
683 std::is_same<T, typename BasicJsonType::const_iterator>::value or
684 std::is_same<T, typename BasicJsonType::reverse_iterator>::value or
685 std::is_same<T, typename BasicJsonType::const_reverse_iterator>::value or
686 std::is_same<T, typename BasicJsonType::json_pointer>::value;
689 template<
class BasicJsonType,
class CompatibleArrayType>
695 BasicJsonType, CompatibleArrayType>>,
696 negation<std::is_constructible<
typename BasicJsonType::string_t,
697 CompatibleArrayType>>,
699 has_value_type<CompatibleArrayType>,
700 has_iterator<CompatibleArrayType>>
::value;
703 template<
bool,
typename,
typename>
706 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
713 static constexpr
auto value =
714 std::is_constructible<RealIntegerType,
715 CompatibleNumberIntegerType>::value and
716 CompatibleLimits::is_integer and
717 RealLimits::is_signed == CompatibleLimits::is_signed;
720 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
725 std::is_integral<CompatibleNumberIntegerType>::value and
726 not std::is_same<bool, CompatibleNumberIntegerType>::value,
727 RealIntegerType, CompatibleNumberIntegerType >
::value;
732 template<
typename BasicJsonType,
typename T>
738 std::declval<BasicJsonType>(), std::declval<T&>()))>
::value>>
743 static constexpr
bool value = std::is_integral<decltype(
744 detect(std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>
::value;
749 template<
typename BasicJsonType,
typename T>
762 std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>
::value;
766 template<
typename BasicJsonType,
typename T>
771 std::declval<BasicJsonType&>(), std::declval<T>()))>
777 std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>
::value;
785 template<
typename BasicJsonType,
typename T,
enable_if_t<
786 std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
792 template<
typename BasicJsonType,
typename CompatibleString,
793 enable_if_t<std::is_constructible<
typename BasicJsonType::string_t,
794 CompatibleString>::value,
int> = 0>
795 void to_json(BasicJsonType& j,
const CompatibleString&
s)
800 template<
typename BasicJsonType,
typename FloatType,
801 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
802 void to_json(BasicJsonType& j, FloatType val) noexcept
808 typename BasicJsonType,
typename CompatibleNumberUnsignedType,
809 enable_if_t<is_compatible_integer_type<
typename BasicJsonType::number_unsigned_t,
810 CompatibleNumberUnsignedType>::value,
int> = 0 >
811 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
817 typename BasicJsonType,
typename CompatibleNumberIntegerType,
818 enable_if_t<is_compatible_integer_type<
typename BasicJsonType::number_integer_t,
819 CompatibleNumberIntegerType>::value,
int> = 0 >
820 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
825 template<
typename BasicJsonType,
typename EnumType,
826 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
827 void to_json(BasicJsonType& j, EnumType e) noexcept
833 template<
typename BasicJsonType>
834 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
840 typename BasicJsonType,
typename CompatibleArrayType,
843 std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value,
845 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
851 typename BasicJsonType,
typename CompatibleObjectType,
852 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value,
854 void to_json(BasicJsonType& j,
const CompatibleObjectType& arr)
859 template <
typename BasicJsonType,
typename T, std::size_t N,
861 typename BasicJsonType::string_t,
T (&)[N]>::value,
873 template<
typename BasicJsonType,
typename ArithmeticType,
874 enable_if_t<std::is_arithmetic<ArithmeticType>::value and
875 not std::is_same<ArithmeticType,
876 typename BasicJsonType::boolean_t>::value,
880 switch (static_cast<value_t>(j))
884 val =
static_cast<ArithmeticType
>(
885 *j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
890 val =
static_cast<ArithmeticType
>(
891 *j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
896 val =
static_cast<ArithmeticType
>(
897 *j.template get_ptr<const typename BasicJsonType::number_float_t*>());
907 template<
typename BasicJsonType>
908 void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t&
b)
910 if (not j.is_boolean())
914 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
917 template<
typename BasicJsonType>
918 void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t&
s)
920 if (not j.is_string())
924 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
927 template<
typename BasicJsonType>
928 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
933 template<
typename BasicJsonType>
934 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
939 template<
typename BasicJsonType>
940 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
945 template<
typename BasicJsonType,
typename EnumType,
946 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
951 e =
static_cast<EnumType
>(val);
954 template<
typename BasicJsonType>
955 void from_json(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr)
957 if (not j.is_array())
961 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
965 template<
typename BasicJsonType,
typename T,
typename Allocator,
966 enable_if_t<std::is_convertible<BasicJsonType, T>::value,
int> = 0>
967 void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>&
l)
969 if (not j.is_array())
974 for (
auto it = j.rbegin(), end = j.rend(); it != end; ++it)
976 l.push_front(it->template get<T>());
980 template<
typename BasicJsonType,
typename CompatibleArrayType>
986 std::transform(j.begin(), j.end(),
987 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
991 return i.template get<typename CompatibleArrayType::value_type>();
995 template<
typename BasicJsonType,
typename CompatibleArrayType>
998 arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
1004 arr.reserve(j.size());
1005 std::transform(j.begin(), j.end(),
1006 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
1010 return i.template get<typename CompatibleArrayType::value_type>();
1014 template<
typename BasicJsonType,
typename CompatibleArrayType,
1015 enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value and
1016 std::is_convertible<BasicJsonType, typename CompatibleArrayType::value_type>::value and
1017 not std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value,
int> = 0>
1018 void from_json(
const BasicJsonType& j, CompatibleArrayType& arr)
1020 if (not j.is_array())
1028 template<
typename BasicJsonType,
typename CompatibleObjectType,
1029 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value,
int> = 0>
1030 void from_json(
const BasicJsonType& j, CompatibleObjectType& obj)
1032 if (not j.is_object())
1037 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
1043 obj = CompatibleObjectType(begin(*inner_object), end(*inner_object));
1050 template<
typename BasicJsonType,
typename ArithmeticType,
1052 std::is_arithmetic<ArithmeticType>::value and
1053 not std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value and
1054 not std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value and
1055 not std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value and
1056 not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
1060 switch (static_cast<value_t>(j))
1064 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
1069 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
1074 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
1079 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
1092 template<
typename BasicJsonType,
typename T>
1094 -> decltype(
to_json(j, std::forward<T>(val)),
void())
1096 return to_json(j, std::forward<T>(val));
1099 template<
typename BasicJsonType,
typename T>
1102 static_assert(
sizeof(BasicJsonType) == 0,
1103 "could not find to_json() method in T's namespace");
1107 template<
typename BasicJsonType,
typename T>
1109 noexcept(noexcept(std::declval<to_json_fn>().
call(j, std::forward<T>(val),
priority_tag<1> {})))
1118 template<
typename BasicJsonType,
typename T>
1126 template<
typename BasicJsonType,
typename T>
1129 static_assert(
sizeof(BasicJsonType) == 0,
1130 "could not find from_json() method in T's namespace");
1134 template<
typename BasicJsonType,
typename T>
1143 template<
typename T>
1149 template<
typename T>
1169 template<
typename =
void,
typename =
void>
1181 template<
typename BasicJsonType,
typename ValueType>
1182 static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
1197 template<
typename BasicJsonType,
typename ValueType>
1198 static void to_json(BasicJsonType& j, ValueType&& val) noexcept(
1288 template<
typename U,
typename V,
typename... Args>
class ObjectType =
std::map,
1289 template<
typename U,
typename... Args>
class ArrayType = std::vector,
1290 class StringType = std::string,
1291 class BooleanType =
bool,
1292 class NumberIntegerType = std::int64_t,
1293 class NumberUnsignedType = std::uint64_t,
1294 class NumberFloatType = double,
1295 template<
typename U>
class AllocatorType = std::allocator,
1296 template<
typename T,
typename SFINAE =
void>
class JSONSerializer = adl_serializer
1304 BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
1305 AllocatorType, JSONSerializer>;
1313 template<
typename T,
typename SFINAE>
1367 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
1369 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
1418 result[
"copyright"] =
"(C) 2013-2017 Niels Lohmann";
1419 result[
"name"] =
"JSON for Modern C++";
1420 result[
"url"] =
"https://github.com/nlohmann/json";
1423 {
"string",
"2.1.1"}, {
"major", 2}, {
"minor", 1}, {
"patch", 1}
1427 result[
"platform"] =
"win32";
1428 #elif defined __linux__ 1429 result[
"platform"] =
"linux";
1430 #elif defined __APPLE__ 1431 result[
"platform"] =
"apple";
1432 #elif defined __unix__ 1433 result[
"platform"] =
"unix";
1435 result[
"platform"] =
"unknown";
1438 #if defined(__clang__) 1439 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
1440 #elif defined(__ICC) || defined(__INTEL_COMPILER) 1441 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
1442 #elif defined(__GNUC__) || defined(__GNUG__) 1444 #elif defined(__HP_cc) || defined(__HP_aCC) 1445 result[
"compiler"] =
"hp" 1446 #elif defined(__IBMCPP__) 1447 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
1448 #elif defined(_MSC_VER) 1449 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
1450 #elif defined(__PGI) 1451 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
1452 #elif defined(__SUNPRO_CC) 1453 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
1455 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
1461 result[
"compiler"][
"c++"] =
"unknown";
1559 using object_t = ObjectType<StringType,
1561 std::less<StringType>,
1562 AllocatorType<std::pair<
const StringType,
1609 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
1906 template<
typename T,
typename... Args>
1909 AllocatorType<T> alloc;
1910 auto deleter = [&](
T *
object)
1912 alloc.deallocate(
object, 1);
1914 std::unique_ptr<T, decltype(deleter)>
object(alloc.allocate(1), deleter);
1915 alloc.construct(
object.
get(), std::forward<Args>(args)...);
1916 assert(
object !=
nullptr);
1917 return object.release();
1982 object = create<object_t>();
1988 array = create<array_t>();
1994 string = create<string_t>(
"");
2041 string = create<string_t>(
value);
2047 object = create<object_t>(
value);
2277 template<
typename CompatibleType,
typename U = detail::uncvref_t<CompatibleType>,
2278 detail::enable_if_t<not std::is_base_of<std::istream, U>::value and
2279 not std::is_same<U, basic_json_t>::value and
2280 not detail::is_basic_json_nested_type<
2281 basic_json_t, U>::value and
2282 detail::has_to_json<basic_json, U>::value,
2285 std::declval<basic_json_t&>(), std::forward<CompatibleType>(val))))
2363 bool type_deduction =
true,
2368 bool is_an_object = std::all_of(init.begin(), init.end(),
2371 return element.is_array() and element.size() == 2 and element[0].is_string();
2375 if (not type_deduction)
2380 is_an_object =
false;
2396 std::for_each(init.begin(), init.end(), [
this](
const basic_json & element)
2446 std::initializer_list<basic_json>())
2487 std::initializer_list<basic_json>())
2559 template<
class InputIT,
typename std::enable_if<
2560 std::is_same<InputIT, typename basic_json_t::iterator>::value or
2561 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int>
::type = 0>
2564 assert(first.m_object !=
nullptr);
2565 assert(last.m_object !=
nullptr);
2568 if (first.m_object != last.m_object)
2574 m_type = first.m_object->m_type;
2585 if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
2632 m_value.
object = create<object_t>(first.m_it.object_iterator,
2633 last.m_it.object_iterator);
2639 m_value.
array = create<array_t>(first.m_it.array_iterator,
2640 last.m_it.array_iterator);
2647 first.m_object->type_name()));
2757 :
m_type(std::move(other.m_type)),
2758 m_value(std::move(other.m_value))
2761 other.assert_invariant();
2764 other.m_type = value_t::null;
2794 std::is_nothrow_move_constructible<value_t>::value and
2795 std::is_nothrow_move_assignable<value_t>::value and
2796 std::is_nothrow_move_constructible<json_value>::value and
2797 std::is_nothrow_move_assignable<json_value>::value
2834 AllocatorType<object_t> alloc;
2842 AllocatorType<array_t> alloc;
2850 AllocatorType<string_t> alloc;
2907 s.dump(*
this,
true, static_cast<unsigned int>(indent));
2911 s.dump(*
this,
false, 0);
3016 return m_type == value_t::null;
3246 return m_type == value_t::discarded;
3385 template<
typename ReferenceType,
typename ThisType>
3392 auto ptr = obj.template get_ptr<PointerType>();
3422 typename BasicJsonType,
3471 typename ValueTypeCV,
3474 not std::is_same<basic_json_t, ValueType>::value and
3478 ValueType
get()
const noexcept(noexcept(
3484 static_assert(not std::is_reference<ValueTypeCV>::value,
3485 "get() cannot be used with reference types, you might want to use get_ref()");
3486 static_assert(std::is_default_constructible<ValueType>::value,
3487 "types must be DefaultConstructible when used with get()");
3526 typename ValueTypeCV,
3531 ValueType
get()
const noexcept(noexcept(
3534 static_assert(not std::is_reference<ValueTypeCV>::value,
3535 "get() cannot be used with reference types, you might want to use get_ref()");
3566 template<
typename PointerType,
typename std::enable_if<
3567 std::is_pointer<PointerType>::value,
int>
::type = 0>
3568 PointerType
get() noexcept
3571 return get_ptr<PointerType>();
3578 template<
typename PointerType,
typename std::enable_if<
3579 std::is_pointer<PointerType>::value,
int>
::type = 0>
3580 constexpr
const PointerType
get()
const noexcept
3583 return get_ptr<PointerType>();
3612 template<
typename PointerType,
typename std::enable_if<
3613 std::is_pointer<PointerType>::value,
int>
::type = 0>
3617 using pointee_t =
typename std::remove_const<
typename 3618 std::remove_pointer<
typename 3622 std::is_same<object_t, pointee_t>::value
3623 or std::is_same<array_t, pointee_t>::value
3624 or std::is_same<string_t, pointee_t>::value
3625 or std::is_same<boolean_t, pointee_t>::value
3626 or std::is_same<number_integer_t, pointee_t>::value
3627 or std::is_same<number_unsigned_t, pointee_t>::value
3628 or std::is_same<number_float_t, pointee_t>::value
3629 ,
"incompatible pointer type");
3632 return get_impl_ptr(static_cast<PointerType>(
nullptr));
3639 template<
typename PointerType,
typename std::enable_if<
3640 std::is_pointer<PointerType>::value and
3642 constexpr
const PointerType
get_ptr() const noexcept
3645 using pointee_t =
typename std::remove_const<
typename 3646 std::remove_pointer<
typename 3650 std::is_same<object_t, pointee_t>::value
3651 or std::is_same<array_t, pointee_t>::value
3652 or std::is_same<string_t, pointee_t>::value
3653 or std::is_same<boolean_t, pointee_t>::value
3654 or std::is_same<number_integer_t, pointee_t>::value
3655 or std::is_same<number_unsigned_t, pointee_t>::value
3656 or std::is_same<number_float_t, pointee_t>::value
3657 ,
"incompatible pointer type");
3660 return get_impl_ptr(static_cast<const PointerType>(
nullptr));
3689 template<
typename ReferenceType,
typename std::enable_if<
3690 std::is_reference<ReferenceType>::value,
int>
::type = 0>
3694 return get_ref_impl<ReferenceType>(*this);
3701 template<
typename ReferenceType,
typename std::enable_if<
3702 std::is_reference<ReferenceType>::value and
3707 return get_ref_impl<ReferenceType>(*this);
3739 template <
typename ValueType,
typename std::enable_if <
3740 not std::is_pointer<ValueType>::value and
3741 not std::is_same<ValueType, typename string_t::value_type>::value
3742 #ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015 3743 and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>
::value 3745 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER >1900 && defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 3746 and not std::is_same<ValueType, typename std::string_view>::value
3749 operator ValueType()
const 3752 return get<ValueType>();
4159 template<
typename T, std::
size_t n>
4162 return operator[](static_cast<const T>(key));
4194 template<
typename T, std::
size_t n>
4197 return operator[](static_cast<const T>(key));
4227 template<
typename T>
4277 template<
typename T>
4338 template<
class ValueType,
typename std::enable_if<
4339 std::is_convertible<basic_json_t, ValueType>::value,
int>
::type = 0>
4340 ValueType
value(
const typename object_t::key_type& key, ValueType default_value)
const 4346 const auto it =
find(key);
4352 return default_value;
4364 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const 4410 template<
class ValueType,
typename std::enable_if<
4411 std::is_convertible<basic_json_t, ValueType>::value,
int>
::type = 0>
4424 return default_value;
4572 template<
class IteratorType,
typename std::enable_if<
4573 std::is_same<IteratorType, typename basic_json_t::iterator>::value or
4574 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int>
::type 4579 if (
this != pos.m_object)
4584 IteratorType result =
end();
4594 if (not pos.m_it.primitive_iterator.is_begin())
4601 AllocatorType<string_t> alloc;
4614 result.m_it.object_iterator =
m_value.
object->erase(pos.m_it.object_iterator);
4620 result.m_it.array_iterator =
m_value.
array->erase(pos.m_it.array_iterator);
4679 template<
class IteratorType,
typename std::enable_if<
4680 std::is_same<IteratorType, typename basic_json_t::iterator>::value or
4681 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int>
::type 4683 IteratorType
erase(IteratorType first, IteratorType last)
4686 if (
this != first.m_object or
this != last.m_object)
4691 IteratorType result =
end();
4701 if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
4708 AllocatorType<string_t> alloc;
4721 result.m_it.object_iterator =
m_value.
object->erase(first.m_it.object_iterator,
4722 last.m_it.object_iterator);
4728 result.m_it.array_iterator =
m_value.
array->erase(first.m_it.array_iterator,
4729 last.m_it.array_iterator);
4858 auto result =
end();
4874 auto result =
cend();
5554 val.m_type = value_t::null;
5678 if (
is_object() and init.size() == 2 and init.begin()->is_string())
5680 const string_t key = *init.begin();
5681 push_back(
typename object_t::value_type(key, *(init.begin() + 1)));
5720 template<
class... Args>
5738 m_value.
array->emplace_back(std::forward<Args>(args)...);
5768 template<
class... Args>
5769 std::pair<iterator, bool>
emplace(Args&& ... args)
5786 auto res =
m_value.
object->emplace(std::forward<Args>(args)...);
5789 it.m_it.object_iterator = res.first;
5792 return {it, res.second};
6062 std::is_nothrow_move_constructible<value_t>::value and
6063 std::is_nothrow_move_assignable<value_t>::value and
6064 std::is_nothrow_move_constructible<json_value>::value and
6065 std::is_nothrow_move_assignable<json_value>::value
6211 const auto lhs_type = lhs.type();
6212 const auto rhs_type = rhs.type();
6214 if (lhs_type == rhs_type)
6220 return *lhs.m_value.array == *rhs.m_value.array;
6224 return *lhs.m_value.object == *rhs.m_value.object;
6232 return *lhs.m_value.string == *rhs.m_value.string;
6236 return lhs.m_value.boolean == rhs.m_value.boolean;
6240 return lhs.m_value.number_integer == rhs.m_value.number_integer;
6244 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
6248 return lhs.m_value.number_float == rhs.m_value.number_float;
6258 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
6262 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
6266 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
6270 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
6274 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
6278 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
6288 template<
typename ScalarType,
typename std::enable_if<
6289 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6299 template<
typename ScalarType,
typename std::enable_if<
6300 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6324 return not (lhs == rhs);
6331 template<
typename ScalarType,
typename std::enable_if<
6332 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6342 template<
typename ScalarType,
typename std::enable_if<
6343 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6375 const auto lhs_type = lhs.type();
6376 const auto rhs_type = rhs.type();
6378 if (lhs_type == rhs_type)
6386 return (*lhs.m_value.array) < *rhs.m_value.array;
6391 return *lhs.m_value.object < *rhs.m_value.object;
6399 return *lhs.m_value.string < *rhs.m_value.string;
6403 return lhs.m_value.boolean < rhs.m_value.boolean;
6407 return lhs.m_value.number_integer < rhs.m_value.number_integer;
6411 return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
6415 return lhs.m_value.number_float < rhs.m_value.number_float;
6425 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
6429 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
6433 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
6437 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
6441 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
6445 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
6458 template<
typename ScalarType,
typename std::enable_if<
6459 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6469 template<
typename ScalarType,
typename std::enable_if<
6470 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6495 return not (rhs < lhs);
6502 template<
typename ScalarType,
typename std::enable_if<
6503 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6513 template<
typename ScalarType,
typename std::enable_if<
6514 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6539 return not (lhs <= rhs);
6546 template<
typename ScalarType,
typename std::enable_if<
6547 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6557 template<
typename ScalarType,
typename std::enable_if<
6558 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6583 return not (lhs < rhs);
6590 template<
typename ScalarType,
typename std::enable_if<
6591 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6601 template<
typename ScalarType,
typename std::enable_if<
6602 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6616 template<
typename CharType>
6624 static std::shared_ptr<output_adapter<CharType>>
create(std::vector<CharType>& vec)
6629 static std::shared_ptr<output_adapter<CharType>>
create(std::ostream&
s)
6634 static std::shared_ptr<output_adapter<CharType>>
create(std::string&
s)
6641 template<
typename CharType>
6645 template<
typename CharType>
6664 std::vector<CharType>&
v;
6668 template<
typename CharType>
6683 stream.write(
s, static_cast<std::streamsize>(length));
6691 template<
typename CharType>
6706 str.append(
s, length);
6710 std::basic_string<CharType>&
str;
6761 const bool pretty_print,
6762 const unsigned int indent_step,
6763 const unsigned int current_indent = 0)
6771 o->write_characters(
"{}", 2);
6777 o->write_characters(
"{\n", 2);
6780 const auto new_indent = current_indent + indent_step;
6788 for (
size_t cnt = 0; cnt < val.
m_value.
object->size() - 1; ++cnt, ++i)
6791 o->write_character(
'\"');
6793 o->write_characters(
"\": ", 3);
6794 dump(i->second,
true, indent_step, new_indent);
6795 o->write_characters(
",\n", 2);
6801 o->write_character(
'\"');
6803 o->write_characters(
"\": ", 3);
6804 dump(i->second,
true, indent_step, new_indent);
6806 o->write_character(
'\n');
6808 o->write_character(
'}');
6812 o->write_character(
'{');
6816 for (
size_t cnt = 0; cnt < val.
m_value.
object->size() - 1; ++cnt, ++i)
6818 o->write_character(
'\"');
6820 o->write_characters(
"\":", 2);
6821 dump(i->second,
false, indent_step, current_indent);
6822 o->write_character(
',');
6827 o->write_character(
'\"');
6829 o->write_characters(
"\":", 2);
6830 dump(i->second,
false, indent_step, current_indent);
6832 o->write_character(
'}');
6842 o->write_characters(
"[]", 2);
6848 o->write_characters(
"[\n", 2);
6851 const auto new_indent = current_indent + indent_step;
6861 dump(*i,
true, indent_step, new_indent);
6862 o->write_characters(
",\n", 2);
6870 o->write_character(
'\n');
6872 o->write_character(
']');
6876 o->write_character(
'[');
6881 dump(*i,
false, indent_step, current_indent);
6882 o->write_character(
',');
6889 o->write_character(
']');
6897 o->write_character(
'\"');
6899 o->write_character(
'\"');
6907 o->write_characters(
"true", 4);
6911 o->write_characters(
"false", 5);
6934 case value_t::discarded:
6936 o->write_characters(
"<discarded>", 11);
6942 o->write_characters(
"null", 4);
6959 return std::accumulate(
s.begin(),
s.end(),
size_t{},
6960 [](
size_t res,
typename string_t::value_type c)
7033 o->write_characters(
s.c_str(),
s.size());
7038 string_t result(
s.size() + space,
'\\');
7039 std::size_t pos = 0;
7041 for (
const auto& c :
s)
7048 result[pos + 1] =
'"';
7064 result[pos + 1] =
'b';
7072 result[pos + 1] =
'f';
7080 result[pos + 1] =
'n';
7088 result[pos + 1] =
'r';
7096 result[pos + 1] =
't';
7131 static const char hexify[16] =
7133 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
7134 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' 7139 {
'u',
'0',
'0', hexify[c >> 4], hexify[c & 0x0f]
7158 assert(pos ==
s.size() + space);
7159 o->write_characters(result.c_str(), result.size());
7172 std::is_same<NumberType, number_unsigned_t>::value or
7173 std::is_same<NumberType, number_integer_t>::value,
int> = 0>
7179 o->write_character(
'0');
7189 const auto digit = std::labs(static_cast<long>(x % 10));
7221 o->write_characters(
"null", 4);
7230 o->write_characters(
"-0.0", 4);
7234 o->write_characters(
"0.0", 3);
7240 static constexpr
auto d = std::numeric_limits<number_float_t>::digits10;
7275 o->write_characters(
number_buffer.data(),
static_cast<size_t>(len));
7278 const bool value_is_int_like = std::none_of(
number_buffer.begin(),
7282 return c ==
'.' or c ==
'e';
7285 if (value_is_int_like)
7287 o->write_characters(
".0", 2);
7299 const std::lconv*
loc =
nullptr;
7344 const bool pretty_print = (o.width() > 0);
7345 const auto indentation = (pretty_print ? o.width() : 0);
7352 s.dump(j, pretty_print, static_cast<unsigned int>(indentation));
7411 template<
class T, std::
size_t N>
7450 template<
typename CharT,
typename std::enable_if<
7451 std::is_pointer<CharT>::value and
7549 template<
class IteratorType,
typename std::enable_if<
7551 std::random_access_iterator_tag,
7552 typename std::iterator_traits<IteratorType>::iterator_category>
::value,
int>
::type = 0>
7603 template<
class ContiguousContainer,
typename std::enable_if<
7604 not std::is_pointer<ContiguousContainer>::value and
7606 std::random_access_iterator_tag,
7607 typename std::iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::
value 7613 return parse(std::begin(c), std::end(c), cb);
7698 case value_t::discarded:
7756 return (m_it == begin_value);
7762 return (m_it == end_value);
7767 return lhs.m_it == rhs.m_it;
7772 return !(lhs == rhs);
7777 return lhs.m_it < rhs.m_it;
7782 return lhs.m_it <= rhs.m_it;
7787 return lhs.m_it > rhs.m_it;
7792 return lhs.m_it >= rhs.m_it;
7797 auto result = *
this;
7804 return lhs.m_it - rhs.m_it;
7809 return os << it.
m_it;
7820 auto result = *
this;
7833 auto result = *
this;
7876 : object_iterator(), array_iterator(), primitive_iterator()
7881 template<
typename IteratorType>
7882 class iteration_proxy
7892 size_t array_index = 0;
7917 return anchor != o.
anchor;
7923 assert(anchor.m_object !=
nullptr);
7925 switch (anchor.m_object->type())
7936 return anchor.key();
7948 typename IteratorType::reference
value()
const 7950 return anchor.value();
7996 template<
typename U>
7997 class iter_impl :
public std::iterator<std::random_access_iterator_tag, U>
8003 static_assert(std::is_same<U, basic_json>::value
8004 or std::is_same<U, const basic_json>::value,
8005 "iter_impl only accepts (const) basic_json");
8013 using pointer =
typename std::conditional<std::is_const<U>::value,
8017 using reference =
typename std::conditional<std::is_const<U>::value,
8035 assert(m_object !=
nullptr);
8037 switch (m_object->m_type)
8041 m_it.object_iterator =
typename object_t::iterator();
8047 m_it.array_iterator =
typename array_t::iterator();
8086 : m_object(other.m_object), m_it(other.m_it)
8095 std::is_nothrow_move_constructible<pointer>::value and
8096 std::is_nothrow_move_assignable<pointer>::value and
8097 std::is_nothrow_move_constructible<internal_iterator>::value and
8098 std::is_nothrow_move_assignable<internal_iterator>::value
8113 assert(m_object !=
nullptr);
8115 switch (m_object->m_type)
8119 m_it.object_iterator = m_object->m_value.object->begin();
8125 m_it.array_iterator = m_object->m_value.array->begin();
8129 case basic_json::value_t::null:
8132 m_it.primitive_iterator.set_end();
8138 m_it.primitive_iterator.set_begin();
8150 assert(m_object !=
nullptr);
8152 switch (m_object->m_type)
8156 m_it.object_iterator = m_object->m_value.object->end();
8162 m_it.array_iterator = m_object->m_value.array->end();
8168 m_it.primitive_iterator.set_end();
8181 assert(m_object !=
nullptr);
8183 switch (m_object->m_type)
8187 assert(m_it.object_iterator != m_object->m_value.object->end());
8188 return m_it.object_iterator->second;
8193 assert(m_it.array_iterator != m_object->m_value.array->end());
8194 return *m_it.array_iterator;
8197 case basic_json::value_t::null:
8204 if (m_it.primitive_iterator.is_begin())
8220 assert(m_object !=
nullptr);
8222 switch (m_object->m_type)
8226 assert(m_it.object_iterator != m_object->m_value.object->end());
8227 return &(m_it.object_iterator->second);
8232 assert(m_it.array_iterator != m_object->m_value.array->end());
8233 return &*m_it.array_iterator;
8238 if (m_it.primitive_iterator.is_begin())
8254 auto result = *
this;
8265 assert(m_object !=
nullptr);
8267 switch (m_object->m_type)
8271 std::advance(m_it.object_iterator, 1);
8277 std::advance(m_it.array_iterator, 1);
8283 ++m_it.primitive_iterator;
8297 auto result = *
this;
8308 assert(m_object !=
nullptr);
8310 switch (m_object->m_type)
8314 std::advance(m_it.object_iterator, -1);
8320 std::advance(m_it.array_iterator, -1);
8326 --m_it.primitive_iterator;
8346 assert(m_object !=
nullptr);
8348 switch (m_object->m_type)
8388 assert(m_object !=
nullptr);
8390 switch (m_object->m_type)
8415 return not other.operator < (*this);
8442 assert(m_object !=
nullptr);
8444 switch (m_object->m_type)
8453 std::advance(m_it.array_iterator, i);
8459 m_it.primitive_iterator += i;
8482 auto result = *
this;
8493 auto result = *
this;
8504 assert(m_object !=
nullptr);
8506 switch (m_object->m_type)
8531 assert(m_object !=
nullptr);
8533 switch (m_object->m_type)
8542 return *std::next(m_it.array_iterator, n);
8545 case basic_json::value_t::null:
8552 if (m_it.primitive_iterator.get_value() == -n)
8566 typename object_t::key_type
key()
const 8568 assert(m_object !=
nullptr);
8570 if (m_object->is_object())
8572 return m_it.object_iterator->first;
8611 template<
typename Base>
8633 return base_iterator::operator++(1);
8639 base_iterator::operator++();
8646 return base_iterator::operator--(1);
8652 base_iterator::operator--();
8659 base_iterator::operator+=(i);
8666 auto result = *
this;
8674 auto result = *
this;
8682 return this->
base() - other.base();
8692 typename object_t::key_type
key()
const 8694 auto it = --this->
base();
8701 auto it = --this->
base();
8702 return it.operator * ();
8717 virtual std::string
read(
size_t offset,
size_t length) = 0;
8723 static std::shared_ptr<input_adapter>
create(std::istream& i,
const size_t buffer_size = 16384)
8729 static std::shared_ptr<input_adapter>
create(std::istream&& i,
const size_t buffer_size = 16384)
8735 static std::shared_ptr<input_adapter>
create(
const char*
b,
size_t l)
8743 template<
typename CharT,
typename std::enable_if<
8744 std::is_pointer<CharT>::value and
8747 static std::shared_ptr<input_adapter>
create(CharT
b)
8749 return create(reinterpret_cast<const char*>(
b),
8750 std::strlen(reinterpret_cast<const char*>(
b)));
8754 template<
class IteratorType,
typename std::enable_if<
8755 std::is_same<typename std::iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>
::value 8758 static std::shared_ptr<input_adapter>
create(IteratorType first, IteratorType last)
8762 assert(std::accumulate(first, last, std::pair<bool, int>(
true, 0),
8763 [&first](std::pair<bool, int> res, decltype(*first) val)
8765 res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
8770 static_assert(
sizeof(
typename std::iterator_traits<IteratorType>::value_type) == 1,
8771 "each element in the iterator range must have the size of 1 byte");
8773 return create(reinterpret_cast<const char*>(&(*first)),
8774 static_cast<size_t>(std::distance(first, last)));
8778 template<
class T, std::
size_t N>
8786 template<
class ContiguousContainer,
typename std::enable_if<
8787 not std::is_pointer<ContiguousContainer>::value and
8789 std::random_access_iterator_tag,
8790 typename std::iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::
value 8792 static std::shared_ptr<input_adapter>
create(
const ContiguousContainer& c)
8795 return create(std::begin(c), std::end(c));
8807 : is(i), start_position(is.tellg()), buffer(buffer_size,
'\0')
8816 is.read(buffer.data(),
static_cast<std::streamsize
>(buffer.size()));
8818 fill_size =
static_cast<size_t>(is.gcount());
8821 if (fill_size >= 3 and buffer[0] ==
'\xEF' and buffer[1] ==
'\xBB' and buffer[2] ==
'\xBF')
8824 processed_chars += 3;
8835 is.seekg(start_position + static_cast<std::streamoff>(processed_chars));
8843 if (buffer_pos == fill_size and not eof)
8846 is.read(buffer.data(),
static_cast<std::streamsize
>(buffer.size()));
8848 fill_size =
static_cast<size_t>(is.gcount());
8857 return std::char_traits<char>::eof();
8862 return buffer[buffer_pos++] & 0xFF;;
8865 std::string
read(
size_t offset,
size_t length)
override 8868 std::string result(length,
'\0');
8871 auto current_pos = is.tellg();
8873 auto flags = is.rdstate();
8878 is.seekg(static_cast<std::streamoff>(offset));
8880 is.read(&result[0], static_cast<std::streamsize>(length));
8883 is.seekg(current_pos);
8895 size_t processed_chars = 0;
8897 size_t buffer_pos = 0;
8902 size_t fill_size = 0;
8919 if (
l >= 3 and
b[0] ==
'\xEF' and
b[1] ==
'\xBB' and
b[2] ==
'\xBF')
8933 return *(cursor++) & 0xFF;
8937 return std::char_traits<char>::eof();
8941 std::string
read(
size_t offset,
size_t length)
override 8944 const size_t max_length =
static_cast<size_t>(limit - start);
8945 return std::string(start + offset,
std::min(length, max_length - offset));
8977 : ia(adapter), is_little_endian(little_endianess())
8996 switch (get_char ?
get() : current)
8999 case std::char_traits<char>::eof():
9035 return get_number<uint8_t>();
9040 return get_number<uint16_t>();
9045 return get_number<uint32_t>();
9050 return get_number<uint64_t>();
9079 return static_cast<int8_t
>(0x20 - 1 - current);
9100 return static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(get_number<uint64_t>());
9134 return get_cbor_string();
9164 const auto len =
static_cast<size_t>(current & 0x1f);
9165 for (
size_t i = 0; i < len; ++i)
9175 const auto len =
static_cast<size_t>(get_number<uint8_t>());
9176 for (
size_t i = 0; i < len; ++i)
9186 const auto len =
static_cast<size_t>(get_number<uint16_t>());
9187 for (
size_t i = 0; i < len; ++i)
9197 const auto len =
static_cast<size_t>(get_number<uint32_t>());
9198 for (
size_t i = 0; i < len; ++i)
9208 const auto len =
static_cast<size_t>(get_number<uint64_t>());
9209 for (
size_t i = 0; i < len; ++i)
9219 while (
get() != 0xff)
9253 const auto len =
static_cast<size_t>(current & 0x1f);
9254 for (
size_t i = 0; i < len; ++i)
9257 auto key = get_cbor_string();
9258 result[key] = parse_cbor();
9266 const auto len =
static_cast<size_t>(get_number<uint8_t>());
9267 for (
size_t i = 0; i < len; ++i)
9270 auto key = get_cbor_string();
9271 result[key] = parse_cbor();
9279 const auto len =
static_cast<size_t>(get_number<uint16_t>());
9280 for (
size_t i = 0; i < len; ++i)
9283 auto key = get_cbor_string();
9284 result[key] = parse_cbor();
9292 const auto len =
static_cast<size_t>(get_number<uint32_t>());
9293 for (
size_t i = 0; i < len; ++i)
9296 auto key = get_cbor_string();
9297 result[key] = parse_cbor();
9305 const auto len =
static_cast<size_t>(get_number<uint64_t>());
9306 for (
size_t i = 0; i < len; ++i)
9309 auto key = get_cbor_string();
9310 result[key] = parse_cbor();
9318 while (
get() != 0xff)
9320 auto key = get_cbor_string();
9321 result[key] = parse_cbor();
9338 return value_t::null;
9343 const int byte1 =
get();
9345 const int byte2 =
get();
9356 const int half = (byte1 << 8) + byte2;
9357 const int exp = (half >> 10) & 0x1f;
9358 const int mant = half & 0x3ff;
9362 val = std::ldexp(mant, -24);
9366 val = std::ldexp(mant + 1024, exp - 25);
9371 ? std::numeric_limits<double>::infinity()
9372 : std::numeric_limits<double>::quiet_NaN();
9374 return (half & 0x8000) != 0 ? -val : val;
9379 return get_number<float>();
9384 return get_number<double>();
9389 std::stringstream ss;
9390 ss << std::setw(2) << std::setfill(
'0') <<
std::hex << current;
9409 case std::char_traits<char>::eof():
9566 const auto len =
static_cast<size_t>(current & 0x0f);
9567 for (
size_t i = 0; i < len; ++i)
9570 auto key = get_msgpack_string();
9571 result[key] = parse_msgpack();
9595 const auto len =
static_cast<size_t>(current & 0x0f);
9596 for (
size_t i = 0; i < len; ++i)
9637 return get_msgpack_string();
9642 return value_t::null;
9657 return get_number<float>();
9662 return get_number<double>();
9667 return get_number<uint8_t>();
9672 return get_number<uint16_t>();
9677 return get_number<uint32_t>();
9682 return get_number<uint64_t>();
9687 return get_number<int8_t>();
9692 return get_number<int16_t>();
9697 return get_number<int32_t>();
9702 return get_number<int64_t>();
9709 return get_msgpack_string();
9715 const auto len =
static_cast<size_t>(get_number<uint16_t>());
9716 for (
size_t i = 0; i < len; ++i)
9726 const auto len =
static_cast<size_t>(get_number<uint32_t>());
9727 for (
size_t i = 0; i < len; ++i)
9737 const auto len =
static_cast<size_t>(get_number<uint16_t>());
9738 for (
size_t i = 0; i < len; ++i)
9741 auto key = get_msgpack_string();
9742 result[key] = parse_msgpack();
9750 const auto len =
static_cast<size_t>(get_number<uint32_t>());
9751 for (
size_t i = 0; i < len; ++i)
9754 auto key = get_msgpack_string();
9755 result[key] = parse_msgpack();
9794 return static_cast<int8_t
>(current);
9799 std::stringstream ss;
9800 ss << std::setw(2) << std::setfill(
'0') <<
std::hex << current;
9816 return (*reinterpret_cast<char*>(&num) == 1);
9832 return (current = ia->get_character());
9848 template<
typename T>
9852 std::array<uint8_t, sizeof(T)> vec;
9853 for (
size_t i = 0; i <
sizeof(
T); ++i)
9859 if (is_little_endian)
9861 vec[
sizeof(
T) - i - 1] = static_cast<uint8_t>(current);
9865 vec[i] =
static_cast<uint8_t
>(current);
9871 std::memcpy(&result, vec.data(),
sizeof(
T));
9887 for (
size_t i = 0; i < len; ++i)
9891 result.append(1, static_cast<char>(current));
9940 const auto len =
static_cast<size_t>(current & 0x1f);
9941 return get_string(len);
9946 const auto len =
static_cast<size_t>(get_number<uint8_t>());
9947 return get_string(len);
9952 const auto len =
static_cast<size_t>(get_number<uint16_t>());
9953 return get_string(len);
9958 const auto len =
static_cast<size_t>(get_number<uint32_t>());
9959 return get_string(len);
9964 const auto len =
static_cast<size_t>(get_number<uint64_t>());
9965 return get_string(len);
9971 while (
get() != 0xff)
9974 result.append(1, static_cast<char>(current));
9981 std::stringstream ss;
9982 ss << std::setw(2) << std::setfill(
'0') <<
std::hex << current;
10039 const auto len =
static_cast<size_t>(current & 0x1f);
10040 return get_string(len);
10045 const auto len =
static_cast<size_t>(get_number<uint8_t>());
10046 return get_string(len);
10051 const auto len =
static_cast<size_t>(get_number<uint16_t>());
10052 return get_string(len);
10057 const auto len =
static_cast<size_t>(get_number<uint32_t>());
10058 return get_string(len);
10063 std::stringstream ss;
10064 ss << std::setw(2) << std::setfill(
'0') <<
std::hex << current;
10076 if (
JSON_UNLIKELY(current == std::char_traits<char>::eof()))
10087 int current = std::char_traits<char>::eof();
10090 size_t chars_read = 0;
10093 const bool is_little_endian =
true;
10108 : is_little_endian(
binary_reader::little_endianess()), oa(adapter)
10120 case value_t::null:
10122 oa->write_character(0xf6);
10145 oa->write_character(0x18);
10150 oa->write_character(0x19);
10155 oa->write_character(0x1a);
10160 oa->write_character(0x1b);
10171 write_number(static_cast<uint8_t>(0x20 + positive_number));
10173 else if (positive_number <= (std::numeric_limits<uint8_t>::max)())
10175 oa->write_character(0x38);
10176 write_number(static_cast<uint8_t>(positive_number));
10178 else if (positive_number <= (std::numeric_limits<uint16_t>::max)())
10180 oa->write_character(0x39);
10181 write_number(static_cast<uint16_t>(positive_number));
10183 else if (positive_number <= (std::numeric_limits<uint32_t>::max)())
10185 oa->write_character(0x3a);
10186 write_number(static_cast<uint32_t>(positive_number));
10190 oa->write_character(0x3b);
10191 write_number(static_cast<uint64_t>(positive_number));
10205 oa->write_character(0x18);
10210 oa->write_character(0x19);
10215 oa->write_character(0x1a);
10220 oa->write_character(0x1b);
10229 oa->write_character(0xfb);
10240 write_number(static_cast<uint8_t>(0x60 + N));
10242 else if (N <= 0xff)
10244 oa->write_character(0x78);
10245 write_number(static_cast<uint8_t>(N));
10247 else if (N <= 0xffff)
10249 oa->write_character(0x79);
10250 write_number(static_cast<uint16_t>(N));
10252 else if (N <= 0xffffffff)
10254 oa->write_character(0x7a);
10255 write_number(static_cast<uint32_t>(N));
10258 else if (N <= 0xffffffffffffffff)
10260 oa->write_character(0x7b);
10261 write_number(static_cast<uint64_t>(N));
10266 oa->write_characters(reinterpret_cast<const uint8_t*>(j.
m_value.
string->c_str()),
10277 write_number(static_cast<uint8_t>(0x80 + N));
10279 else if (N <= 0xff)
10281 oa->write_character(0x98);
10282 write_number(static_cast<uint8_t>(N));
10284 else if (N <= 0xffff)
10286 oa->write_character(0x99);
10287 write_number(static_cast<uint16_t>(N));
10289 else if (N <= 0xffffffff)
10291 oa->write_character(0x9a);
10292 write_number(static_cast<uint32_t>(N));
10295 else if (N <= 0xffffffffffffffff)
10297 oa->write_character(0x9b);
10298 write_number(static_cast<uint64_t>(N));
10316 write_number(static_cast<uint8_t>(0xa0 + N));
10318 else if (N <= 0xff)
10320 oa->write_character(0xb8);
10321 write_number(static_cast<uint8_t>(N));
10323 else if (N <= 0xffff)
10325 oa->write_character(0xb9);
10326 write_number(static_cast<uint16_t>(N));
10328 else if (N <= 0xffffffff)
10330 oa->write_character(0xba);
10331 write_number(static_cast<uint32_t>(N));
10334 else if (N <= 0xffffffffffffffff)
10336 oa->write_character(0xbb);
10337 write_number(static_cast<uint64_t>(N));
10344 write_cbor(el.first);
10345 write_cbor(el.second);
10364 case value_t::null:
10367 oa->write_character(0xc0);
10394 oa->write_character(0xcc);
10400 oa->write_character(0xcd);
10406 oa->write_character(0xce);
10412 oa->write_character(0xcf);
10426 oa->write_character(0xd0);
10432 oa->write_character(0xd1);
10438 oa->write_character(0xd2);
10444 oa->write_character(0xd3);
10461 oa->write_character(0xcc);
10467 oa->write_character(0xcd);
10473 oa->write_character(0xce);
10479 oa->write_character(0xcf);
10488 oa->write_character(0xcb);
10500 write_number(static_cast<uint8_t>(0xa0 | N));
10505 oa->write_character(0xd9);
10506 write_number(static_cast<uint8_t>(N));
10508 else if (N <= 65535)
10511 oa->write_character(0xda);
10512 write_number(static_cast<uint16_t>(N));
10514 else if (N <= 4294967295)
10517 oa->write_character(0xdb);
10518 write_number(static_cast<uint32_t>(N));
10522 oa->write_characters(reinterpret_cast<const uint8_t*>(j.
m_value.
string->c_str()),
10534 write_number(static_cast<uint8_t>(0x90 | N));
10536 else if (N <= 0xffff)
10539 oa->write_character(0xdc);
10540 write_number(static_cast<uint16_t>(N));
10542 else if (N <= 0xffffffff)
10545 oa->write_character(0xdd);
10546 write_number(static_cast<uint32_t>(N));
10564 write_number(static_cast<uint8_t>(0x80 | (N & 0xf)));
10566 else if (N <= 65535)
10569 oa->write_character(0xde);
10570 write_number(static_cast<uint16_t>(N));
10572 else if (N <= 4294967295)
10575 oa->write_character(0xdf);
10576 write_number(static_cast<uint32_t>(N));
10582 write_msgpack(el.first);
10583 write_msgpack(el.second);
10606 template<
typename T>
10610 std::array<uint8_t, sizeof(T)> vec;
10611 std::memcpy(vec.data(), &n,
sizeof(
T));
10614 for (
size_t i = 0; i <
sizeof(
T); ++i)
10617 if (is_little_endian)
10619 oa->write_character(vec[
sizeof(
T) - i - 1]);
10623 oa->write_character(vec[i]);
10630 const bool is_little_endian =
true;
10721 std::vector<uint8_t> result;
10803 std::vector<uint8_t> result;
10897 const size_t start_index = 0)
10972 const size_t start_index = 0)
11019 case token_type::uninitialized:
11020 return "<uninitialized>";
11021 case token_type::literal_true:
11022 return "true literal";
11023 case token_type::literal_false:
11024 return "false literal";
11025 case token_type::literal_null:
11026 return "null literal";
11027 case token_type::value_string:
11028 return "string literal";
11032 return "number literal";
11033 case token_type::begin_array:
11035 case token_type::begin_object:
11037 case token_type::end_array:
11039 case token_type::end_object:
11041 case token_type::name_separator:
11043 case token_type::value_separator:
11045 case token_type::parse_error:
11046 return "<parse error>";
11047 case token_type::end_of_input:
11048 return "end of input";
11052 return "unknown token";
11058 : ia(adapter), decimal_point_char(get_decimal_point())
11069 const auto loc = localeconv();
11070 assert(loc !=
nullptr);
11071 return (loc->decimal_point ==
nullptr) ?
'.' : loc->decimal_point[0];
11087 assert(current ==
'u');
11096 codepoint += 0x1000;
11099 codepoint += 0x2000;
11102 codepoint += 0x3000;
11105 codepoint += 0x4000;
11108 codepoint += 0x5000;
11111 codepoint += 0x6000;
11114 codepoint += 0x7000;
11117 codepoint += 0x8000;
11120 codepoint += 0x9000;
11124 codepoint += 0xa000;
11128 codepoint += 0xb000;
11132 codepoint += 0xc000;
11136 codepoint += 0xd000;
11140 codepoint += 0xe000;
11144 codepoint += 0xf000;
11156 codepoint += 0x0100;
11159 codepoint += 0x0200;
11162 codepoint += 0x0300;
11165 codepoint += 0x0400;
11168 codepoint += 0x0500;
11171 codepoint += 0x0600;
11174 codepoint += 0x0700;
11177 codepoint += 0x0800;
11180 codepoint += 0x0900;
11184 codepoint += 0x0a00;
11188 codepoint += 0x0b00;
11192 codepoint += 0x0c00;
11196 codepoint += 0x0d00;
11200 codepoint += 0x0e00;
11204 codepoint += 0x0f00;
11216 codepoint += 0x0010;
11219 codepoint += 0x0020;
11222 codepoint += 0x0030;
11225 codepoint += 0x0040;
11228 codepoint += 0x0050;
11231 codepoint += 0x0060;
11234 codepoint += 0x0070;
11237 codepoint += 0x0080;
11240 codepoint += 0x0090;
11244 codepoint += 0x00a0;
11248 codepoint += 0x00b0;
11252 codepoint += 0x00c0;
11256 codepoint += 0x00d0;
11260 codepoint += 0x00e0;
11264 codepoint += 0x00f0;
11276 codepoint += 0x0001;
11279 codepoint += 0x0002;
11282 codepoint += 0x0003;
11285 codepoint += 0x0004;
11288 codepoint += 0x0005;
11291 codepoint += 0x0006;
11294 codepoint += 0x0007;
11297 codepoint += 0x0008;
11300 codepoint += 0x0009;
11304 codepoint += 0x000a;
11308 codepoint += 0x000b;
11312 codepoint += 0x000c;
11316 codepoint += 0x000d;
11320 codepoint += 0x000e;
11324 codepoint += 0x000f;
11339 std::stringstream ss;
11340 ss <<
"U+" << std::setw(4) << std::uppercase << std::setfill(
'0') <<
std::hex << codepoint;
11364 assert(current ==
'\"');
11374 case std::char_traits<char>::eof():
11376 error_message =
"invalid string: missing closing quote";
11377 return token_type::parse_error;
11386 return token_type::value_string;
11431 int codepoint1 = get_codepoint();
11435 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
11436 return token_type::parse_error;
11440 if (0xD800 <= codepoint1 and codepoint1 <= 0xDBFF)
11445 const int codepoint2 = get_codepoint();
11449 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
11450 return token_type::parse_error;
11454 if (
JSON_LIKELY(0xDC00 <= codepoint2 and codepoint2 <= 0xDFFF))
11468 error_message =
"invalid string: surrogate " + codepoint_to_string(codepoint1) +
" must be followed by U+DC00..U+DFFF instead of " + codepoint_to_string(codepoint2);
11469 return token_type::parse_error;
11474 error_message =
"invalid string: surrogate " + codepoint_to_string(codepoint1) +
" must be followed by U+DC00..U+DFFF";
11475 return token_type::parse_error;
11480 if (
JSON_UNLIKELY(0xDC00 <= codepoint1 and codepoint1 <= 0xDFFF))
11482 error_message =
"invalid string: surrogate " + codepoint_to_string(codepoint1) +
" must follow U+D800..U+DBFF";
11483 return token_type::parse_error;
11487 codepoint = codepoint1;
11491 assert(0x00 <= codepoint and codepoint <= 0x10FFFF);
11494 if (codepoint < 0x80)
11499 else if (codepoint <= 0x7ff)
11502 add(0xC0 | (codepoint >> 6));
11503 add(0x80 | (codepoint & 0x3F));
11505 else if (codepoint <= 0xffff)
11508 add(0xE0 | (codepoint >> 12));
11509 add(0x80 | ((codepoint >> 6) & 0x3F));
11510 add(0x80 | (codepoint & 0x3F));
11515 add(0xF0 | (codepoint >> 18));
11516 add(0x80 | ((codepoint >> 12) & 0x3F));
11517 add(0x80 | ((codepoint >> 6) & 0x3F));
11518 add(0x80 | (codepoint & 0x3F));
11526 error_message =
"invalid string: forbidden character after backslash";
11527 return token_type::parse_error;
11567 error_message =
"invalid string: control character " + codepoint_to_string(current) +
" must be escaped";
11568 return token_type::parse_error;
11705 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11711 error_message =
"invalid string: ill-formed UTF-8 byte";
11712 return token_type::parse_error;
11720 if (
JSON_LIKELY(0xa0 <= current and current <= 0xbf))
11724 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11731 error_message =
"invalid string: ill-formed UTF-8 byte";
11732 return token_type::parse_error;
11754 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11758 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11765 error_message =
"invalid string: ill-formed UTF-8 byte";
11766 return token_type::parse_error;
11774 if (
JSON_LIKELY(0x80 <= current and current <= 0x9f))
11778 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11785 error_message =
"invalid string: ill-formed UTF-8 byte";
11786 return token_type::parse_error;
11794 if (
JSON_LIKELY(0x90 <= current and current <= 0xbf))
11798 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11802 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11810 error_message =
"invalid string: ill-formed UTF-8 byte";
11811 return token_type::parse_error;
11821 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11825 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11829 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11837 error_message =
"invalid string: ill-formed UTF-8 byte";
11838 return token_type::parse_error;
11846 if (
JSON_LIKELY(0x80 <= current and current <= 0x8f))
11850 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11854 if (
JSON_LIKELY(0x80 <= current and current <= 0xbf))
11862 error_message =
"invalid string: ill-formed UTF-8 byte";
11863 return token_type::parse_error;
11869 error_message =
"invalid string: ill-formed UTF-8 byte";
11870 return token_type::parse_error;
11876 static void strtof(
float& f,
const char* str,
char** endptr) noexcept
11878 f = std::strtof(str, endptr);
11881 static void strtof(
double& f,
const char* str,
char** endptr) noexcept
11883 f = std::strtod(str, endptr);
11886 static void strtof(
long double& f,
const char* str,
char** endptr) noexcept
11888 f = std::strtold(str, endptr);
11939 token_type number_type = token_type::value_unsigned;
11947 goto scan_number_minus;
11953 goto scan_number_zero;
11967 goto scan_number_any1;
11979 number_type = token_type::value_integer;
11985 goto scan_number_zero;
11999 goto scan_number_any1;
12004 error_message =
"invalid number; expected digit after '-'";
12005 return token_type::parse_error;
12015 add(decimal_point_char);
12016 goto scan_number_decimal1;
12023 goto scan_number_exponent;
12028 goto scan_number_done;
12048 goto scan_number_any1;
12053 add(decimal_point_char);
12054 goto scan_number_decimal1;
12061 goto scan_number_exponent;
12066 goto scan_number_done;
12070 scan_number_decimal1:
12072 number_type = token_type::value_float;
12087 goto scan_number_decimal2;
12092 error_message =
"invalid number; expected digit after '.'";
12093 return token_type::parse_error;
12097 scan_number_decimal2:
12113 goto scan_number_decimal2;
12120 goto scan_number_exponent;
12125 goto scan_number_done;
12129 scan_number_exponent:
12131 number_type = token_type::value_float;
12138 goto scan_number_sign;
12153 goto scan_number_any2;
12158 error_message =
"invalid number; expected '+', '-', or digit after exponent";
12159 return token_type::parse_error;
12179 goto scan_number_any2;
12184 error_message =
"invalid number; expected digit after exponent sign";
12185 return token_type::parse_error;
12205 goto scan_number_any2;
12210 goto scan_number_done;
12225 if (number_type == token_type::value_unsigned)
12227 char* endptr =
nullptr;
12229 const auto x = std::strtoull(yytext.data(), &endptr, 10);
12232 assert(endptr == yytext.data() + yylen);
12237 if (value_unsigned == x)
12239 return token_type::value_unsigned;
12243 else if (number_type == token_type::value_integer)
12245 char* endptr =
nullptr;
12247 const auto x = std::strtoll(yytext.data(), &endptr, 10);
12250 assert(endptr == yytext.data() + yylen);
12255 if (value_integer == x)
12257 return token_type::value_integer;
12264 strtof(value_float, yytext.data(),
nullptr);
12265 return token_type::value_float;
12270 assert(current ==
't');
12271 if (
JSON_LIKELY((
get() ==
'r' and
get() ==
'u' and
get() ==
'e')))
12273 return token_type::literal_true;
12276 error_message =
"invalid literal; expected 'true'";
12277 return token_type::parse_error;
12282 assert(current ==
'f');
12283 if (
JSON_LIKELY((
get() ==
'a' and
get() ==
'l' and
get() ==
's' and
get() ==
'e')))
12285 return token_type::literal_false;
12288 error_message =
"invalid literal; expected 'false'";
12289 return token_type::parse_error;
12294 assert(current ==
'n');
12295 if (
JSON_LIKELY((
get() ==
'u' and
get() ==
'l' and
get() ==
'l')))
12297 return token_type::literal_null;
12300 error_message =
"invalid literal; expected 'null'";
12301 return token_type::parse_error;
12312 start_pos = chars_read - 1;
12320 ? (next_unget =
false, current)
12321 : (current = ia->get_character());
12331 yytext.resize(2 * yytext.capacity(),
'\0');
12333 yytext[yylen++] =
static_cast<char>(c);
12344 return value_integer;
12350 return value_unsigned;
12356 return value_float;
12364 return std::string(yytext.data(), yylen);
12381 std::string
s = ia->read(start_pos, chars_read - start_pos);
12384 std::string result;
12387 if (c ==
'\0' or c == std::char_traits<char>::eof())
12392 else if (
'\x00' <= c and c <=
'\x1f')
12395 result +=
"<" + codepoint_to_string(c) +
">";
12400 result.append(1, c);
12410 return error_message;
12424 while (current ==
' ' or current ==
'\t' or current ==
'\n' or current ==
'\r');
12430 return token_type::begin_array;
12432 return token_type::end_array;
12434 return token_type::begin_object;
12436 return token_type::end_object;
12438 return token_type::name_separator;
12440 return token_type::value_separator;
12444 return scan_true();
12446 return scan_false();
12448 return scan_null();
12452 return scan_string();
12466 return scan_number();
12471 case std::char_traits<char>::eof():
12472 return token_type::end_of_input;
12476 error_message =
"invalid literal";
12477 return token_type::parse_error;
12486 int current = std::char_traits<char>::eof();
12489 bool next_unget =
false;
12492 size_t chars_read = 0;
12494 size_t start_pos = 0;
12497 std::vector<char> yytext = std::vector<char>(1024,
'\0');
12502 std::string error_message =
"";
12510 const char decimal_point_char =
'.';
12524 : callback(cb), m_lexer(adapter)
12567 if (not accept_internal())
12589 auto result =
basic_json(value_t::discarded);
12591 switch (last_token)
12595 if (keep and (not callback
12621 const auto key = m_lexer.get_string();
12623 bool keep_tag =
false;
12643 auto value = parse_internal(keep);
12644 if (keep and keep_tag and not
value.is_discarded())
12646 result[key] = std::move(
value);
12672 if (keep and (not callback
12697 auto value = parse_internal(keep);
12698 if (keep and not
value.is_discarded())
12700 result.push_back(std::move(
value));
12726 result.m_type = value_t::null;
12739 result.m_value =
true;
12746 result.m_value =
false;
12753 result.m_value = m_lexer.get_number_unsigned();
12760 result.m_value = m_lexer.get_number_integer();
12767 result.m_value = m_lexer.get_number_float();
12770 if (
JSON_UNLIKELY(not std::isfinite(result.m_value.number_float)))
12781 unexpect(last_token);
12805 switch (last_token)
12836 if (not accept_internal())
12874 if (not accept_internal())
12919 last_token = m_lexer.scan();
12930 std::string error_msg =
"syntax error - ";
12933 error_msg += m_lexer.get_error_message() +
"; last read: '" + m_lexer.get_token_string() +
"'";
12952 std::string error_msg =
"syntax error - ";
12955 error_msg += m_lexer.get_error_message() +
"; last read '" + m_lexer.get_token_string() +
"'";
13018 : reference_tokens(split(
s))
13038 return std::accumulate(reference_tokens.begin(),
13039 reference_tokens.end(), std::string{},
13040 [](
const std::string &
a,
const std::string &
b)
13047 operator std::string()
const 13064 auto last = reference_tokens.back();
13065 reference_tokens.pop_back();
13072 return reference_tokens.empty();
13101 for (
const auto& reference_token : reference_tokens)
13103 switch (result->m_type)
13105 case value_t::null:
13107 if (reference_token ==
"0")
13110 result = &result->operator[](0);
13115 result = &result->operator[](reference_token);
13123 result = &result->operator[](reference_token);
13132 result = &result->operator[](
static_cast<size_type>(std::stoi(reference_token)));
13179 for (
const auto& reference_token : reference_tokens)
13182 if (ptr->m_type == value_t::null)
13185 const bool nums = std::all_of(reference_token.begin(),
13186 reference_token.end(),
13189 return (x >=
'0' and x <=
'9');
13194 if (nums or reference_token ==
"-")
13204 switch (ptr->m_type)
13209 ptr = &ptr->operator[](reference_token);
13216 if (reference_token.size() > 1 and reference_token[0] ==
'0')
13221 if (reference_token ==
"-")
13224 ptr = &ptr->operator[](ptr->m_value.array->size());
13231 ptr = &ptr->operator[](
static_cast<size_type>(std::stoi(reference_token)));
13259 for (
const auto& reference_token : reference_tokens)
13261 switch (ptr->m_type)
13266 ptr = &ptr->at(reference_token);
13272 if (reference_token ==
"-")
13277 ") is out of range"));
13281 if (reference_token.size() > 1 and reference_token[0] ==
'0')
13289 ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
13323 for (
const auto& reference_token : reference_tokens)
13325 switch (ptr->m_type)
13330 ptr = &ptr->operator[](reference_token);
13336 if (reference_token ==
"-")
13341 ") is out of range"));
13345 if (reference_token.size() > 1 and reference_token[0] ==
'0')
13353 ptr = &ptr->operator[](
static_cast<size_type>(std::stoi(reference_token)));
13380 for (
const auto& reference_token : reference_tokens)
13382 switch (ptr->m_type)
13387 ptr = &ptr->at(reference_token);
13393 if (reference_token ==
"-")
13398 ") is out of range"));
13402 if (reference_token.size() > 1 and reference_token[0] ==
'0')
13410 ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
13438 static std::vector<std::string>
split(
const std::string& reference_string)
13440 std::vector<std::string> result;
13443 if (reference_string.empty())
13449 if (reference_string[0] !=
'/')
13459 size_t slash = reference_string.find_first_of(
'/', 1),
13468 slash = reference_string.find_first_of(
'/', start))
13472 auto reference_token = reference_string.substr(start, slash - start);
13475 for (
size_t pos = reference_token.find_first_of(
'~');
13476 pos != std::string::npos;
13477 pos = reference_token.find_first_of(
'~', pos + 1))
13479 assert(reference_token[pos] ==
'~');
13482 if (pos == reference_token.size() - 1 or
13483 (reference_token[pos + 1] !=
'0' and
13484 reference_token[pos + 1] !=
'1'))
13491 unescape(reference_token);
13492 result.push_back(reference_token);
13512 const std::string& f,
13513 const std::string& t)
13515 assert(not f.empty());
13518 size_t pos =
s.find(f);
13519 pos != std::string::npos;
13520 s.replace(pos, f.size(), t),
13521 pos =
s.find(f, pos + t.size())
13529 replace_substring(
s,
"~",
"~0");
13530 replace_substring(
s,
"/",
"~1");
13538 replace_substring(
s,
"~1",
"/");
13540 replace_substring(
s,
"~0",
"~");
13550 static void flatten(
const std::string& reference_string,
13554 switch (
value.m_type)
13558 if (
value.m_value.array->empty())
13561 result[reference_string] =
nullptr;
13566 for (
size_t i = 0; i <
value.m_value.array->size(); ++i)
13569 value.m_value.array->operator[](i), result);
13577 if (
value.m_value.object->empty())
13580 result[reference_string] =
nullptr;
13585 for (
const auto& element : *
value.m_value.object)
13588 element.second, result);
13597 result[reference_string] =
value;
13615 if (not
value.is_object())
13623 for (
const auto& element : *
value.m_value.object)
13625 if (not element.second.is_primitive())
13644 return lhs.reference_tokens == rhs.reference_tokens;
13650 return !(lhs == rhs);
13654 std::vector<std::string> reference_tokens {};
13936 enum class patch_operations {add,
remove,
replace, move,
copy,
test, invalid};
13938 const auto get_op = [](
const std::string & op)
13942 return patch_operations::add;
13944 if (op ==
"remove")
13946 return patch_operations::remove;
13948 if (op ==
"replace")
13954 return patch_operations::move;
13962 return patch_operations::test;
13965 return patch_operations::invalid;
13980 if (top_pointer != ptr)
13982 result.
at(top_pointer);
13986 const auto last_path = ptr.
pop_back();
13991 case value_t::null:
13995 parent[last_path] = val;
14001 if (last_path ==
"-")
14008 const auto idx = std::stoi(last_path);
14009 if (static_cast<size_type>(idx) > parent.
size())
14033 const auto operation_remove = [&result](
json_pointer & ptr)
14036 const auto last_path = ptr.
pop_back();
14043 auto it = parent.
find(last_path);
14044 if (it != parent.
end())
14056 parent.
erase(static_cast<size_type>(std::stoi(last_path)));
14067 for (
const auto& val : json_patch)
14070 const auto get_value = [&val](
const std::string & op,
14071 const std::string & member,
14078 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
14081 if (it == val.m_value.object->end())
14087 if (string_type and not it->second.is_string())
14097 if (not val.is_object())
14103 const std::string op = get_value(
"op",
"op",
true);
14104 const std::string path = get_value(op,
"path",
true);
14107 switch (get_op(op))
14109 case patch_operations::add:
14111 operation_add(ptr, get_value(
"add",
"value",
false));
14115 case patch_operations::remove:
14117 operation_remove(ptr);
14124 result.
at(ptr) = get_value(
"replace",
"value",
false);
14128 case patch_operations::move:
14130 const std::string from_path = get_value(
"move",
"from",
true);
14140 operation_remove(from_ptr);
14141 operation_add(ptr, v);
14147 const std::string from_path = get_value(
"copy",
"from",
true);;
14151 result[ptr] = result.
at(from_ptr);
14155 case patch_operations::test:
14157 bool success =
false;
14162 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
14178 case patch_operations::invalid:
14224 const std::string& path =
"")
14230 if (source == target)
14235 if (source.
type() != target.
type())
14247 switch (source.
type())
14253 while (i < source.
size() and i < target.
size())
14257 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
14266 while (i < source.
size())
14279 while (i < target.
size())
14285 {
"value", target[i]}
14296 for (
auto it = source.
begin(); it != source.
end(); ++it)
14301 if (target.
find(it.key()) != target.
end())
14304 auto temp_diff =
diff(it.value(), target[it.key()], path +
"/" + key);
14305 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
14313 {
"path", path +
"/" + key}
14319 for (
auto it = target.
begin(); it != target.
end(); ++it)
14321 if (source.
find(it.key()) == source.
end())
14328 {
"path", path +
"/" + key},
14329 {
"value", it.value()}
14388 is_nothrow_move_constructible<nlohmann::json>::value and
14389 is_nothrow_move_assignable<nlohmann::json>::value
14407 const auto& h = hash<nlohmann::json::string_t>();
14408 return h(j.
dump());
14466 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 14467 #pragma GCC diagnostic pop 14469 #if defined(__clang__) 14470 #pragma GCC diagnostic pop 14478 #undef JSON_UNLIKELY 14479 #undef JSON_DEPRECATED friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7775
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition: json.hpp:1609
the parser read ] and finished processing a JSON array
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:1951
reference operator+=(const basic_json &val)
add an object to an array
Definition: json.hpp:5595
int d
Definition: base.py:14
lexer(input_adapter_t adapter)
Definition: json.hpp:11057
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition: json.hpp:2562
const_reference operator[](const typename object_t::key_type &key) const
read-only access specified object element
Definition: json.hpp:4120
the character for array begin [
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition: json.hpp:1374
string_t * get_impl_ptr(string_t *) noexcept
get a pointer to the value (string)
Definition: json.hpp:3315
static void construct(BasicJsonType &j, const CompatibleArrayType &arr)
Definition: json.hpp:573
json_reverse_iterator operator++(int)
post-increment (it++)
Definition: json.hpp:8631
const int id
the id of the exception
Definition: json.hpp:155
const uint32_t T[512]
Definition: groestl_tables.h:34
constexpr const object_t * get_impl_ptr(const object_t *) const noexcept
get a pointer to the value (object)
Definition: json.hpp:3297
void emplace_back(Args &&... args)
add an object to an array
Definition: json.hpp:5721
iteration_proxy_internal & operator++()
increment operator (needed for range-based for)
Definition: json.hpp:7906
void set_end() noexcept
set iterator to a defined past the end
Definition: json.hpp:7748
Definition: json.hpp:1115
basic_json parse(const bool strict=true)
public parser interface
Definition: json.hpp:12537
void set_begin() noexcept
set the iterator to the first value
Definition: json.hpp:8111
friend std::ostream & operator<<(std::ostream &os, primitive_iterator_t it)
Definition: json.hpp:7807
number_unsigned_t * get_impl_ptr(number_unsigned_t *) noexcept
get a pointer to the value (unsigned number)
Definition: json.hpp:3351
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition: json.hpp:5406
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:6373
std::numeric_limits< RealIntegerType > RealLimits
Definition: json.hpp:710
basic_json(basic_json &&other) noexcept
move constructor
Definition: json.hpp:2756
#define JSON_CATCH(exception)
Definition: json.hpp:99
bool is_negative(T value)
Definition: format.h:906
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:1899
basic_json parse_internal(bool keep)
the actual parser
Definition: json.hpp:12587
iter_impl operator--(int)
post-decrement (it–)
Definition: json.hpp:8295
void dump_escaped(const string_t &s) const
dump escaped string
Definition: json.hpp:7028
difference_type operator-(const iter_impl &other) const
return difference
Definition: json.hpp:8502
an iterator for primitive JSON types
Definition: json.hpp:7733
specialization for std::less<value_t>
Definition: json.hpp:14414
token_type scan_null()
Definition: json.hpp:12292
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:7872
friend bool operator==(json_pointer const &lhs, json_pointer const &rhs) noexcept
Definition: json.hpp:13641
void expect(typename lexer::token_type t) const
Definition: json.hpp:12926
bool accept(const bool strict=true)
public accept interface
Definition: json.hpp:12562
reference get_checked(pointer ptr) const
Definition: json.hpp:13257
number value (unsigned integer)
static constexpr auto value
Definition: json.hpp:723
void check_eof() const
check if input ended
Definition: json.hpp:10074
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition: json.hpp:8626
static auto constexpr value
Definition: json.hpp:682
iter_impl operator+(difference_type i)
add to iterator
Definition: json.hpp:8480
void dump_float(number_float_t x)
dump a floating-point number
Definition: json.hpp:7216
static basic_json parse(std::istream &&i, const parser_callback_t cb=nullptr)
deserialize from stream
Definition: json.hpp:7498
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition: json.hpp:4576
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition: json.hpp:12354
static void construct(BasicJsonType &j, typename BasicJsonType::number_float_t val) noexcept
Definition: json.hpp:526
void operator()(const BasicJsonType &j, T &val) const noexcept(noexcept(std::declval< from_json_fn >().call(j, val, priority_tag< 1 > {})))
Definition: json.hpp:1135
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:1953
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.hpp:13725
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:1955
typename std::remove_cv< typename std::remove_reference< T >::type >::type uncvref_t
Definition: json.hpp:465
json_value(const string_t &value)
constructor for strings
Definition: json.hpp:2039
IntFormatSpec< int, TypeSpec< 'x'> > hex(int value)
friend bool operator!=(json_pointer const &lhs, json_pointer const &rhs) noexcept
Definition: json.hpp:13647
iteration_proxy_internal end() noexcept
return iterator end (needed for range-based for)
Definition: json.hpp:7970
primitive_iterator_t & operator+=(difference_type n)
Definition: json.hpp:7838
token_type scan_number()
scan a number literal
Definition: json.hpp:11932
basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer > basic_json_t
workaround type for MSVC
Definition: json.hpp:1305
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition: json.hpp:1831
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.hpp:2935
static basic_json parse(std::istream &i, const parser_callback_t cb=nullptr)
deserialize from stream
Definition: json.hpp:7489
boolean_t boolean
boolean
Definition: json.hpp:1957
std::string to_string() const noexcept
return a string representation of the JSON pointer
Definition: json.hpp:13036
token_type scan()
Definition: json.hpp:12417
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than or equal
Definition: json.hpp:6504
helper class for iteration
Definition: json.hpp:7886
json_value(number_float_t v) noexcept
constructor for numbers (floating-point)
Definition: json.hpp:1974
json_value(value_t t)
constructor for empty values of a given type
Definition: json.hpp:1976
serializer(output_adapter_t< char > s, const char ichar)
Definition: json.hpp:6736
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:1760
reference operator[](const typename object_t::key_type &key)
access specified object element
Definition: json.hpp:4071
bool accept_internal()
the acutal acceptor
Definition: json.hpp:12803
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition: json.hpp:2965
static void replace_substring(std::string &s, const std::string &f, const std::string &t)
replace all occurrences of a substring by another string
Definition: json.hpp:13511
std::runtime_error m
an exception object as storage for error messages
Definition: json.hpp:169
a class to store JSON values
Definition: json.hpp:1298
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition: json.hpp:1367
void from_json_array_impl(const BasicJsonType &j, CompatibleArrayType &arr, priority_tag< 0 >)
Definition: json.hpp:981
typename std::conditional< std::is_const< U >::value, typename basic_json::const_reference, typename basic_json::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition: json.hpp:8019
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.hpp:13765
const char thousands_sep
the locale's thousand separator character
Definition: json.hpp:7301
iterator insert(const_iterator pos, basic_json &&val)
inserts element
Definition: json.hpp:5841
std::numeric_limits< CompatibleNumberIntegerType > CompatibleLimits
Definition: json.hpp:711
size_type count(typename object_t::key_type key) const
returns the number of occurrences of a key in a JSON object
Definition: json.hpp:4905
an floating point number – use get_number_float() for actual value
default JSONSerializer template argument
Definition: json.hpp:1170
void insert(const_iterator first, const_iterator last)
inserts elements
Definition: json.hpp:6021
array_t * get_impl_ptr(array_t *) noexcept
get a pointer to the value (array)
Definition: json.hpp:3303
typename basic_json::difference_type difference_type
a type to represent differences between iterators
Definition: json.hpp:8011
static std::shared_ptr< output_adapter< CharType > > create(std::string &s)
Definition: json.hpp:6634
boolean_t * get_impl_ptr(boolean_t *) noexcept
get a pointer to the value (boolean)
Definition: json.hpp:3327
constexpr bool is_structured() const noexcept
return whether type is structured
Definition: json.hpp:2992
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
Definition: json.hpp:7341
type_error(int id_, const char *what_arg)
Definition: json.hpp:317
static allocator_type get_allocator()
returns the allocator associated with the container
Definition: json.hpp:1386
StringType string_t
a type for a string
Definition: json.hpp:1662
JSON_DEPRECATED friend std::istream & operator<<(basic_json &j, std::istream &i)
deserialize from stream
Definition: json.hpp:7624
friend constexpr bool operator>(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7785
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value and is_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
Definition: json.hpp:14386
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:5016
void set_end() noexcept
set the iterator past the last value
Definition: json.hpp:8148
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:7296
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition: json.hpp:2510
static iteration_proxy< iterator > iterator_wrapper(reference cont)
wrapper to access iterator member functions in range-based for
Definition: json.hpp:5212
reference operator[](T *(&key)[n])
access specified object element
Definition: json.hpp:4160
basic_json flatten() const
return flattened JSON value
Definition: json.hpp:13832
detail::parse_error parse_error
exception indicating a parse error
Definition: json.hpp:1328
Definition: block_queue.cpp:41
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:4945
iter_impl & operator--()
pre-decrement (–it)
Definition: json.hpp:8306
static void construct(BasicJsonType &j, const typename BasicJsonType::string_t &s)
Definition: json.hpp:514
static void strtof(double &f, const char *str, char **endptr) noexcept
Definition: json.hpp:11881
std::bidirectional_iterator_tag iterator_category
the category of the iterator
Definition: json.hpp:8021
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.hpp:1359
static void unescape(std::string &s)
unescape tilde and slash
Definition: json.hpp:13535
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition: json.hpp:5645
static std::string codepoint_to_string(int codepoint)
create diagnostic representation of a codepoint
Definition: json.hpp:11337
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts elements
Definition: json.hpp:5920
reference value() const
return the value of an iterator
Definition: json.hpp:8582
ValueType value(const typename object_t::key_type &key, ValueType default_value) const
access specified object element with default value
Definition: json.hpp:4340
lexical analysis
Definition: json.hpp:10990
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:6344
the character for object end }
const_iterator find(typename object_t::key_type key) const
find an element in a JSON object
Definition: json.hpp:4872
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than
Definition: json.hpp:6548
const_reverse_iterator rbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:5094
number_unsigned_t number_unsigned
number (unsigned integer)
Definition: json.hpp:1961
number_float_t number_float
number (floating-point)
Definition: json.hpp:1963
static iteration_proxy< const_iterator > iterator_wrapper(const_reference cont)
wrapper to access iterator member functions in range-based for
Definition: json.hpp:5220
static basic_json from_cbor(const std::vector< uint8_t > &v, const size_t start_index=0)
create a JSON value from a byte vector in CBOR format
Definition: json.hpp:10896
const char indent_char
the indentation character
Definition: json.hpp:7306
static std::size_t extra_space(const string_t &s) noexcept
calculates the extra space to escape a JSON string
Definition: json.hpp:6957
static basic_json parse(const CharT s, const parser_callback_t cb=nullptr)
deserialize from string literal
Definition: json.hpp:7454
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:6301
void get_arithmetic_value(const BasicJsonType &j, ArithmeticType &val)
Definition: json.hpp:878
const value_type & const_reference
the type of an element const reference
Definition: json.hpp:1356
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:3173
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition: json.hpp:5769
#define JSON_UNLIKELY(x)
Definition: json.hpp:108
static void construct(BasicJsonType &j, typename BasicJsonType::number_unsigned_t val) noexcept
Definition: json.hpp:538
std::shared_ptr< input_adapter > input_adapter_t
a type to simplify interfaces
Definition: json.hpp:8800
virtual ~output_adapter()
Definition: json.hpp:6622
friend constexpr bool operator!=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7770
array (ordered collection of values)
indicating the end of the input buffer
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition: json.hpp:8664
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:6559
typename std::conditional< std::is_const< U >::value, typename basic_json::const_pointer, typename basic_json::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition: json.hpp:8015
void write_msgpack(const basic_json &j)
[in] j JSON value to serialize
Definition: json.hpp:10360
constexpr const string_t * get_impl_ptr(const string_t *) const noexcept
get a pointer to the value (string)
Definition: json.hpp:3321
json_reverse_iterator & operator++()
pre-increment (++it)
Definition: json.hpp:8637
IteratorType::reference value() const
return value of the iterator
Definition: json.hpp:7948
static std::vector< std::string > split(const std::string &reference_string)
split the string input to reference tokens
Definition: json.hpp:13438
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition: json.hpp:8032
json_value(number_integer_t v) noexcept
constructor for numbers (integer)
Definition: json.hpp:1970
void copy(key &AA, const key &A)
Definition: rctOps.h:81
serialization to CBOR and MessagePack values
Definition: json.hpp:10099
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:6592
void to_json(BasicJsonType &j, T b) noexcept
Definition: json.hpp:787
static void to_json(BasicJsonType &j, ValueType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< ValueType >(val))))
convert any value type to a JSON value
Definition: json.hpp:1198
const_reference operator[](T *key) const
read-only access specified object element
Definition: json.hpp:4278
const std::lconv * loc
the locale
Definition: json.hpp:7299
reference & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value)
copy assignment
Definition: json.hpp:2793
static std::string escape(std::string s)
escape tilde and slash
Definition: json.hpp:13526
typename Base::reference reference
the reference type for the pointed-to element
Definition: json.hpp:8618
static basic_json parse(const ContiguousContainer &c, const parser_callback_t cb=nullptr)
deserialize from a container with contiguous storage
Definition: json.hpp:7609
NLOHMANN_JSON_HAS_HELPER(mapped_type)
flags
Definition: http_parser_merged.h:136
putput adatpter for output streams
Definition: json.hpp:6669
exception indicating access out of the defined range
Definition: json.hpp:338
static out_of_range create(int id, const std::string &what_arg)
Definition: json.hpp:341
constexpr bool is_null() const noexcept
return whether value is null
Definition: json.hpp:3014
iteration_proxy_internal(IteratorType it) noexcept
Definition: json.hpp:7895
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition: json.hpp:3151
bool operator!=(const iter_impl &other) const
comparison: not equal
Definition: json.hpp:8371
JSONSerializer< T, SFINAE > json_serializer
Definition: json.hpp:1314
const_reference get_checked(const_pointer ptr) const
Definition: json.hpp:13378
const std::string get_string()
return string value
Definition: json.hpp:12360
static basic_json unflatten(const basic_json &value)
Definition: json.hpp:13613
discarded by the the parser callback function
virtual void write_characters(const CharType *s, size_t length)=0
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:3792
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition: json.hpp:2218
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: json.hpp:8471
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition: json.hpp:3941
const size_t byte
byte index of the parse error
Definition: json.hpp:236
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition: json.hpp:4771
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than
Definition: json.hpp:6460
basic_json(const basic_json &other)
copy constructor
Definition: json.hpp:2679
output adapter for basic_string
Definition: json.hpp:6692
static constexpr bool value
Definition: json.hpp:743
T get_number()
Definition: json.hpp:9849
ValueType value(const json_pointer &ptr, ValueType default_value) const
access specified object element via JSON Pointer with default value
Definition: json.hpp:4412
output_vector_adapter(std::vector< CharType > &vec)
Definition: json.hpp:6649
void push_back(std::initializer_list< basic_json > init)
add an object to an object
Definition: json.hpp:5676
void add(int c)
add a character to yytext
Definition: json.hpp:12325
json_value()=default
default constructor (for null values)
static void construct(BasicJsonType &j, const typename BasicJsonType::object_t &obj)
Definition: json.hpp:600
void clear() noexcept
clears the contents
Definition: json.hpp:5462
std::vector< node > array
Definition: mstch.hpp:120
void to_json(BasicJsonType &j, T(&arr)[N])
Definition: json.hpp:863
primitive_iterator_t & operator--()
Definition: json.hpp:7825
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts elements
Definition: json.hpp:5870
~basic_json()
destructor
Definition: json.hpp:2826
std::vector< std::string > reference_tokens
the reference tokens
Definition: json.hpp:13654
std::string type_name() const
return the type as string
Definition: json.hpp:7683
constexpr bool is_number() const noexcept
return whether value is a number
Definition: json.hpp:3066
internal::map< const std::string, node > map
Definition: mstch.hpp:119
static basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
Definition: json.hpp:14222
exception indicating a parse error
Definition: json.hpp:207
basic_json parse_msgpack()
create a JSON value from MessagePack input
Definition: json.hpp:9404
static type_error create(int id, const std::string &what_arg)
Definition: json.hpp:310
reference operator[](T *key)
access specified object element
Definition: json.hpp:4228
friend class basic_json
allow basic_json to access private members
Definition: json.hpp:8000
internal_iterator m_it
the actual iterator of the associated instance
Definition: json.hpp:8591
#define JSON_THROW(exception)
Definition: json.hpp:97
an unsigned integer – use get_number_unsigned() for actual value
basic_json::string_t key() const
return key of the iterator
Definition: json.hpp:7921
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.hpp:13697
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition: json.hpp:8621
static void construct(BasicJsonType &j, const typename BasicJsonType::array_t &arr)
Definition: json.hpp:562
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition: json.hpp:3890
reference get_and_create(reference j) const
create and return a reference to the pointed to value
Definition: json.hpp:13095
string_t indent_string
the indentation string
Definition: json.hpp:7309
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition: json.hpp:8657
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition: json.hpp:8672
#define JSON_DEPRECATED
Definition: json.hpp:88
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: json.hpp:8179
general exception of the basic_json class
Definition: json.hpp:145
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:5340
difference_type get_value() const noexcept
Definition: json.hpp:7737
out_of_range(int id_, const char *what_arg)
Definition: json.hpp:348
constexpr const PointerType get_ptr() const noexcept
get a pointer value (implicit)
Definition: json.hpp:3642
declaration and default definition for the functions used the API
void escape(const std::string &str, std::string &ret)
Definition: json.h:33
static std::vector< uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition: json.hpp:10719
void write_characters(const CharType *s, size_t length) override
Definition: json.hpp:6681
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition: json.hpp:12342
auto call(const BasicJsonType &j, T &val, priority_tag< 1 >) const noexcept(noexcept(from_json(j, val))) -> decltype(from_json(j, val), void())
Definition: json.hpp:1119
reference back()
access the last element
Definition: json.hpp:4509
binary_writer(output_adapter_t< uint8_t > adapter)
create a binary writer
Definition: json.hpp:10107
static void construct(BasicJsonType &j, typename BasicJsonType::number_integer_t val) noexcept
Definition: json.hpp:550
syntax analysis
Definition: json.hpp:12518
DummyInt isnan(...)
Definition: format.h:372
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: json.hpp:8380
friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
comparison: equal
Definition: json.hpp:6290
a string – use get_string() for actual value
iter_impl(const iter_impl &other) noexcept
copy constructor
Definition: json.hpp:8085
static std::shared_ptr< output_adapter< CharType > > create(std::vector< CharType > &vec)
Definition: json.hpp:6624
iter_impl operator++(int)
post-increment (it++)
Definition: json.hpp:8252
static void strtof(float &f, const char *str, char **endptr) noexcept
Definition: json.hpp:11876
reference operator[](difference_type n) const
access to successor
Definition: json.hpp:8686
const_iterator begin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:4955
exception indicating errors with iterators
Definition: json.hpp:268
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition: json.hpp:5123
static std::string name(const std::string &ename, int id)
Definition: json.hpp:162
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition: json.hpp:3036
wrapper around the serialization functions
Definition: json.hpp:6725
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition: json.hpp:431
json_pointer top() const
Definition: json.hpp:13075
number_integer_t * get_impl_ptr(number_integer_t *) noexcept
get a pointer to the value (integer number)
Definition: json.hpp:3339
namespace for Niels Lohmann
Definition: json.hpp:116
serializer & operator=(const serializer &)=delete
parse_event_t
JSON callback events.
Definition: json.hpp:2088
hash value for JSON objects
Definition: json.hpp:14397
serializer(const serializer &)=delete
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition: json.hpp:4683
constexpr const boolean_t * get_impl_ptr(const boolean_t *) const noexcept
get a pointer to the value (boolean)
Definition: json.hpp:3333
static void flatten(const std::string &reference_string, const basic_json &value, basic_json &result)
Definition: json.hpp:13550
object (unordered set of name/value pairs)
constexpr bool is_string() const noexcept
return whether value is a string
Definition: json.hpp:3217
parser(input_adapter_t adapter, const parser_callback_t cb=nullptr)
a parser reading from an input adapter
Definition: json.hpp:12522
static other_error create(int id, const std::string &what_arg)
Definition: json.hpp:367
void write_cbor(const basic_json &j)
[in] j JSON value to serialize
Definition: json.hpp:10116
static const char * token_type_name(const token_type t) noexcept
return name of values of type token_type (only used for errors)
Definition: json.hpp:11015
static ReferenceType get_ref_impl(ThisType &obj)
helper function to implement get_ref()
Definition: json.hpp:3386
const char decimal_point
the locale's decimal point character
Definition: json.hpp:7303
Definition: json.hpp:1089
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.hpp:3691
static constexpr bool value
Definition: json.hpp:761
Definition: json.hpp:1144
iteration_proxy_internal begin() noexcept
return iterator begin (needed for range-based for)
Definition: json.hpp:7964
typename std::enable_if< B, T >::type enable_if_t
Definition: json.hpp:462
string_t dump(const int indent=-1, const char indent_char=' ') const
serialization
Definition: json.hpp:2900
#define min(a, b)
Definition: oaes_lib.c:71
the parser read } and finished processing a JSON object
friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7802
primitive_iterator_t operator--(int)
Definition: json.hpp:7831
an iterator value
Definition: json.hpp:7865
int b
Definition: base.py:1
exception indicating executing a member function with a wrong type
Definition: json.hpp:307
value_t m_type
the type of the current element
Definition: json.hpp:7713
json_value(number_unsigned_t v) noexcept
constructor for numbers (unsigned)
Definition: json.hpp:1972
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:6515
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adaptor
Definition: json.hpp:8616
object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:7868
static basic_json from_msgpack(const std::vector< uint8_t > &v, const size_t start_index=0)
create a JSON value from a byte vector in MessagePack format
Definition: json.hpp:10971
void write_character(CharType c) override
Definition: json.hpp:6699
std::shared_ptr< output_adapter< CharType > > output_adapter_t
a type to simplify interfaces
Definition: json.hpp:6642
static basic_json array(std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
explicitly create an array from an initializer list
Definition: json.hpp:2445
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.hpp:3614
value_t
the JSON type enumeration
Definition: json.hpp:409
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition: json.hpp:7656
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition: json.hpp:8650
output_string_adapter(std::string &s)
Definition: json.hpp:6695
DummyInt signbit(...)
Definition: format.h:368
#define JSON_LIKELY(x)
Definition: json.hpp:107
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:6209
JSON Pointer.
Definition: json.hpp:12989
type
Definition: json.h:74
void write_character(CharType c) override
Definition: json.hpp:6653
void reset() noexcept
reset yytext
Definition: json.hpp:12309
string_t value(const json_pointer &ptr, const char *default_value) const
overload for a default value of type const char*
Definition: json.hpp:4435
void push_back(const basic_json &val)
add an object to an array
Definition: json.hpp:5571
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: json.hpp:8413
a signed integer – use get_number_integer() for actual value
internal::object_t< node > object
Definition: mstch.hpp:117
primitive_iterator_t & operator-=(difference_type n)
Definition: json.hpp:7844
static constexpr T value
Definition: json.hpp:1146
deserialization of CBOR and MessagePack values
Definition: json.hpp:8968
difference_type m_it
iterator as signed integer type
Definition: json.hpp:7855
int l
Definition: base.py:3
iter_impl & operator=(iter_impl other) noexcept(std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value)
copy assignment
Definition: json.hpp:8094
output_stream_adapter(std::basic_ostream< CharType > &s)
Definition: json.hpp:6672
static T * create(Args &&... args)
helper for exception-safe object creation
Definition: json.hpp:1907
std::size_t operator()(const nlohmann::json &j) const
return a hash value for a JSON object
Definition: json.hpp:14404
token_type
token types for the parser
Definition: json.hpp:10994
#define JSON_TRY
Definition: json.hpp:98
object_t::key_type key() const
return the key of an object iterator
Definition: json.hpp:8692
const_reference operator[](T *(&key)[n]) const
read-only access specified object element
Definition: json.hpp:4195
const_reference back() const
access the last element
Definition: json.hpp:4519
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition: json.hpp:1378
token_type scan_false()
Definition: json.hpp:12280
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition: json.hpp:3244
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:7293
void write_characters(const CharType *s, size_t length) override
Definition: json.hpp:6658
array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:7870
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:1688
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:6537
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: json.hpp:8431
a JSON value
Definition: json.hpp:1948
void from_json(const BasicJsonType &j, ArithmeticType &val)
Definition: json.hpp:1058
bool operator==(const iter_impl &other) const
comparison: equal
Definition: json.hpp:8338
static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
deserialize from an array
Definition: json.hpp:7412
reference operator+=(basic_json &&val)
add an object to an array
Definition: json.hpp:5561
static char get_decimal_point() noexcept
return the locale-dependent decimal point
Definition: json.hpp:11067
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: json.hpp:8422
void unexpect(typename lexer::token_type t) const
Definition: json.hpp:12948
basic_json(std::initializer_list< basic_json > init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
Definition: json.hpp:2362
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition: json.hpp:3095
static std::shared_ptr< output_adapter< CharType > > create(std::ostream &s)
Definition: json.hpp:6629
exception indicating other errors
Definition: json.hpp:364
output adapter for byte vectors
Definition: json.hpp:6646
lexer::token_type get_token()
get next token from lexer
Definition: json.hpp:12917
the parser finished reading a JSON value
invalid_iterator(int id_, const char *what_arg)
Definition: json.hpp:278
iteration_proxy_internal & operator*()
dereference operator (needed for range-based for)
Definition: json.hpp:7900
primitive_iterator_t operator++(int)
Definition: json.hpp:7818
void set_begin() noexcept
set iterator to a defined beginning
Definition: json.hpp:7742
std::string get_cbor_string()
reads a CBOR string
Definition: json.hpp:9908
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:4985
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:6603
void write_character(CharType c) override
Definition: json.hpp:6676
void swap(array_t &other)
exchanges the values
Definition: json.hpp:6093
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition: json.hpp:3839
object_t * get_impl_ptr(object_t *) noexcept
get a pointer to the value (object)
Definition: json.hpp:3291
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition: json.hpp:1369
iteration_proxy(typename IteratorType::reference cont)
construct iteration proxy from a container
Definition: json.hpp:7959
basic_json(const value_t value_type)
create an empty value with a given type
Definition: json.hpp:2194
static constexpr bool value
Definition: json.hpp:776
static auto constexpr value
Definition: json.hpp:692
primitive_iterator_t operator+(difference_type i)
Definition: json.hpp:7795
reference operator[](difference_type n) const
access to successor
Definition: json.hpp:8529
void write_characters(const CharType *s, size_t length) override
Definition: json.hpp:6704
bool operator()(nlohmann::detail::value_t lhs, nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition: json.hpp:14420
static basic_json object(std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
explicitly create an object from an initializer list
Definition: json.hpp:2486
token_type scan_string()
scan a string literal
Definition: json.hpp:11358
void dump(const basic_json &val, const bool pretty_print, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition: json.hpp:6760
friend constexpr bool operator>=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7790
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition: json.hpp:3123
constexpr const array_t * get_impl_ptr(const array_t *) const noexcept
get a pointer to the value (array)
Definition: json.hpp:3309
static invalid_iterator create(int id, const std::string &what_arg)
Definition: json.hpp:271
proxy class for the iterator_wrapper functions
Definition: json.hpp:5196
static void construct(BasicJsonType &j, const std::vector< bool > &arr)
Definition: json.hpp:583
number_integer_t number_integer
number (integer)
Definition: json.hpp:1959
ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json > >> object_t
a type for an object
Definition: json.hpp:1563
string a
Definition: MakeCryptoOps.py:15
std::string const & replace(std::string &src, std::string const &to_find, std::string const &to_replace)
Definition: minicsv.h:41
void swap(string_t &other)
exchanges the values
Definition: json.hpp:6159
internal_iterator() noexcept
create an uninitialized internal_iterator
Definition: json.hpp:7875
exception(int id_, const char *what_arg)
Definition: json.hpp:158
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition: json.hpp:7760
json_value(const array_t &value)
constructor for arrays
Definition: json.hpp:2051
typename basic_json::value_type value_type
the type of the values when the iterator is dereferenced
Definition: json.hpp:8009
parse_error(int id_, size_t byte_, const char *what_arg)
Definition: json.hpp:239
const_reference get_unchecked(const_pointer ptr) const
return a const reference to the pointed to value
Definition: json.hpp:13321
int bool
Definition: stdbool.h:36
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:5817
constexpr bool is_array() const noexcept
return whether value is an array
Definition: json.hpp:3195
const_iterator end() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:5026
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:5160
lexer m_lexer
the lexer
Definition: json.hpp:12974
static auto constexpr value
Definition: json.hpp:672
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition: json.hpp:1376
detail::value_t value_t
Definition: json.hpp:1308
std::string get_string(const size_t len)
create a string by reading characters from the input
Definition: json.hpp:9884
friend constexpr bool operator<=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7780
the parser read { and started to process a JSON object
static void construct(BasicJsonType &j, const CompatibleObjectType &obj)
Definition: json.hpp:611
json_value(boolean_t v) noexcept
constructor for booleans
Definition: json.hpp:1968
friend class basic_json
allow basic_json to access private members
Definition: json.hpp:12992
basic_json(CompatibleType &&val) noexcept(noexcept(JSONSerializer< U >::to_json(std::declval< basic_json_t &>(), std::forward< CompatibleType >(val))))
create a JSON value
Definition: json.hpp:2284
static basic_json parse(IteratorType first, IteratorType last, const parser_callback_t cb=nullptr)
deserialize from an iterator range with contiguous storage
Definition: json.hpp:7553
reference operator[](size_type idx)
access specified array element
Definition: json.hpp:3987
string_t value(const typename object_t::key_type &key, const char *default_value) const
overload for a default value of type const char*
Definition: json.hpp:4364
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:5535
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:6471
reference front()
access the first element
Definition: json.hpp:4465
IteratorType::reference container
the container to iterate
Definition: json.hpp:7955
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition: json.hpp:5086
ReferenceType get_ref() const
get a reference value (implicit)
Definition: json.hpp:3704
static parse_error create(int id, size_t byte_, const std::string &what_arg)
create a parse error exception
Definition: json.hpp:218
std::size_t size_type
a type to represent container sizes
Definition: json.hpp:1361
reference value() const
return the value of an iterator
Definition: json.hpp:8699
indicating the scanner is uninitialized
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:5189
json_reverse_iterator operator--(int)
post-decrement (it–)
Definition: json.hpp:8644
iter_impl & operator+=(difference_type i)
add to iterator
Definition: json.hpp:8440
the parser read a key of a value in an object
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
Definition: json.hpp:13930
const_reference operator[](size_type idx) const
access specified array element
Definition: json.hpp:4033
void assert_invariant() const
checks the class invariants
Definition: json.hpp:2066
void call(BasicJsonType &, T &&, priority_tag< 0 >) const noexcept
Definition: json.hpp:1100
iter_impl operator-(difference_type i)
subtract from iterator
Definition: json.hpp:8491
void operator()(BasicJsonType &j, T &&val) const noexcept(noexcept(std::declval< to_json_fn >().call(j, std::forward< T >(val), priority_tag< 1 > {})))
Definition: json.hpp:1108
std::string to_string(t_connection_type type)
Definition: connection_basic.cpp:96
iter_impl & operator++()
pre-increment (++it)
Definition: json.hpp:8263
criter reverse(citer it)
Definition: utils.cpp:16
boolean_t get_impl(boolean_t *) const
get a boolean (explicit)
Definition: json.hpp:3280
token_type scan_true()
Definition: json.hpp:12268
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
comparison: not equal
Definition: json.hpp:6333
pointer operator->() const
dereference the iterator
Definition: json.hpp:8218
the character for array end ]
static bool little_endianess() noexcept
determine system byte order
Definition: json.hpp:9813
std::basic_string< CharType > & str
Definition: json.hpp:6710
json_pointer(const std::string &s="")
create JSON pointer
Definition: json.hpp:13017
void swap(object_t &other)
exchanges the values
Definition: json.hpp:6126
json_value(const object_t &value)
constructor for objects
Definition: json.hpp:2045
void dump_integer(NumberType x)
dump an integer
Definition: json.hpp:7174
static std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition: json.hpp:10801
a template for a reverse iterator class
Definition: json.hpp:1311
the character for object begin {
virtual void write_character(CharType c)=0
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition: json.hpp:12348
void call(const BasicJsonType &, T &, priority_tag< 0 >) const noexcept
Definition: json.hpp:1127
constexpr size_t get_position() const noexcept
return position of last read token
Definition: json.hpp:12372
int get_codepoint()
get codepoint from 4 hex characters following \u
Definition: json.hpp:11084
void from_json(const BasicJsonType &j, typename BasicJsonType::boolean_t &b)
Definition: json.hpp:908
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:5056
number_float_t * get_impl_ptr(number_float_t *) noexcept
get a pointer to the value (floating-point number)
Definition: json.hpp:3363
basic_json value_type
the type of elements in a basic_json container
Definition: json.hpp:1351
abstract output adapter interface
Definition: json.hpp:6617
static void strtof(long double &f, const char *str, char **endptr) noexcept
Definition: json.hpp:11886
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition: json.hpp:5621
binary_reader(input_adapter_t adapter)
create a binary reader
Definition: json.hpp:8976
other_error(int id_, const char *what_arg)
Definition: json.hpp:374
constexpr const number_unsigned_t * get_impl_ptr(const number_unsigned_t *) const noexcept
get a pointer to the value (unsigned number)
Definition: json.hpp:3357
JSON_DEPRECATED friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
Definition: json.hpp:7364
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:4856
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: json.hpp:7754
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition: json.hpp:13869
std::string get_msgpack_string()
reads a MessagePack string
Definition: json.hpp:9999
static ge_precomp base[32][8]
Definition: ge_scalarmult_base.c:30
auto call(BasicJsonType &j, T &&val, priority_tag< 1 >) const noexcept(noexcept(to_json(j, std::forward< T >(val)))) -> decltype(to_json(j, std::forward< T >(val)), void())
Definition: json.hpp:1093
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:6493
basic_json parse_cbor(const bool get_char=true)
create a JSON value from CBOR input
Definition: json.hpp:8994
void erase(const size_type idx)
remove element from a JSON array given an index
Definition: json.hpp:4806
number value (signed integer)
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:6581
pointer m_object
associated JSON instance
Definition: json.hpp:8589
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:6322
reference get_unchecked(pointer ptr) const
return a reference to the pointed to value
Definition: json.hpp:13177
bool is_root() const
return whether pointer points to the root document
Definition: json.hpp:13070
static void construct(BasicJsonType &j, typename BasicJsonType::boolean_t b) noexcept
Definition: json.hpp:502
reference operator+=(std::initializer_list< basic_json > init)
add an object to an object
Definition: json.hpp:5693
primitive_iterator_t & operator++()
Definition: json.hpp:7812
#define true
Definition: stdbool.h:37
constexpr const number_float_t * get_impl_ptr(const number_float_t *) const noexcept
get a pointer to the value (floating-point number)
Definition: json.hpp:3369
virtual const char * what() const noexcept override
returns the explanatory string
Definition: json.hpp:149
std::basic_ostream< CharType > & stream
Definition: json.hpp:6687
#define s(x, c)
Definition: aesb.c:46
std::string pop_back()
remove and return last reference pointer
Definition: json.hpp:13057
IteratorType anchor
the iterator
Definition: json.hpp:7890
std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
per-element parser callback type
Definition: json.hpp:2158
iterator insert(const_iterator pos, std::initializer_list< basic_json > ilist)
inserts elements
Definition: json.hpp:5978
object_t::key_type key() const
return the key of an object iterator
Definition: json.hpp:8566
AllocatorType< basic_json > allocator_type
the allocator type
Definition: json.hpp:1364
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition: json.hpp:6061
const_reference front() const
access the first element
Definition: json.hpp:4473
a template for a random access iterator for the basic_json class
Definition: json.hpp:1310
the parser read [ and started to process a JSON array
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition: json.hpp:8680
number value (floating-point)
const std::string & get_error_message() const noexcept
return syntax error message
Definition: json.hpp:12408
friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
Definition: json.hpp:7765
json_value m_value
the value of the current element
Definition: json.hpp:7716
std::vector< CharType > & v
Definition: json.hpp:6664
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.hpp:13805
const_reverse_iterator rend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:5131
bool empty() const noexcept
checks whether the container is empty
Definition: json.hpp:5272
std::string get_token_string() const
return the last read token (for errors only)
Definition: json.hpp:12378
void write_number(T n)
Definition: json.hpp:10607
static basic_json meta()
returns version information on the library
Definition: json.hpp:1414
constexpr const number_integer_t * get_impl_ptr(const number_integer_t *) const noexcept
get a pointer to the value (integer number)
Definition: json.hpp:3345
static void from_json(BasicJsonType &&j, ValueType &val) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), val)))
convert a JSON value to any value type
Definition: json.hpp:1182