simdjson 5.0.1
Ridiculously Fast JSON
Loading...
Searching...
No Matches
document.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
2
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/ondemand/json_iterator.h"
7#include "simdjson/generic/ondemand/deserialize.h"
8#include "simdjson/generic/ondemand/value.h"
9#include <vector>
10#endif // SIMDJSON_CONDITIONAL_INCLUDE
11
12
13namespace simdjson {
14namespace SIMDJSON_IMPLEMENTATION {
15namespace ondemand {
16
24class document {
25public:
31 simdjson_inline document() noexcept = default;
32 simdjson_inline document(const document &other) noexcept = delete; // pass your documents by reference, not by copy
33 simdjson_inline document(document &&other) noexcept = default;
34 simdjson_inline document &operator=(const document &other) noexcept = delete;
35 simdjson_inline document &operator=(document &&other) noexcept = default;
36
43 simdjson_inline simdjson_result<array> get_array() & noexcept;
50 simdjson_inline simdjson_result<object> get_object() & noexcept;
57 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
64 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
71 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
78 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
88 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
98 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
108 simdjson_inline simdjson_result<uint16_t> get_uint16() noexcept;
118 simdjson_inline simdjson_result<int16_t> get_int16() noexcept;
128 simdjson_inline simdjson_result<uint8_t> get_uint8() noexcept;
138 simdjson_inline simdjson_result<int8_t> get_int8() noexcept;
145 simdjson_inline simdjson_result<double> get_double() noexcept;
146
153 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
154
166 simdjson_inline simdjson_result<float> get_float() noexcept;
167
175 simdjson_inline simdjson_result<float> get_float_in_string() noexcept;
176
177#if SIMDJSON_SUPPORTS_FLOAT32_T
187 simdjson_inline simdjson_result<std::float32_t> get_float32() noexcept;
188#endif // SIMDJSON_SUPPORTS_FLOAT32_T
189
190#if SIMDJSON_SUPPORTS_FLOAT64_T
199 simdjson_inline simdjson_result<std::float64_t> get_float64() noexcept;
200#endif // SIMDJSON_SUPPORTS_FLOAT64_T
213 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
214#if SIMDJSON_SUPPORTS_CHAR8_T
230 simdjson_inline simdjson_result<std::u8string_view> get_u8string(bool allow_replacement = false) noexcept;
231#endif // SIMDJSON_SUPPORTS_CHAR8_T
245 template <typename string_type>
246 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
258 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
267 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
274 simdjson_inline simdjson_result<bool> get_bool() noexcept;
287 simdjson_inline simdjson_result<value> get_value() noexcept;
288
297 simdjson_inline simdjson_result<bool> is_null() noexcept;
298
313 template <typename T>
314 simdjson_inline simdjson_result<T> get() &
315#if SIMDJSON_SUPPORTS_CONCEPTS
316 noexcept(nothrow_gettable<T, document>)
317#else
318 noexcept
319#endif
320 {
321 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
322 T out{};
323 SIMDJSON_TRY(get<T>(out));
324 return out;
325 }
336 template<typename T>
337 simdjson_inline simdjson_result<T> get() &&
338#if SIMDJSON_SUPPORTS_CONCEPTS
339 noexcept(nothrow_gettable<T, document>)
340#else
341 noexcept
342#endif
343 {
344 static_assert(!std::is_same<T, array>::value && !std::is_same<T, object>::value, "You should never hold either an ondemand::array or ondemand::object without a corresponding ondemand::document being alive; that would be Undefined Behaviour.");
345 return static_cast<document&>(*this).get<T>();
346 }
347
360 template<typename T>
361 simdjson_warn_unused simdjson_inline error_code get(T &out) &
362#if SIMDJSON_SUPPORTS_CONCEPTS
363 noexcept(nothrow_gettable<T, document>)
364#else
365 noexcept
366#endif
367 {
368#if SIMDJSON_SUPPORTS_CONCEPTS
369 if constexpr (custom_deserializable<T, document>) {
370 return deserialize(*this, out);
371 } else {
372 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
373 "And you do not seem to have added support for it. Indeed, we have that "
374 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
375 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
376 "int64_t, uint32_t, int32_t, uint16_t, int16_t, uint8_t, int8_t, double, float, or bool.");
377 static_cast<void>(out); // to get rid of unused errors
378 return UNINITIALIZED;
379 }
380#else // SIMDJSON_SUPPORTS_CONCEPTS
381 // Unless the simdjson library or the user provides an inline implementation, calling this method should
382 // immediately fail.
383 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
384 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
385 "int64_t, uint32_t, int32_t, uint16_t, int16_t, uint8_t, int8_t, double, float, and bool. We recommend you use get_double(), get_float(), "
386 "get_bool(), get_uint64(), get_int64(), get_uint32(), get_int32(), get_uint16(), get_int16(), get_uint8(), get_int8(), "
387 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
388 " You may also add support for custom types, see our documentation.");
389 static_cast<void>(out); // to get rid of unused errors
390 return UNINITIALIZED;
391#endif // SIMDJSON_SUPPORTS_CONCEPTS
392 }
393
395 template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) &&
396#if SIMDJSON_SUPPORTS_CONCEPTS
397 noexcept(nothrow_gettable<T, document>);
398#else
399 noexcept;
400#endif
401
402#if SIMDJSON_EXCEPTIONS
412 template <class T>
413 explicit simdjson_inline operator T() & noexcept(false);
414 template <class T>
415 explicit simdjson_deprecated simdjson_inline operator T() && noexcept(false);
416
423 simdjson_inline operator array() & noexcept(false);
430 simdjson_inline operator object() & noexcept(false);
437 explicit simdjson_inline operator uint64_t() noexcept(false);
444 explicit simdjson_inline operator int64_t() noexcept(false);
451 explicit simdjson_inline operator double() noexcept(false);
461 explicit simdjson_inline operator std::string_view() noexcept(false) simdjson_lifetime_bound;
470 explicit simdjson_inline operator raw_json_string() noexcept(false) simdjson_lifetime_bound;
477 explicit simdjson_inline operator bool() noexcept(false);
489 simdjson_inline operator value() noexcept(false);
490#endif
503 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
518 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
526 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
532 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
538 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
539
574 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
576 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
577
609 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
611 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
613 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
615 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
616 simdjson_result<value> operator[](int) & noexcept = delete;
617
645 simdjson_inline simdjson_result<json_type> type() noexcept;
646
654 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
655
662 simdjson_inline simdjson_result<bool> is_string() noexcept;
663
669 simdjson_inline bool is_negative() noexcept;
679 simdjson_inline simdjson_result<bool> is_integer() noexcept;
704 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
705
732 simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
733
756 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
757
763 inline void rewind() noexcept;
767 inline std::string to_debug_string() noexcept;
772 inline bool is_alive() noexcept;
773
777 inline simdjson_result<const char *> current_location() const noexcept;
778
784 inline bool at_end() const noexcept;
785
795 simdjson_inline int32_t current_depth() const noexcept;
796
836 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
837
859 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
860
873#if SIMDJSON_SUPPORTS_CONCEPTS
874 template <typename Func>
875 requires std::invocable<Func, value>
876#else
877 template <typename Func>
878#endif
879 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
880
886 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
887
888#if SIMDJSON_STATIC_REFLECTION
913 template<constevalutil::fixed_string... FieldNames, typename T>
914 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
915 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
916#endif // SIMDJSON_STATIC_REFLECTION
917protected:
921 simdjson_warn_unused simdjson_inline error_code consume() noexcept;
922
923 simdjson_inline document(ondemand::json_iterator &&iter) noexcept;
924 simdjson_inline const uint8_t *text(uint32_t idx) const noexcept;
925
926 simdjson_inline value_iterator resume_value_iterator() noexcept;
927 simdjson_inline value_iterator get_root_value_iterator() noexcept;
928 simdjson_inline simdjson_result<object> start_or_resume_object() noexcept;
929 static simdjson_inline document start(ondemand::json_iterator &&iter) noexcept;
930
931 //
932 // Fields
933 //
934 json_iterator iter{};
935 static constexpr depth_t DOCUMENT_DEPTH = 0;
936
937 friend class array_iterator;
938 friend class value;
939 friend class ondemand::parser;
940 friend class object;
941 friend class array;
942 friend class field;
943 friend class token;
944 friend class document_stream;
945 friend class document_reference;
946};
947
948
958public:
959 simdjson_inline document_reference() noexcept;
960 simdjson_inline document_reference(document &d) noexcept;
961 simdjson_inline document_reference(const document_reference &other) noexcept = default;
962 simdjson_inline document_reference& operator=(const document_reference &other) noexcept = default;
963 simdjson_inline void rewind() noexcept;
964 simdjson_inline simdjson_result<array> get_array() & noexcept;
965 simdjson_inline simdjson_result<object> get_object() & noexcept;
966 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
967 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
968 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
969 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
970 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
971 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
972 simdjson_inline simdjson_result<uint16_t> get_uint16() noexcept;
973 simdjson_inline simdjson_result<int16_t> get_int16() noexcept;
974 simdjson_inline simdjson_result<uint8_t> get_uint8() noexcept;
975 simdjson_inline simdjson_result<int8_t> get_int8() noexcept;
976 simdjson_inline simdjson_result<double> get_double() noexcept;
977 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
978 simdjson_inline simdjson_result<float> get_float() noexcept;
979 simdjson_inline simdjson_result<float> get_float_in_string() noexcept;
980#if SIMDJSON_SUPPORTS_FLOAT32_T
981 simdjson_inline simdjson_result<std::float32_t> get_float32() noexcept;
982#endif // SIMDJSON_SUPPORTS_FLOAT32_T
983#if SIMDJSON_SUPPORTS_FLOAT64_T
984 simdjson_inline simdjson_result<std::float64_t> get_float64() noexcept;
985#endif // SIMDJSON_SUPPORTS_FLOAT64_T
986 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
987#if SIMDJSON_SUPPORTS_CHAR8_T
988 simdjson_inline simdjson_result<std::u8string_view> get_u8string(bool allow_replacement = false) noexcept;
989#endif // SIMDJSON_SUPPORTS_CHAR8_T
990 template <typename string_type>
991 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
992 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
993 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
994 simdjson_inline simdjson_result<bool> get_bool() noexcept;
995 simdjson_inline simdjson_result<value> get_value() noexcept;
996
997 simdjson_inline simdjson_result<bool> is_null() noexcept;
998 template <typename T>
999 simdjson_inline simdjson_result<T> get() &
1000#if SIMDJSON_SUPPORTS_CONCEPTS
1001 noexcept(nothrow_gettable<T, document_reference>)
1002#else
1003 noexcept
1004#endif
1005 {
1006 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
1007 T out{};
1008 SIMDJSON_TRY(get<T>(out));
1009 return out;
1010 }
1011 template<typename T>
1012 simdjson_inline simdjson_result<T> get() &&
1013#if SIMDJSON_SUPPORTS_CONCEPTS
1014 // Forwards to document::get<T>(), so the document customization decides.
1015 noexcept(nothrow_gettable<T, document>)
1016#else
1017 noexcept
1018#endif
1019 {
1020 static_assert(!std::is_same<T, array>::value && !std::is_same<T, object>::value, "You should never hold either an ondemand::array or ondemand::object without a corresponding ondemand::document_reference being alive; that would be Undefined Behaviour.");
1021 return static_cast<document&>(*this).get<T>();
1022 }
1023
1036 template<typename T>
1037 simdjson_warn_unused simdjson_inline error_code get(T &out) &
1038#if SIMDJSON_SUPPORTS_CONCEPTS
1039 noexcept(nothrow_gettable<T, document_reference>)
1040#else
1041 noexcept
1042#endif
1043 {
1044#if SIMDJSON_SUPPORTS_CONCEPTS
1045 if constexpr (custom_deserializable<T, document_reference>) {
1046 return deserialize(*this, out);
1047 } else {
1048 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
1049 "And you do not seem to have added support for it. Indeed, we have that "
1050 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
1051 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
1052 "int64_t, uint32_t, int32_t, uint16_t, int16_t, uint8_t, int8_t, double, float, or bool.");
1053 static_cast<void>(out); // to get rid of unused errors
1054 return UNINITIALIZED;
1055 }
1056#else // SIMDJSON_SUPPORTS_CONCEPTS
1057 // Unless the simdjson library or the user provides an inline implementation, calling this method should
1058 // immediately fail.
1059 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
1060 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
1061 "int64_t, uint32_t, int32_t, uint16_t, int16_t, uint8_t, int8_t, double, float, and bool. We recommend you use get_double(), get_float(), "
1062 "get_bool(), get_uint64(), get_int64(), get_uint32(), get_int32(), get_uint16(), get_int16(), get_uint8(), get_int8(), "
1063 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
1064 " You may also add support for custom types, see our documentation.");
1065 static_cast<void>(out); // to get rid of unused errors
1066 return UNINITIALIZED;
1067#endif // SIMDJSON_SUPPORTS_CONCEPTS
1068 }
1069
1071 template<typename T> simdjson_inline error_code get(T &out) &&
1072#if SIMDJSON_SUPPORTS_CONCEPTS
1073 noexcept(nothrow_gettable<T, document_reference>);
1074#else
1075 noexcept;
1076#endif
1077 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
1078#if SIMDJSON_STATIC_REFLECTION
1079 template<constevalutil::fixed_string... FieldNames, typename T>
1080 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1081 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1082#endif // SIMDJSON_STATIC_REFLECTION
1083 simdjson_inline operator document&() const noexcept;
1084#if SIMDJSON_EXCEPTIONS
1085 template <class T>
1086 explicit simdjson_inline operator T() noexcept(false);
1087 simdjson_inline operator array() & noexcept(false);
1088 simdjson_inline operator object() & noexcept(false);
1089 explicit simdjson_inline operator uint64_t() noexcept(false);
1090 explicit simdjson_inline operator int64_t() noexcept(false);
1091 explicit simdjson_inline operator double() noexcept(false);
1092 explicit simdjson_inline operator std::string_view() noexcept(false);
1093 explicit simdjson_inline operator raw_json_string() noexcept(false);
1094 explicit simdjson_inline operator bool() noexcept(false);
1095 simdjson_inline operator value() noexcept(false);
1096#endif
1097 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1098 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1099 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
1100 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
1101 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
1102 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
1103 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
1104 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
1105 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
1106 simdjson_result<value> operator[](int) & noexcept = delete;
1107 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
1108 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
1109
1110 simdjson_inline simdjson_result<json_type> type() noexcept;
1111 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1112 simdjson_inline simdjson_result<bool> is_string() noexcept;
1113
1114 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1115 simdjson_inline int32_t current_depth() const noexcept;
1116 simdjson_inline bool is_negative() noexcept;
1117 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1118 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
1119 simdjson_inline simdjson_result<number> get_number() noexcept;
1120 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1121 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
1122 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
1123#if SIMDJSON_SUPPORTS_CONCEPTS
1124 template <typename Func>
1125 requires std::invocable<Func, value>
1126#else
1127 template <typename Func>
1128#endif
1129 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
1130
1131private:
1132 document *doc{nullptr};
1133};
1134} // namespace ondemand
1135} // namespace SIMDJSON_IMPLEMENTATION
1136} // namespace simdjson
1137
1138namespace simdjson {
1139
1140template<>
1141struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document> {
1142public:
1143 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document &&value) noexcept;
1144 simdjson_inline simdjson_result(error_code error) noexcept;
1145 simdjson_inline simdjson_result() noexcept = default;
1146 simdjson_inline error_code rewind() noexcept;
1147
1148 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
1149 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
1150 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
1151 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
1152 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
1153 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
1154 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
1155 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
1156 simdjson_inline simdjson_result<uint16_t> get_uint16() noexcept;
1157 simdjson_inline simdjson_result<int16_t> get_int16() noexcept;
1158 simdjson_inline simdjson_result<uint8_t> get_uint8() noexcept;
1159 simdjson_inline simdjson_result<int8_t> get_int8() noexcept;
1160 simdjson_inline simdjson_result<double> get_double() noexcept;
1161 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
1162 simdjson_inline simdjson_result<float> get_float() noexcept;
1163 simdjson_inline simdjson_result<float> get_float_in_string() noexcept;
1164#if SIMDJSON_SUPPORTS_FLOAT32_T
1165 simdjson_inline simdjson_result<std::float32_t> get_float32() noexcept;
1166#endif // SIMDJSON_SUPPORTS_FLOAT32_T
1167#if SIMDJSON_SUPPORTS_FLOAT64_T
1168 simdjson_inline simdjson_result<std::float64_t> get_float64() noexcept;
1169#endif // SIMDJSON_SUPPORTS_FLOAT64_T
1170 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
1171#if SIMDJSON_SUPPORTS_CHAR8_T
1172 simdjson_inline simdjson_result<std::u8string_view> get_u8string(bool allow_replacement = false) noexcept;
1173#endif // SIMDJSON_SUPPORTS_CHAR8_T
1174 template <typename string_type>
1175 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
1176 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
1177 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
1178 simdjson_inline simdjson_result<bool> get_bool() noexcept;
1179 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
1180 simdjson_inline simdjson_result<bool> is_null() noexcept;
1181
1182 template<typename T> simdjson_inline simdjson_result<T> get() &
1183#if SIMDJSON_SUPPORTS_CONCEPTS
1184 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document>);
1185#else
1186 noexcept;
1187#endif
1188 template<typename T> simdjson_deprecated simdjson_inline simdjson_result<T> get() &&
1189#if SIMDJSON_SUPPORTS_CONCEPTS
1190 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document>);
1191#else
1192 noexcept;
1193#endif
1194
1195 template<typename T> simdjson_inline error_code get(T &out) &
1196#if SIMDJSON_SUPPORTS_CONCEPTS
1197 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document>);
1198#else
1199 noexcept;
1200#endif
1201 template<typename T> simdjson_inline error_code get(T &out) &&
1202#if SIMDJSON_SUPPORTS_CONCEPTS
1203 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document>);
1204#else
1205 noexcept;
1206#endif
1207#if SIMDJSON_EXCEPTIONS
1208
1209 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator*;
1210 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator->;
1211 template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false>::type>
1212 explicit simdjson_inline operator T() noexcept(false);
1213 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1214 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1215 explicit simdjson_inline operator uint64_t() noexcept(false);
1216 explicit simdjson_inline operator int64_t() noexcept(false);
1217 explicit simdjson_inline operator double() noexcept(false);
1218 explicit simdjson_inline operator std::string_view() noexcept(false);
1219 explicit simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1220 explicit simdjson_inline operator bool() noexcept(false);
1221 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1222#endif
1223 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1224 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1225 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1226 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> begin() & noexcept;
1227 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> end() & noexcept;
1228 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1229 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1230 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1231 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1232 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1233 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1234 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1235 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
1236 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1237 simdjson_inline simdjson_result<bool> is_string() noexcept;
1238 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1239 simdjson_inline int32_t current_depth() const noexcept;
1240 simdjson_inline bool at_end() const noexcept;
1241 simdjson_inline bool is_negative() noexcept;
1242 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1243 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1244 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1246 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1247
1248 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1249 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1250#if SIMDJSON_SUPPORTS_CONCEPTS
1251 template <typename Func>
1252 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
1253#else
1254 template <typename Func>
1255#endif
1256 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
1257#if SIMDJSON_STATIC_REFLECTION
1258 template<constevalutil::fixed_string... FieldNames, typename T>
1259 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1260 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1261#endif // SIMDJSON_STATIC_REFLECTION
1262};
1263
1264
1265} // namespace simdjson
1266
1267
1268
1269namespace simdjson {
1270
1271template<>
1272struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> {
1273public:
1275 simdjson_inline simdjson_result() noexcept = default;
1276 simdjson_inline error_code rewind() noexcept;
1277
1278 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
1279 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
1280 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
1281 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
1282 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
1283 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
1284 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
1285 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
1286 simdjson_inline simdjson_result<uint16_t> get_uint16() noexcept;
1287 simdjson_inline simdjson_result<int16_t> get_int16() noexcept;
1288 simdjson_inline simdjson_result<uint8_t> get_uint8() noexcept;
1289 simdjson_inline simdjson_result<int8_t> get_int8() noexcept;
1290 simdjson_inline simdjson_result<double> get_double() noexcept;
1291 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
1292 simdjson_inline simdjson_result<float> get_float() noexcept;
1293 simdjson_inline simdjson_result<float> get_float_in_string() noexcept;
1294#if SIMDJSON_SUPPORTS_FLOAT32_T
1295 simdjson_inline simdjson_result<std::float32_t> get_float32() noexcept;
1296#endif // SIMDJSON_SUPPORTS_FLOAT32_T
1297#if SIMDJSON_SUPPORTS_FLOAT64_T
1298 simdjson_inline simdjson_result<std::float64_t> get_float64() noexcept;
1299#endif // SIMDJSON_SUPPORTS_FLOAT64_T
1300 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
1301#if SIMDJSON_SUPPORTS_CHAR8_T
1302 simdjson_inline simdjson_result<std::u8string_view> get_u8string(bool allow_replacement = false) noexcept;
1303#endif // SIMDJSON_SUPPORTS_CHAR8_T
1304 template <typename string_type>
1305 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
1306 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
1307 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
1308 simdjson_inline simdjson_result<bool> get_bool() noexcept;
1309 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
1310 simdjson_inline simdjson_result<bool> is_null() noexcept;
1311
1312 template<typename T> simdjson_inline simdjson_result<T> get() &
1313#if SIMDJSON_SUPPORTS_CONCEPTS
1314 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document_reference>);
1315#else
1316 noexcept;
1317#endif
1318 template<typename T> simdjson_inline simdjson_result<T> get() &&
1319#if SIMDJSON_SUPPORTS_CONCEPTS
1320 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document_reference>);
1321#else
1322 noexcept;
1323#endif
1324
1325 template<typename T> simdjson_inline error_code get(T &out) &
1326#if SIMDJSON_SUPPORTS_CONCEPTS
1327 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document_reference>);
1328#else
1329 noexcept;
1330#endif
1331 template<typename T> simdjson_inline error_code get(T &out) &&
1332#if SIMDJSON_SUPPORTS_CONCEPTS
1333 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::document_reference>);
1334#else
1335 noexcept;
1336#endif
1337#if SIMDJSON_EXCEPTIONS
1338 template <class T>
1339 explicit simdjson_inline operator T() noexcept(false);
1340 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1341 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1342 explicit simdjson_inline operator uint64_t() noexcept(false);
1343 explicit simdjson_inline operator int64_t() noexcept(false);
1344 explicit simdjson_inline operator double() noexcept(false);
1345 explicit simdjson_inline operator std::string_view() noexcept(false);
1346 explicit simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1347 explicit simdjson_inline operator bool() noexcept(false);
1348 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1349#endif
1350 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1351 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1352 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1355 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1356 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1357 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1358 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1359 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1360 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1361 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1363 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1364 simdjson_inline simdjson_result<bool> is_string() noexcept;
1365 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1366 simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
1367 simdjson_inline simdjson_result<bool> is_negative() noexcept;
1368 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1369 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1370 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1372 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1373
1374 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1375 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1376#if SIMDJSON_SUPPORTS_CONCEPTS
1377 template <typename Func>
1378 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
1379#else
1380 template <typename Func>
1381#endif
1382 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
1383#if SIMDJSON_STATIC_REFLECTION
1384 template<constevalutil::fixed_string... FieldNames, typename T>
1385 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1386 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1387#endif // SIMDJSON_STATIC_REFLECTION
1388};
1389
1390
1391} // namespace simdjson
1392
1393#endif // SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
A document_reference is a thin wrapper around a document reference instance.
Definition document.h:957
simdjson_warn_unused simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition document.h:1037
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
The document_reference instances are used primarily/solely for streams of JSON documents.
simdjson_inline simdjson_result< value > at(size_t index) &noexcept
Get the value at the given index in the array.
simdjson_inline simdjson_result< int16_t > get_int16() noexcept
Cast this JSON value to a 16-bit signed integer.
simdjson_inline simdjson_result< float > get_float() noexcept
Cast this JSON value to a float (binary32).
simdjson_warn_unused simdjson_inline error_code consume() noexcept
Consumes the document.
static constexpr depth_t DOCUMENT_DEPTH
document depth is always 0
Definition document.h:935
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
simdjson_inline simdjson_result< uint16_t > get_uint16() noexcept
Cast this JSON value to a 16-bit unsigned integer.
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
simdjson_warn_unused simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition document.h:361
bool is_alive() noexcept
Some unrecoverable error conditions may render the document instance unusable.
simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func &&callback) noexcept
Call the provided callback for each value matching the given JSONPath expression with wildcard suppor...
simdjson_inline simdjson_result< uint8_t > get_uint8() noexcept
Cast this JSON value to an 8-bit unsigned integer.
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
simdjson_inline simdjson_result< object > get_object() &noexcept
Cast this JSON value to an object.
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the document is a string.
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
simdjson_inline bool is_negative() noexcept
Checks whether the document is a negative number.
simdjson_inline document() noexcept=default
Create a new invalid document.
simdjson_inline simdjson_result< std::string_view > raw_json_token() noexcept
Get the raw JSON for this token.
simdjson_inline simdjson_result< float > get_float_in_string() noexcept
Cast this JSON value (inside string) to a float (binary32).
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to an unsigned integer.
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
simdjson_inline simdjson_result< int8_t > get_int8() noexcept
Cast this JSON value to an 8-bit signed integer.
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
simdjson_inline simdjson_result< int32_t > get_int32() noexcept
Cast this JSON value to a 32-bit signed integer.
simdjson_inline simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
simdjson_inline simdjson_result< json_type > type() noexcept
Get the type of this JSON value.
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
simdjson_inline operator std::string_view() noexcept(false) simdjson_lifetime_bound
Cast this JSON value to a string.
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
simdjson_inline simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
json_iterator iter
Current position in the document.
Definition document.h:934
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
std::string to_debug_string() noexcept
Returns debugging information.
void rewind() noexcept
Reset the iterator inside the document instance so we are pointing back at the beginning of the docum...
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Consumes the document and returns a string_view instance corresponding to the document as represented...
simdjson_inline simdjson_result< value > find_field_unordered(std::string_view key) &noexcept
Look up a field by name on an object, without regard to key order.
simdjson_inline simdjson_result< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
simdjson_inline simdjson_result< value > get_value() noexcept
Cast this JSON value to a value when the document is an object or an array.
simdjson_inline simdjson_result< value > find_field(std::string_view key) &noexcept
Look up a field by name on an object (order-sensitive).
simdjson_inline simdjson_result< number_type > get_number_type() noexcept
Determine the number type (integer or floating-point number) as quickly as possible.
simdjson_inline simdjson_result< uint32_t > get_uint32() noexcept
Cast this JSON value to a 32-bit unsigned integer.
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the document is a scalar (string, number, null, Boolean).
simdjson_inline simdjson_result< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a string.
bool at_end() const noexcept
Returns true if this document has been fully parsed.
simdjson_inline simdjson_result< array > get_array() &noexcept
Cast this JSON value to an array.
simdjson_inline simdjson_result< bool > is_integer() noexcept
Checks whether the document is an integer number.
simdjson_result< const char * > current_location() const noexcept
Returns the current location in the document if in bounds.
simdjson_inline simdjson_result< T > get() &noexcept
Get this value as the given type.
Definition document.h:314
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
A JSON field (key/value pair) in an object.
Definition field.h:22
A forward-only JSON object field iterator.
Definition object.h:130
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
Definition value.h:22
int32_t depth_t
Represents the depth of a JSON value (number of nested arrays/objects).
Definition base.h:18
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8
error_code
All possible errors returned by simdjson.
Definition error.h:19
@ UNINITIALIZED
unknown error, or uninitialized document
Definition error.h:32
A type representing a JSON number.
Definition json_type.h:33
The result of a simdjson operation that could fail.
Definition error.h:281
simdjson_inline error_code error() const noexcept
The error.
Definition error-inl.h:168
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
Definition error-inl.h:163