35 #ifndef WPI_SUPPORT_JSON_H_ 36 #define WPI_SUPPORT_JSON_H_ 45 #include <initializer_list> 50 #include <type_traits> 54 #include "llvm/ArrayRef.h" 55 #include "llvm/raw_ostream.h" 56 #include "llvm/StringMap.h" 57 #include "llvm/StringRef.h" 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__) < 40800 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" 74 #pragma GCC diagnostic ignored "-Wtype-limits" 78 #if defined(__clang__) 79 #pragma GCC diagnostic push 80 #pragma GCC diagnostic ignored "-Wdocumentation" 81 #pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" 85 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) 86 #define JSON_THROW(exception) throw exception 88 #define JSON_CATCH(exception) catch(exception) 90 #define JSON_THROW(exception) std::abort() 91 #define JSON_TRY if(true) 92 #define JSON_CATCH(exception) if(false) 96 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 97 #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) 98 #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) 100 #define JSON_LIKELY(x) x 101 #define JSON_UNLIKELY(x) x 139 virtual const char*
what() const noexcept
override 149 : id(id_), m(what_arg)
156 std::runtime_error m;
220 parse_error(
int id_,
size_t byte_,
const char* what_arg)
399 static constexpr uint8_t order[] = {
416 return order[
static_cast<std::size_t
>(lhs)] <
417 order[static_cast<std::size_t>(rhs)];
426 template<
bool B,
typename T =
void>
427 using enable_if_t =
typename std::enable_if<B, T>::type;
430 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
447 template<
class B1,
class... Bn>
448 struct conjunction<B1, Bn...> : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
450 template<
class B>
struct negation : std::integral_constant < bool, !B::value > {};
466 template<
typename BasicJsonType>
467 static void construct(BasicJsonType& j,
bool b) noexcept
471 j.assert_invariant();
478 template<
typename BasicJsonType>
483 j.assert_invariant();
490 template<
typename BasicJsonType>
491 static void construct(BasicJsonType& j,
double val) noexcept
495 j.assert_invariant();
502 template<
typename BasicJsonType>
503 static void construct(BasicJsonType& j, std::uint64_t val) noexcept
507 j.assert_invariant();
514 template<
typename BasicJsonType>
515 static void construct(BasicJsonType& j, std::int64_t val) noexcept
519 j.assert_invariant();
526 template<
typename BasicJsonType>
527 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
531 j.assert_invariant();
534 template<
typename BasicJsonType,
typename T>
540 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
541 j.assert_invariant();
544 template<
typename BasicJsonType,
typename CompatibleArrayType,
545 enable_if_t<!std::is_same<CompatibleArrayType,
546 typename BasicJsonType::array_t>::value,
548 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
553 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
554 j.assert_invariant();
557 template<
typename BasicJsonType>
558 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
562 j.m_value.array->reserve(arr.size());
565 j.m_value.array->push_back(x);
567 j.assert_invariant();
574 template<
typename BasicJsonType>
575 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
579 j.assert_invariant();
582 template<
typename BasicJsonType,
typename CompatibleObjectType,
583 enable_if_t<!std::is_same<CompatibleObjectType,
584 typename BasicJsonType::object_t>::value,
586 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
590 for (
const auto& x : obj)
592 j.m_value.object->emplace_second(x.first, x.second);
594 j.assert_invariant();
613 #define WPI_JSON_HAS_HELPER(type) \ 614 template<typename T> struct has_##type { \ 616 template<typename U, typename = typename U::type> \ 617 static int detect(U &&); \ 618 static void detect(...); \ 620 static constexpr bool value = \ 621 std::is_integral<decltype(detect(std::declval<T>()))>::value; \ 624 WPI_JSON_HAS_HELPER(mapped_type);
625 WPI_JSON_HAS_HELPER(key_type);
626 WPI_JSON_HAS_HELPER(value_type);
627 WPI_JSON_HAS_HELPER(iterator);
629 #undef WPI_JSON_HAS_HELPER 632 template<
bool B,
class RealType,
class CompatibleObjectType>
635 template<
class RealType,
class CompatibleObjectType>
638 static constexpr
auto value =
640 typename CompatibleObjectType::key_type>::value &&
641 std::is_constructible<
typename RealType::mapped_type,
642 typename CompatibleObjectType::mapped_type>::value;
645 template<
typename BasicJsonType,
class CompatibleObjectType>
650 has_mapped_type<CompatibleObjectType>,
651 has_key_type<CompatibleObjectType>>::value,
652 typename BasicJsonType::object_t, CompatibleObjectType >::value;
655 template<
typename BasicJsonType,
typename T>
658 static auto constexpr value = std::is_same<T, typename BasicJsonType::iterator>::value ||
659 std::is_same<T, typename BasicJsonType::const_iterator>::value ||
660 std::is_same<T, typename BasicJsonType::json_pointer>::value;
663 template<
typename BasicJsonType,
class CompatibleArrayType>
666 static auto constexpr value =
671 has_value_type<CompatibleArrayType>,
672 has_iterator<CompatibleArrayType>>::value;
675 template<
bool,
typename,
typename>
678 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
682 using RealLimits = std::numeric_limits<RealIntegerType>;
683 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
685 static constexpr
auto value =
686 std::is_constructible<RealIntegerType,
687 CompatibleNumberIntegerType>::value &&
688 CompatibleLimits::is_integer &&
689 RealLimits::is_signed == CompatibleLimits::is_signed;
692 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
695 static constexpr
auto value =
697 std::is_integral<CompatibleNumberIntegerType>::value &&
698 !std::is_same<bool, CompatibleNumberIntegerType>::value,
699 RealIntegerType, CompatibleNumberIntegerType > ::value;
706 template<
typename BasicJsonType,
typename T, enable_if_t<
707 std::is_same<T, bool>::value,
int> = 0>
709 void to_json(BasicJsonType& j, T b) noexcept
714 template<
typename BasicJsonType,
typename CompatibleString,
716 CompatibleString>::value,
int> = 0>
718 void to_json(BasicJsonType& j,
const CompatibleString& s)
723 template<
typename BasicJsonType,
typename FloatType,
724 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
726 void to_json(BasicJsonType& j, FloatType val) noexcept
732 typename BasicJsonType,
typename CompatibleNumberUnsignedType,
734 CompatibleNumberUnsignedType>::value,
int> = 0 >
736 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
742 typename BasicJsonType,
typename CompatibleNumberIntegerType,
744 CompatibleNumberIntegerType>::value,
int> = 0 >
746 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
751 template<
typename BasicJsonType,
typename EnumType,
752 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
754 void to_json(BasicJsonType& j, EnumType e) noexcept
756 using underlying_type =
typename std::underlying_type<EnumType>::type;
760 template<
typename BasicJsonType>
762 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
767 template<
typename BasicJsonType,
typename T>
775 typename BasicJsonType,
typename CompatibleArrayType,
778 std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value,
781 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
787 typename BasicJsonType,
typename CompatibleObjectType,
788 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value,
791 void to_json(BasicJsonType& j,
const CompatibleObjectType& arr)
796 template <
typename BasicJsonType,
typename T, std::size_t N,
797 enable_if_t<!std::is_constructible<
798 llvm::StringRef, T (&)[N]>::value,
801 void to_json(BasicJsonType& j, T (&arr)[N])
806 template <
typename BasicJsonType,
typename CompatibleString,
typename T,
807 enable_if_t<std::is_constructible<llvm::StringRef,
808 CompatibleString>::value,
int> = 0>
810 void to_json(BasicJsonType& j, std::pair<CompatibleString, T>
const& p)
812 j[p.first] = p.second;
820 template<
typename BasicJsonType,
typename ArithmeticType,
821 enable_if_t<std::is_arithmetic<ArithmeticType>::value &&
822 !std::is_same<ArithmeticType, bool>::value,
824 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
826 switch (static_cast<value_t>(j))
830 val =
static_cast<ArithmeticType
>(
831 *j.template get_ptr<const std::uint64_t*>());
836 val =
static_cast<ArithmeticType
>(
837 *j.template get_ptr<const std::int64_t*>());
842 val =
static_cast<ArithmeticType
>(
843 *j.template get_ptr<const double*>());
848 JSON_THROW(type_error::create(302,
"type must be number, but is " + j.type_name()));
853 template<
typename BasicJsonType>
855 void from_json(
const BasicJsonType& j,
bool& b)
859 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + j.type_name()));
861 b = *j.template get_ptr<const bool*>();
864 template<
typename BasicJsonType>
866 void from_json(
const BasicJsonType& j,
std::string& s)
870 JSON_THROW(detail::type_error::create(302,
"type must be string, but is " + j.type_name()));
872 s = *j.template get_ptr<const std::string*>();
875 template<
typename BasicJsonType>
877 void from_json(
const BasicJsonType& j,
double& val)
879 get_arithmetic_value(j, val);
882 template<
typename BasicJsonType>
884 void from_json(
const BasicJsonType& j, std::uint64_t& val)
886 get_arithmetic_value(j, val);
889 template<
typename BasicJsonType>
891 void from_json(
const BasicJsonType& j, std::int64_t& val)
893 get_arithmetic_value(j, val);
896 template<
typename BasicJsonType,
typename EnumType,
897 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
899 void from_json(
const BasicJsonType& j, EnumType& e)
901 typename std::underlying_type<EnumType>::type val;
902 get_arithmetic_value(j, val);
903 e =
static_cast<EnumType
>(val);
906 template<
typename BasicJsonType>
908 void from_json(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr)
912 JSON_THROW(type_error::create(302,
"type must be array, but is " + j.type_name()));
914 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
917 template<
typename BasicJsonType,
typename CompatibleArrayType>
923 std::transform(j.begin(), j.end(),
924 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
928 return i.template get<typename CompatibleArrayType::value_type>();
932 template<
typename BasicJsonType,
typename CompatibleArrayType>
935 arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
941 arr.reserve(j.size());
942 std::transform(j.begin(), j.end(),
943 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
947 return i.template get<typename CompatibleArrayType::value_type>();
951 template<
typename BasicJsonType,
typename CompatibleArrayType,
952 enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value &&
953 std::is_convertible<BasicJsonType, typename CompatibleArrayType::value_type>::value &&
954 !std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value,
int> = 0>
955 void from_json(
const BasicJsonType& j, CompatibleArrayType& arr)
959 JSON_THROW(type_error::create(302,
"type must be array, but is " + j.type_name()));
965 template<
typename BasicJsonType>
967 void from_json(
const BasicJsonType& j,
typename BasicJsonType::object_t& obj)
971 JSON_THROW(type_error::create(302,
"type must be object, but is " + j.type_name()));
974 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
975 for (
const auto& i : *inner_object) {
976 obj.emplace_second(i.first(), i.second);
980 template<
typename BasicJsonType,
typename CompatibleObjectType,
981 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value &&
982 !std::is_same<typename BasicJsonType::object_t, CompatibleObjectType>::value,
int> = 0>
983 void from_json(
const BasicJsonType& j, CompatibleObjectType& obj)
987 JSON_THROW(type_error::create(302,
"type must be object, but is " + j.type_name()));
990 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
993 using value_type =
typename CompatibleObjectType::value_type;
994 std::vector<value_type> v;
996 for (
const auto& p : *inner_object)
1001 .template get<typename CompatibleObjectType::mapped_type>());
1006 obj = CompatibleObjectType(std::make_move_iterator(begin(v)),
1007 std::make_move_iterator(end(v)));
1011 template<
typename BasicJsonType,
typename ArithmeticType,
1013 std::is_arithmetic<ArithmeticType>::value &&
1014 !std::is_same<ArithmeticType, std::uint64_t>::value &&
1015 !std::is_same<ArithmeticType, std::int64_t>::value &&
1016 !std::is_same<ArithmeticType, double>::value &&
1017 !std::is_same<ArithmeticType, bool>::value,
1019 void from_json(
const BasicJsonType& j, ArithmeticType& val)
1021 switch (static_cast<value_t>(j))
1025 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const std::uint64_t*>());
1030 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const std::int64_t*>());
1035 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const double*>());
1040 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const bool*>());
1045 JSON_THROW(type_error::create(302,
"type must be number, but is " + j.type_name()));
1050 template <
typename BasicJsonType,
typename CompatibleString,
typename T,
1051 enable_if_t<std::is_constructible<llvm::StringRef,
1052 CompatibleString>::value,
int> = 0>
1053 void from_json(
const BasicJsonType& j, std::pair<CompatibleString, T>& p)
1057 JSON_THROW(type_error::create(302,
"type must be object, but is " + j.type_name()));
1060 auto const inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
1061 auto const size = inner_object->size();
1064 JSON_THROW(other_error::create(502,
"conversion to std::pair requires the object to have exactly one field, but it has " + std::to_string(size)));
1066 auto const& obj = *inner_object->begin();
1068 p = std::make_pair(CompatibleString(obj.first()), obj.second.template get<T>());
1074 template<
typename BasicJsonType,
typename T>
1075 auto call(BasicJsonType& j, T&& val,
priority_tag<1>)
const noexcept(noexcept(to_json(j, std::forward<T>(val))))
1076 -> decltype(to_json(j, std::forward<T>(val)),
void())
1078 return to_json(j, std::forward<T>(val));
1081 template<
typename BasicJsonType,
typename T>
1084 static_assert(
sizeof(BasicJsonType) == 0,
1085 "could not find to_json() method in T's namespace");
1089 template<
typename BasicJsonType,
typename T>
1090 void operator()(BasicJsonType& j, T&& val)
const 1091 noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val),
priority_tag<1> {})))
1100 template<
typename BasicJsonType,
typename T>
1102 noexcept(noexcept(from_json(j, val)))
1103 -> decltype(from_json(j, val),
void())
1105 return from_json(j, val);
1108 template<
typename BasicJsonType,
typename T>
1111 static_assert(
sizeof(BasicJsonType) == 0,
1112 "could not find from_json() method in T's namespace");
1116 template<
typename BasicJsonType,
typename T>
1117 void operator()(
const BasicJsonType& j, T& val)
const 1118 noexcept(noexcept(std::declval<from_json_fn>().call(j, val,
priority_tag<1> {})))
1125 template<
typename T>
1128 static constexpr T value{};
1131 template<
typename T>
1205 friend class JsonTest;
1683 template<
typename T,
typename... Args>
1684 static T* create(Args&& ... args)
1686 std::allocator<T> alloc;
1687 auto deleter = [&](T *
object)
1689 alloc.deallocate(
object, 1);
1691 std::unique_ptr<T, decltype(deleter)>
object(alloc.allocate(1), deleter);
1692 alloc.construct(
object.
get(), std::forward<Args>(args)...);
1693 assert(
object !=
nullptr);
1694 return object.release();
1777 void assert_invariant()
const 1906 : m_type(value_type), m_value(value_type)
1929 json(std::nullptr_t =
nullptr) noexcept
1988 template<
typename CompatibleType,
typename U = detail::uncvref_t<CompatibleType>,
1989 detail::enable_if_t<!std::is_base_of<wpi::raw_istream, U>::value &&
1990 !std::is_same<U, json>::value &&
1991 !detail::is_json_nested_type<json, U>::value,
1995 to_json(*
this, std::forward<CompatibleType>(val));
2070 json(std::initializer_list<json> init,
2071 bool type_deduction =
true,
2109 std::initializer_list<json>())
2150 std::initializer_list<json>())
2217 template<
class InputIT,
typename std::enable_if<
2218 std::is_same<InputIT, json::iterator>::value ||
2219 std::is_same<InputIT, json::const_iterator>::value,
int>::type = 0>
2222 assert(first.m_object !=
nullptr);
2223 assert(last.m_object !=
nullptr);
2226 if (first.m_object != last.m_object)
2228 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible"));
2232 m_type = first.m_object->m_type;
2243 if (!first.m_it.primitive_iterator.is_begin() || !last.m_it.primitive_iterator.is_end())
2245 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
2260 m_value.number_integer = first.m_object->m_value.number_integer;
2266 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
2272 m_value.number_float = first.m_object->m_value.number_float;
2278 m_value.boolean = first.m_object->m_value.boolean;
2284 m_value = *first.m_object->m_value.string;
2290 m_value.array = create<array_t>(first.m_it.array_iterator,
2291 last.m_it.array_iterator);
2297 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " +
2298 first.m_object->type_name()));
2351 : m_type(
std::move(other.m_type)),
2352 m_value(
std::move(other.m_value))
2355 other.assert_invariant();
2388 std::is_nothrow_move_constructible<value_t>::value &&
2389 std::is_nothrow_move_assignable<value_t>::value &&
2390 std::is_nothrow_move_constructible<json_value>::value &&
2391 std::is_nothrow_move_assignable<json_value>::value
2395 other.assert_invariant();
2398 swap(m_type, other.m_type);
2399 swap(m_value, other.m_value);
2532 return is_null() || is_string() || is_boolean() || is_number();
2559 return is_array() || is_object();
2633 return is_number_integer() || is_number_float();
2845 bool get_impl(
bool* )
const 2849 return m_value.boolean;
2852 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + type_name()));
2858 return is_object() ? m_value.object :
nullptr;
2864 return is_object() ? m_value.object :
nullptr;
2870 return is_array() ? m_value.array :
nullptr;
2876 return is_array() ? m_value.array :
nullptr;
2882 return is_string() ? m_value.string :
nullptr;
2888 return is_string() ? m_value.string :
nullptr;
2892 bool* get_impl_ptr(
bool* ) noexcept
2894 return is_boolean() ? &m_value.boolean :
nullptr;
2898 const bool* get_impl_ptr(
const bool* )
const noexcept
2900 return is_boolean() ? &m_value.boolean :
nullptr;
2904 std::int64_t* get_impl_ptr(std::int64_t* ) noexcept
2906 return is_number_integer() ? &m_value.number_integer :
nullptr;
2910 const std::int64_t* get_impl_ptr(
const std::int64_t* )
const noexcept
2912 return is_number_integer() ? &m_value.number_integer :
nullptr;
2916 std::uint64_t* get_impl_ptr(std::uint64_t* ) noexcept
2918 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
2922 const std::uint64_t* get_impl_ptr(
const std::uint64_t* )
const noexcept
2924 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
2928 double* get_impl_ptr(
double* ) noexcept
2930 return is_number_float() ? &m_value.number_float :
nullptr;
2934 const double* get_impl_ptr(
const double* )
const noexcept
2936 return is_number_float() ? &m_value.number_float :
nullptr;
2950 template<
typename ReferenceType,
typename ThisType>
2951 static ReferenceType get_ref_impl(ThisType& obj)
2954 using PointerType =
typename std::add_pointer<ReferenceType>::type;
2957 auto ptr = obj.template get_ptr<PointerType>();
2964 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + obj.type_name()));
2987 typename BasicJsonType,
2988 detail::enable_if_t<std::is_same<typename std::remove_const<BasicJsonType>::type,
3036 typename ValueTypeCV,
3037 typename ValueType = detail::uncvref_t<ValueTypeCV>,
3038 detail::enable_if_t < !std::is_same<json, ValueType>::value,
int > = 0 >
3039 ValueType
get()
const 3044 static_assert(!std::is_reference<ValueTypeCV>::value,
3045 "get() cannot be used with reference types, you might want to use get_ref()");
3046 static_assert(std::is_default_constructible<ValueType>::value,
3047 "types must be DefaultConstructible when used with get()");
3050 from_json(*
this, ret);
3081 template<
typename PointerType,
typename std::enable_if<
3082 std::is_pointer<PointerType>::value,
int>::type = 0>
3083 PointerType
get() noexcept
3086 return get_ptr<PointerType>();
3093 template<
typename PointerType,
typename std::enable_if<
3094 std::is_pointer<PointerType>::value,
int>::type = 0>
3095 const PointerType
get()
const noexcept
3098 return get_ptr<PointerType>();
3127 template<
typename PointerType,
typename std::enable_if<
3128 std::is_pointer<PointerType>::value,
int>::type = 0>
3132 using pointee_t =
typename std::remove_const<
typename 3133 std::remove_pointer<
typename 3134 std::remove_const<PointerType>::type>::type>::type;
3137 std::is_same<object_t, pointee_t>::value
3138 || std::is_same<array_t, pointee_t>::value
3139 || std::is_same<std::string, pointee_t>::value
3140 || std::is_same<bool, pointee_t>::value
3141 || std::is_same<std::int64_t, pointee_t>::value
3142 || std::is_same<std::uint64_t, pointee_t>::value
3143 || std::is_same<double, pointee_t>::value
3144 ,
"incompatible pointer type");
3147 return get_impl_ptr(static_cast<PointerType>(
nullptr));
3154 template<
typename PointerType,
typename std::enable_if<
3155 std::is_pointer<PointerType>::value &&
3156 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int>::type = 0>
3160 using pointee_t =
typename std::remove_const<
typename 3161 std::remove_pointer<
typename 3162 std::remove_const<PointerType>::type>::type>::type;
3165 std::is_same<object_t, pointee_t>::value
3166 || std::is_same<array_t, pointee_t>::value
3167 || std::is_same<std::string, pointee_t>::value
3168 || std::is_same<bool, pointee_t>::value
3169 || std::is_same<std::int64_t, pointee_t>::value
3170 || std::is_same<std::uint64_t, pointee_t>::value
3171 || std::is_same<double, pointee_t>::value
3172 ,
"incompatible pointer type");
3175 return get_impl_ptr(static_cast<const PointerType>(
nullptr));
3204 template<
typename ReferenceType,
typename std::enable_if<
3205 std::is_reference<ReferenceType>::value,
int>::type = 0>
3209 return get_ref_impl<ReferenceType>(*this);
3216 template<
typename ReferenceType,
typename std::enable_if<
3217 std::is_reference<ReferenceType>::value &&
3218 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int>::type = 0>
3222 return get_ref_impl<ReferenceType>(*this);
3254 template <
typename ValueType,
typename std::enable_if <
3255 !std::is_pointer<ValueType>::value &&
3256 !std::is_same<ValueType, std::string::value_type>::value
3257 #ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015 3258 && !std::is_same<ValueType, std::initializer_list<std::string::value_type>>::value
3260 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER >1900 && defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 3261 && !std::is_same<ValueType, typename std::string_view>::value
3264 operator ValueType()
const 3267 return get<ValueType>();
3537 template<
typename T, std::
size_t n>
3540 return operator[](static_cast<const T>(key));
3572 template<
typename T, std::
size_t n>
3575 return operator[](static_cast<const T>(key));
3605 template<
typename T>
3641 template<
typename T>
3695 template<
class ValueType,
typename std::enable_if<
3696 std::is_convertible<json, ValueType>::value,
int>::type = 0>
3703 const auto it = find(key);
3709 return default_value;
3713 JSON_THROW(type_error::create(306,
"cannot use value() with " + type_name()));
3767 template<
class ValueType,
typename std::enable_if<
3768 std::is_convertible<json, ValueType>::value,
int>::type = 0>
3777 return ptr.get_checked(
this);
3781 return default_value;
3785 JSON_THROW(type_error::create(306,
"cannot use value() with " + type_name()));
3917 template<
class IteratorType,
typename std::enable_if<
3918 std::is_same<IteratorType, json::iterator>::value ||
3919 std::is_same<IteratorType, json::const_iterator>::value,
int>::type
3924 if (
this != pos.m_object)
3926 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
3937 if (!pos.m_it.primitive_iterator.is_begin())
3939 JSON_THROW(invalid_iterator::create(205,
"iterator out of range"));
3944 std::allocator<std::string> alloc;
3945 alloc.destroy(m_value.string);
3946 alloc.deallocate(m_value.string, 1);
3947 m_value.string =
nullptr;
3957 m_value.object->erase(pos.m_it.object_iterator);
3963 m_value.array->erase(pos.m_it.array_iterator);
3969 JSON_THROW(type_error::create(307,
"cannot use erase() with " + type_name()));
4020 template<
class IteratorType,
typename std::enable_if<
4021 std::is_same<IteratorType, json::iterator>::value ||
4022 std::is_same<IteratorType, json::const_iterator>::value,
int>::type
4024 void erase(IteratorType first, IteratorType last)
4027 if (
this != first.m_object ||
this != last.m_object)
4029 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value"));
4040 if (!first.m_it.primitive_iterator.is_begin() || !last.m_it.primitive_iterator.is_end())
4042 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
4047 std::allocator<std::string> alloc;
4048 alloc.destroy(m_value.string);
4049 alloc.deallocate(m_value.string, 1);
4050 m_value.string =
nullptr;
4060 m_value.array->erase(first.m_it.array_iterator,
4061 last.m_it.array_iterator);
4067 JSON_THROW(type_error::create(307,
"cannot use erase() with " + type_name()));
4193 return is_object() ? m_value.object->count(key) : 0;
4350 template<
typename IteratorType>
class iteration_proxy;
4368 return iteration_proxy<iterator>(cont);
4376 return iteration_proxy<const_iterator>(cont);
4426 bool empty()
const noexcept;
4538 void clear() noexcept;
4560 void push_back(
json&& val);
4568 push_back(std::move(val));
4576 void push_back(
const json& val);
4608 void push_back(
const std::pair<llvm::StringRef, json>& val);
4645 void push_back(std::initializer_list<json> init);
4678 template<
class... Args>
4682 if (!(is_null() || is_array()))
4684 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + type_name()));
4696 m_value.array->emplace_back(std::forward<Args>(args)...);
4726 template<
class... Args>
4730 if (!(is_null() || is_object()))
4732 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + type_name()));
4744 auto res = m_value.object->emplace_second(key, std::forward<Args>(args)...);
4747 it.m_it.object_iterator = res.first;
4750 return {it, res.second};
4783 return insert(pos, val);
4913 std::is_nothrow_move_constructible<value_t>::value &&
4914 std::is_nothrow_move_assignable<value_t>::value &&
4915 std::is_nothrow_move_constructible<json_value>::value &&
4916 std::is_nothrow_move_assignable<json_value>::value
4919 std::swap(m_type, other.m_type);
4920 std::swap(m_value, other.m_value);
4949 std::swap(*(m_value.array), other);
4953 JSON_THROW(type_error::create(310,
"cannot use swap() with " + type_name()));
4982 std::swap(*(m_value.object), other);
4986 JSON_THROW(type_error::create(310,
"cannot use swap() with " + type_name()));
5015 std::swap(*(m_value.string), other);
5019 JSON_THROW(type_error::create(310,
"cannot use swap() with " + type_name()));
5066 template<
typename ScalarType,
typename std::enable_if<
5067 std::is_scalar<ScalarType>::value,
int>::type = 0>
5070 return (lhs ==
json(rhs));
5077 template<
typename ScalarType,
typename std::enable_if<
5078 std::is_scalar<ScalarType>::value,
int>::type = 0>
5081 return (
json(lhs) == rhs);
5102 return !(lhs == rhs);
5109 template<
typename ScalarType,
typename std::enable_if<
5110 std::is_scalar<ScalarType>::value,
int>::type = 0>
5113 return (lhs !=
json(rhs));
5120 template<
typename ScalarType,
typename std::enable_if<
5121 std::is_scalar<ScalarType>::value,
int>::type = 0>
5124 return (
json(lhs) != rhs);
5157 template<
typename ScalarType,
typename std::enable_if<
5158 std::is_scalar<ScalarType>::value,
int>::type = 0>
5161 return (lhs <
json(rhs));
5168 template<
typename ScalarType,
typename std::enable_if<
5169 std::is_scalar<ScalarType>::value,
int>::type = 0>
5172 return (
json(lhs) < rhs);
5194 return !(rhs < lhs);
5201 template<
typename ScalarType,
typename std::enable_if<
5202 std::is_scalar<ScalarType>::value,
int>::type = 0>
5205 return (lhs <=
json(rhs));
5212 template<
typename ScalarType,
typename std::enable_if<
5213 std::is_scalar<ScalarType>::value,
int>::type = 0>
5216 return (
json(lhs) <= rhs);
5238 return !(lhs <= rhs);
5245 template<
typename ScalarType,
typename std::enable_if<
5246 std::is_scalar<ScalarType>::value,
int>::type = 0>
5249 return (lhs >
json(rhs));
5256 template<
typename ScalarType,
typename std::enable_if<
5257 std::is_scalar<ScalarType>::value,
int>::type = 0>
5260 return (
json(lhs) > rhs);
5282 return !(lhs < rhs);
5289 template<
typename ScalarType,
typename std::enable_if<
5290 std::is_scalar<ScalarType>::value,
int>::type = 0>
5293 return (lhs >=
json(rhs));
5300 template<
typename ScalarType,
typename std::enable_if<
5301 std::is_scalar<ScalarType>::value,
int>::type = 0>
5304 return (
json(lhs) >= rhs);
5500 class primitive_iterator_t
5509 void set_begin() noexcept
5515 void set_end() noexcept
5521 constexpr
bool is_begin()
const noexcept
5523 return (m_it == begin_value);
5527 constexpr
bool is_end()
const noexcept
5529 return (m_it == end_value);
5532 friend constexpr
bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5534 return lhs.m_it == rhs.m_it;
5537 friend constexpr
bool operator!=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5539 return !(lhs == rhs);
5542 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5544 return lhs.m_it < rhs.m_it;
5547 friend constexpr
bool operator<=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5549 return lhs.m_it <= rhs.m_it;
5552 friend constexpr
bool operator>(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5554 return lhs.m_it > rhs.m_it;
5557 friend constexpr
bool operator>=(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5559 return lhs.m_it >= rhs.m_it;
5564 auto result = *
this;
5569 friend constexpr
difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
5571 return lhs.m_it - rhs.m_it;
5576 return os << it.m_it;
5579 primitive_iterator_t& operator++()
5585 primitive_iterator_t operator++(
int)
5587 auto result = *
this;
5592 primitive_iterator_t& operator--()
5598 primitive_iterator_t operator--(
int)
5600 auto result = *
this;
5622 difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
5632 struct internal_iterator
5637 typename array_t::iterator array_iterator;
5639 primitive_iterator_t primitive_iterator;
5642 internal_iterator() noexcept
5643 : object_iterator(), array_iterator(), primitive_iterator()
5648 template<
typename IteratorType>
5649 class iteration_proxy
5653 class iteration_proxy_internal
5657 IteratorType anchor;
5659 size_t array_index = 0;
5662 explicit iteration_proxy_internal(IteratorType it) noexcept
5667 iteration_proxy_internal& operator*()
5673 iteration_proxy_internal& operator++()
5682 bool operator!= (
const iteration_proxy_internal& o)
const 5684 return anchor != o.anchor;
5690 assert(anchor.m_object !=
nullptr);
5692 switch (anchor.m_object->type())
5697 return std::to_string(array_index);
5703 return anchor.key();
5715 typename IteratorType::reference value()
const 5717 return anchor.value();
5722 typename IteratorType::reference container;
5726 explicit iteration_proxy(
typename IteratorType::reference cont)
5731 iteration_proxy_internal begin() noexcept
5733 return iteration_proxy_internal(container.begin());
5737 iteration_proxy_internal end() noexcept
5739 return iteration_proxy_internal(container.end());
5763 template<
typename U>
5764 class iter_impl :
public std::iterator<std::random_access_iterator_tag, U>
5768 friend class JsonTest;
5771 static_assert(std::is_same<U, json>::value
5772 || std::is_same<U, const json>::value,
5773 "iter_impl only accepts (const) json");
5781 using pointer =
typename std::conditional<std::is_const<U>::value,
5785 using reference =
typename std::conditional<std::is_const<U>::value,
5803 assert(m_object !=
nullptr);
5805 switch (m_object->m_type)
5815 m_it.array_iterator =
typename array_t::iterator();
5821 m_it.primitive_iterator = primitive_iterator_t();
5843 : m_object(other.m_object), m_it(other.m_it)
5854 m_object = other.m_object;
5864 void set_begin() noexcept
5866 assert(m_object !=
nullptr);
5868 switch (m_object->m_type)
5872 m_it.object_iterator = m_object->m_value.object->begin();
5878 m_it.array_iterator = m_object->m_value.array->begin();
5882 case json::value_t::null:
5885 m_it.primitive_iterator.set_end();
5891 m_it.primitive_iterator.set_begin();
5901 void set_end() noexcept
5903 assert(m_object !=
nullptr);
5905 switch (m_object->m_type)
5909 m_it.object_iterator = m_object->m_value.object->end();
5915 m_it.array_iterator = m_object->m_value.array->end();
5921 m_it.primitive_iterator.set_end();
5934 assert(m_object !=
nullptr);
5936 switch (m_object->m_type)
5940 assert(m_it.object_iterator != m_object->m_value.object->end());
5941 return m_it.object_iterator->second;
5946 assert(m_it.array_iterator != m_object->m_value.array->end());
5947 return *m_it.array_iterator;
5950 case json::value_t::null:
5952 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
5957 if (m_it.primitive_iterator.is_begin())
5962 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
5973 assert(m_object !=
nullptr);
5975 switch (m_object->m_type)
5979 assert(m_it.object_iterator != m_object->m_value.object->end());
5980 return &(m_it.object_iterator->second);
5985 assert(m_it.array_iterator != m_object->m_value.array->end());
5986 return &*m_it.array_iterator;
5991 if (m_it.primitive_iterator.is_begin())
5996 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
6007 auto result = *
this;
6018 assert(m_object !=
nullptr);
6020 switch (m_object->m_type)
6024 ++m_it.object_iterator;
6030 ++m_it.array_iterator;
6036 ++m_it.primitive_iterator;
6050 auto result = *
this;
6061 assert(m_object !=
nullptr);
6063 switch (m_object->m_type)
6067 JSON_THROW(invalid_iterator::create(209,
"cannot decrement object iterators"));
6073 std::advance(m_it.array_iterator, -1);
6079 --m_it.primitive_iterator;
6094 if (m_object != other.m_object)
6096 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
6099 assert(m_object !=
nullptr);
6101 switch (m_object->m_type)
6105 return (m_it.object_iterator == other.m_it.object_iterator);
6110 return (m_it.array_iterator == other.m_it.array_iterator);
6115 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
6126 return !operator==(other);
6136 if (m_object != other.m_object)
6138 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
6141 assert(m_object !=
nullptr);
6143 switch (m_object->m_type)
6147 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
6152 return (m_it.array_iterator < other.m_it.array_iterator);
6157 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
6168 return !(other.operator < (*this));
6177 return !operator<=(other);
6195 assert(m_object !=
nullptr);
6197 switch (m_object->m_type)
6201 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
6206 std::advance(m_it.array_iterator, i);
6212 m_it.primitive_iterator += i;
6226 return operator+=(-i);
6235 auto result = *
this;
6257 auto result = *
this;
6268 assert(m_object !=
nullptr);
6270 switch (m_object->m_type)
6274 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
6279 return m_it.array_iterator - other.m_it.array_iterator;
6284 return m_it.primitive_iterator - other.m_it.primitive_iterator;
6295 assert(m_object !=
nullptr);
6297 switch (m_object->m_type)
6301 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
6306 return *std::next(m_it.array_iterator, n);
6309 case json::value_t::null:
6311 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
6316 if (m_it.primitive_iterator.get_value() == -n)
6321 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
6332 assert(m_object !=
nullptr);
6334 if (m_object->is_object())
6336 return m_it.object_iterator->first();
6339 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
6355 struct internal_iterator m_it = internal_iterator();
6706 friend class JsonTest;
6732 : reference_tokens(split(s))
6767 JSON_THROW(out_of_range::create(405,
"JSON pointer has no parent"));
6770 auto last = reference_tokens.back();
6771 reference_tokens.pop_back();
6776 bool is_root()
const 6778 return reference_tokens.empty();
6785 JSON_THROW(out_of_range::create(405,
"JSON pointer has no parent"));
6789 result.reference_tokens = {reference_tokens[0]};
6864 static std::vector<std::string> split(
const std::string& reference_string);
6896 static void flatten(
const std::string& reference_string,
6910 static json unflatten(
const json& value);
6915 return lhs.reference_tokens == rhs.reference_tokens;
6921 return !(lhs == rhs);
6925 std::vector<std::string> reference_tokens {};
6970 return ptr.get_unchecked(
this);
6998 return ptr.get_unchecked(
this);
7038 return ptr.get_checked(
this);
7078 return ptr.get_checked(
this);
7106 json_pointer::flatten(
"", *
this, result);
7142 return json_pointer::unflatten(*
this);
7166 is_nothrow_move_constructible<wpi::json>::value &&
7167 is_nothrow_move_assignable<wpi::json>::value
7182 std::size_t operator()(
const wpi::json& j)
const;
7215 inline wpi::json operator "" _json(
const char* s, std::size_t n)
7238 #ifndef WPI_JSON_IMPLEMENTATION 7241 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 7242 #pragma GCC diagnostic pop 7244 #if defined(__clang__) 7245 #pragma GCC diagnostic pop 7253 #undef JSON_UNLIKELY 7255 #endif // WPI_JSON_IMPLEMENTATION friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
comparison: equal
Definition: json.h:5068
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.h:5079
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.h:5236
std::vector< json > array_t
a type for an array
Definition: json.h:1406
const_reference operator[](T *key) const
read-only access specified object element
Definition: json.h:3642
void swap(array_t &other)
exchanges the values
Definition: json.h:4944
reference front()
access the first element
Definition: json.h:3822
iter_impl & operator++()
pre-increment (++it)
Definition: json.h:6016
bool is_null() const noexcept
return whether value is null
Definition: json.h:2579
std::uint64_t number_unsigned
number (unsigned integer)
Definition: json.h:1739
static json array(std::initializer_list< json > init=std::initializer_list< json >())
explicitly create an array from an initializer list
Definition: json.h:2108
serialization to CBOR and MessagePack values
Definition: json_binary_writer.cpp:51
reference operator+=(const json &val)
add an object to an array
Definition: json.h:4582
iter_impl operator--(int)
post-decrement (it–)
Definition: json.h:6048
bool is_discarded() const noexcept
return whether value is discarded
Definition: json.h:2809
static json parse(llvm::StringRef s, const parser_callback_t cb=nullptr)
deserialize from string literal
Definition: json_parser.cpp:2076
json(const value_t value_type)
create an empty value with a given type
Definition: json.h:1905
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.h:4301
void erase(IteratorType pos)
remove element given an iterator
Definition: json.h:3921
bool operator!=(const iter_impl &other) const
comparison: not equal
Definition: json.h:6124
bool operator==(const iter_impl &other) const
comparison: equal
Definition: json.h:6091
llvm::StringRef key() const
return the key of an object iterator
Definition: json.h:6330
ValueType value(llvm::StringRef key, ValueType default_value) const
access specified object element with default value
Definition: json.h:3697
typename std::conditional< std::is_const< U >::value, typename json::const_pointer, typename json::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition: json.h:5783
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.h:7076
json(CompatibleType &&val)
create a JSON value
Definition: json.h:1993
void erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition: json.h:4024
syntax analysis
Definition: json_parser.cpp:1603
iter_impl & operator--()
pre-decrement (–it)
Definition: json.h:6059
reference operator[](difference_type n) const
access to successor
Definition: json.h:6293
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
comparison: not equal
Definition: json.h:5111
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition: json.h:4270
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition: json.h:5800
const value_type & const_reference
the type of an element const reference
Definition: json.h:1256
std::string value(const json_pointer &ptr, const char *default_value) const
overload for a default value of type const char*
Definition: json.h:3792
number value (unsigned integer)
Definition: json.cpp:1170
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.h:5214
value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.h:2500
bool is_structured() const noexcept
return whether type is structured
Definition: json.h:2557
iterator begin() noexcept
returns an iterator to the first element
Definition: json.h:4230
std::pair< iterator, bool > emplace(llvm::StringRef key, Args &&...args)
add an object to an object if key does not exist
Definition: json.h:4727
discarded by the the parser callback function
std::string value(llvm::StringRef key, const char *default_value) const
overload for a default value of type const char*
Definition: json.h:3721
reference operator[](T *key)
access specified object element
Definition: json.h:3606
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.h:5302
bool is_number_integer() const noexcept
return whether value is an integer number
Definition: json.h:2660
Definition: SocketError.cpp:18
const_iterator end() const noexcept
returns a const iterator to one past the last element
Definition: json.h:4311
reference & operator=(json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
copy assignment
Definition: json.h:2387
a JSON value
Definition: json.h:1726
json value_type
the type of elements in a json container
Definition: json.h:1251
void swap(std::string &other)
exchanges the values
Definition: json.h:5010
virtual const char * what() const noexceptoverride
returns the explanatory string
Definition: json.h:139
json(json &&other) noexcept
move constructor
Definition: json.h:2350
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.h:7036
void swap(object_t &other)
exchanges the values
Definition: json.h:4977
bool is_boolean() const noexcept
return whether value is a boolean
Definition: json.h:2601
typename std::conditional< std::is_const< U >::value, typename json::const_reference, typename json::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition: json.h:5787
iterator insert(const_iterator pos, json &&val)
inserts element
Definition: json.h:4781
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
iter_impl operator+(difference_type i) const
add to iterator
Definition: json.h:6233
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.h:3206
typename json::difference_type difference_type
a type to represent differences between iterators
Definition: json.h:5779
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: json.h:6166
json_value(std::uint64_t v) noexcept
constructor for numbers (unsigned)
Definition: json.h:1750
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than
Definition: json.h:5247
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.h:3129
std::string * string
string (stored with pointer to save storage)
Definition: json.h:1733
Definition: raw_istream.h:23
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: json.h:6184
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.h:6968
wrapper around the serialization functions
Definition: json_serializer.h:46
std::bidirectional_iterator_tag iterator_category
the category of the iterator
Definition: json.h:5789
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: json.h:5932
bool is_array() const noexcept
return whether value is an array
Definition: json.h:2760
const size_t byte
byte index of the parse error
Definition: json.h:217
bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition: json.h:2688
static json object(std::initializer_list< json > init=std::initializer_list< json >())
explicitly create an object from an initializer list
Definition: json.h:2149
const int id
the id of the exception
Definition: json.h:145
json(std::nullptr_t=nullptr) noexcept
create a null object
Definition: json.h:1929
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than or equal
Definition: json.h:5203
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition: json.h:6244
iter_impl operator-(difference_type i) const
subtract from iterator
Definition: json.h:6255
object (unordered set of name/value pairs)
exception indicating access out of the defined range
Definition: json.h:311
number value (signed integer)
ReferenceType get_ref() const
get a reference value (implicit)
Definition: json.h:3219
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: json.h:6133
general exception of the json class
Definition: json.h:135
array (ordered collection of values)
reference operator+=(json &&val)
add an object to an array
Definition: json.h:4566
static iteration_proxy< iterator > iterator_wrapper(reference cont)
wrapper to access iterator member functions in range-based for
Definition: json.h:4366
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.h:5280
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.h:5192
uint64_t number_unsigned_t
a type for a number (unsigned)
Definition: json.h:1612
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition: json.h:397
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition: json.h:4912
size_type count(llvm::StringRef key) const
returns the number of occurrences of a key in a JSON object
Definition: json.h:4190
bool is_string() const noexcept
return whether value is a string
Definition: json.h:2782
exception indicating other errors
Definition: json.h:334
const json * const_pointer
the type of an element const pointer
Definition: json.h:1266
iter_impl & operator+=(difference_type i)
add to iterator
Definition: json.h:6193
std::string string_t
a type for a string
Definition: json.h:1455
bool boolean
boolean
Definition: json.h:1735
json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition: json.h:2220
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than
Definition: json.h:5159
static iteration_proxy< const_iterator > iterator_wrapper(const_reference cont)
wrapper to access iterator member functions in range-based for
Definition: json.h:4374
std::function< bool(int depth, parse_event_t event, json &parsed)> parser_callback_t
per-element parser callback type
Definition: json.h:1869
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.h:5122
int64_t number_integer_t
a type for a number (integer)
Definition: json.h:1545
double number_float_t
a type for a number (floating-point)
Definition: json.h:1676
ValueType value(const json_pointer &ptr, ValueType default_value) const
access specified object element via JSON Pointer with default value
Definition: json.h:3769
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.h:5258
a class to store JSON values
Definition: json.h:1201
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:202
double number_float
number (floating-point)
Definition: json.h:1741
bool is_number() const noexcept
return whether value is a number
Definition: json.h:2631
exception indicating a parse error
Definition: json.h:194
exception indicating errors with iterators
Definition: json.h:249
bool is_number_float() const noexcept
return whether value is a floating-point number
Definition: json.h:2716
iter_impl() noexcept
default constructor
Definition: json.h:5792
const PointerType get_ptr() const noexcept
get a pointer value (implicit)
Definition: json.h:3157
iter_impl & operator=(const iter_impl< json > &other) noexcept
converting assignment
Definition: json.h:5852
bool is_object() const noexcept
return whether value is an object
Definition: json.h:2738
std::size_t size_type
a type to represent container sizes
Definition: json.h:1261
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: json.h:6224
reference operator[](T *(&key)[n])
access specified object element
Definition: json.h:3538
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than or equal
Definition: json.h:5291
json unflatten() const
unflatten a previously flattened JSON value
Definition: json.h:7140
JSON Pointer.
Definition: json.h:6702
const_reference operator[](T *(&key)[n]) const
read-only access specified object element
Definition: json.h:3573
array_t * array
array (stored with pointer to save storage)
Definition: json.h:1731
Definition: StringMap.h:29
json_pointer(const std::string &s="")
create JSON pointer
Definition: json.h:6731
json_value(bool v) noexcept
constructor for booleans
Definition: json.h:1746
iter_impl operator++(int)
post-increment (it++)
Definition: json.h:6005
exception indicating executing a member function with a wrong type
Definition: json.h:284
reference operator+=(const std::pair< llvm::StringRef, json > &val)
add an object to an object
Definition: json.h:4614
iter_impl(const iter_impl< json > &other) noexcept
converting constructor
Definition: json.h:5842
std::int64_t number_integer
number (integer)
Definition: json.h:1737
difference_type operator-(const iter_impl &other) const
return difference
Definition: json.h:6266
bool boolean_t
a type for a boolean
Definition: json.h:1477
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.h:6996
value_t
the JSON type enumeration
Definition: json.h:375
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: json.h:6175
json_value(double v) noexcept
constructor for numbers (floating-point)
Definition: json.h:1752
const_reference front() const
access the first element
Definition: json.h:3830
reference value() const
return the value of an iterator
Definition: json.h:6346
pointer operator->() const
dereference the iterator
Definition: json.h:5971
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.h:4341
void emplace_back(Args &&...args)
add an object to an array
Definition: json.h:4679
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33
json_value(std::int64_t v) noexcept
constructor for numbers (integer)
Definition: json.h:1748
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
parse_event_t
JSON callback events.
Definition: json.h:1799
const_iterator begin() const noexcept
returns a const iterator to the first element
Definition: json.h:4240
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.h:1259
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.h:5170
a template for a random access iterator for the json class
Definition: json.h:1210
number value (floating-point)
typename json::value_type value_type
the type of the values when the iterator is dereferenced
Definition: json.h:5777
reference operator+=(std::initializer_list< json > init)
add an object to an object
Definition: json.h:4651
bool is_primitive() const noexcept
return whether type is primitive
Definition: json.h:2530
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.h:5100
json flatten() const
return flattened JSON value
Definition: json.h:7103
bool operator()(wpi::detail::value_t lhs, wpi::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition: json.h:7193
object_t * object
object (stored with pointer to save storage)
Definition: json.h:1729