simdjson 4.6.3
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;
105 simdjson_inline simdjson_result<double> get_double() noexcept;
106
113 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
126 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
140 template <typename string_type>
141 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
153 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
162 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
169 simdjson_inline simdjson_result<bool> get_bool() noexcept;
182 simdjson_inline simdjson_result<value> get_value() noexcept;
183
192 simdjson_inline simdjson_result<bool> is_null() noexcept;
193
205 template <typename T>
206 simdjson_inline simdjson_result<T> get() &
207#if SIMDJSON_SUPPORTS_CONCEPTS
208 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
209#else
210 noexcept
211#endif
212 {
213 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
214 T out{};
215 SIMDJSON_TRY(get<T>(out));
216 return out;
217 }
228 template<typename T>
229 simdjson_inline simdjson_result<T> get() &&
230#if SIMDJSON_SUPPORTS_CONCEPTS
231 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
232#else
233 noexcept
234#endif
235 {
236 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.");
237 return static_cast<document&>(*this).get<T>();
238 }
239
251 template<typename T>
252 simdjson_warn_unused simdjson_inline error_code get(T &out) &
253#if SIMDJSON_SUPPORTS_CONCEPTS
254 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
255#else
256 noexcept
257#endif
258 {
259#if SIMDJSON_SUPPORTS_CONCEPTS
260 if constexpr (custom_deserializable<T, document>) {
261 return deserialize(*this, out);
262 } else {
263 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
264 "And you do not seem to have added support for it. Indeed, we have that "
265 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
266 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
267 "int64_t, double, or bool.");
268 static_cast<void>(out); // to get rid of unused errors
269 return UNINITIALIZED;
270 }
271#else // SIMDJSON_SUPPORTS_CONCEPTS
272 // Unless the simdjson library or the user provides an inline implementation, calling this method should
273 // immediately fail.
274 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
275 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
276 "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
277 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
278 " You may also add support for custom types, see our documentation.");
279 static_cast<void>(out); // to get rid of unused errors
280 return UNINITIALIZED;
281#endif // SIMDJSON_SUPPORTS_CONCEPTS
282 }
283
285 template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) && noexcept;
286
287#if SIMDJSON_EXCEPTIONS
297 template <class T>
298 explicit simdjson_inline operator T() & noexcept(false);
299 template <class T>
300 explicit simdjson_deprecated simdjson_inline operator T() && noexcept(false);
301
308 simdjson_inline operator array() & noexcept(false);
315 simdjson_inline operator object() & noexcept(false);
322 simdjson_inline operator uint64_t() noexcept(false);
329 simdjson_inline operator int64_t() noexcept(false);
336 simdjson_inline operator double() noexcept(false);
346 simdjson_inline operator std::string_view() noexcept(false) simdjson_lifetime_bound;
355 simdjson_inline operator raw_json_string() noexcept(false) simdjson_lifetime_bound;
362 simdjson_inline operator bool() noexcept(false);
374 simdjson_inline operator value() noexcept(false);
375#endif
388 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
403 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
411 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
417 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
423 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
424
459 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
461 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
462
494 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
496 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
498 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
500 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
501 simdjson_result<value> operator[](int) & noexcept = delete;
502
530 simdjson_inline simdjson_result<json_type> type() noexcept;
531
539 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
540
547 simdjson_inline simdjson_result<bool> is_string() noexcept;
548
554 simdjson_inline bool is_negative() noexcept;
564 simdjson_inline simdjson_result<bool> is_integer() noexcept;
589 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
590
617 simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
618
641 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
642
648 inline void rewind() noexcept;
652 inline std::string to_debug_string() noexcept;
657 inline bool is_alive() noexcept;
658
662 inline simdjson_result<const char *> current_location() const noexcept;
663
669 inline bool at_end() const noexcept;
670
680 simdjson_inline int32_t current_depth() const noexcept;
681
721 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
722
744 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
745
758#if SIMDJSON_SUPPORTS_CONCEPTS
759 template <typename Func>
760 requires std::invocable<Func, value>
761#else
762 template <typename Func>
763#endif
764 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
765
771 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
772
773#if SIMDJSON_STATIC_REFLECTION
798 template<constevalutil::fixed_string... FieldNames, typename T>
799 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
800 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
801#endif // SIMDJSON_STATIC_REFLECTION
802protected:
806 simdjson_warn_unused simdjson_inline error_code consume() noexcept;
807
808 simdjson_inline document(ondemand::json_iterator &&iter) noexcept;
809 simdjson_inline const uint8_t *text(uint32_t idx) const noexcept;
810
811 simdjson_inline value_iterator resume_value_iterator() noexcept;
812 simdjson_inline value_iterator get_root_value_iterator() noexcept;
813 simdjson_inline simdjson_result<object> start_or_resume_object() noexcept;
814 static simdjson_inline document start(ondemand::json_iterator &&iter) noexcept;
815
816 //
817 // Fields
818 //
819 json_iterator iter{};
820 static constexpr depth_t DOCUMENT_DEPTH = 0;
821
822 friend class array_iterator;
823 friend class value;
824 friend class ondemand::parser;
825 friend class object;
826 friend class array;
827 friend class field;
828 friend class token;
829 friend class document_stream;
830 friend class document_reference;
831};
832
833
843public:
844 simdjson_inline document_reference() noexcept;
845 simdjson_inline document_reference(document &d) noexcept;
846 simdjson_inline document_reference(const document_reference &other) noexcept = default;
847 simdjson_inline document_reference& operator=(const document_reference &other) noexcept = default;
848 simdjson_inline void rewind() noexcept;
849 simdjson_inline simdjson_result<array> get_array() & noexcept;
850 simdjson_inline simdjson_result<object> get_object() & noexcept;
851 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
852 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
853 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
854 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
855 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
856 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
857 simdjson_inline simdjson_result<double> get_double() noexcept;
858 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
859 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
860 template <typename string_type>
861 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
862 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
863 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
864 simdjson_inline simdjson_result<bool> get_bool() noexcept;
865 simdjson_inline simdjson_result<value> get_value() noexcept;
866
867 simdjson_inline simdjson_result<bool> is_null() noexcept;
868 template <typename T>
869 simdjson_inline simdjson_result<T> get() &
870#if SIMDJSON_SUPPORTS_CONCEPTS
871 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
872#else
873 noexcept
874#endif
875 {
876 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
877 T out{};
878 SIMDJSON_TRY(get<T>(out));
879 return out;
880 }
881 template<typename T>
882 simdjson_inline simdjson_result<T> get() &&
883#if SIMDJSON_SUPPORTS_CONCEPTS
884 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
885#else
886 noexcept
887#endif
888 {
889 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.");
890 return static_cast<document&>(*this).get<T>();
891 }
892
904 template<typename T>
905 simdjson_warn_unused simdjson_inline error_code get(T &out) &
906#if SIMDJSON_SUPPORTS_CONCEPTS
907 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document_reference> : true)
908#else
909 noexcept
910#endif
911 {
912#if SIMDJSON_SUPPORTS_CONCEPTS
913 if constexpr (custom_deserializable<T, document_reference>) {
914 return deserialize(*this, out);
915 } else {
916 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
917 "And you do not seem to have added support for it. Indeed, we have that "
918 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
919 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
920 "int64_t, double, or bool.");
921 static_cast<void>(out); // to get rid of unused errors
922 return UNINITIALIZED;
923 }
924#else // SIMDJSON_SUPPORTS_CONCEPTS
925 // Unless the simdjson library or the user provides an inline implementation, calling this method should
926 // immediately fail.
927 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
928 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
929 "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
930 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
931 " You may also add support for custom types, see our documentation.");
932 static_cast<void>(out); // to get rid of unused errors
933 return UNINITIALIZED;
934#endif // SIMDJSON_SUPPORTS_CONCEPTS
935 }
936
938 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
939 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
940#if SIMDJSON_STATIC_REFLECTION
941 template<constevalutil::fixed_string... FieldNames, typename T>
942 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
943 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
944#endif // SIMDJSON_STATIC_REFLECTION
945 simdjson_inline operator document&() const noexcept;
946#if SIMDJSON_EXCEPTIONS
947 template <class T>
948 explicit simdjson_inline operator T() noexcept(false);
949 simdjson_inline operator array() & noexcept(false);
950 simdjson_inline operator object() & noexcept(false);
951 simdjson_inline operator uint64_t() noexcept(false);
952 simdjson_inline operator int64_t() noexcept(false);
953 simdjson_inline operator double() noexcept(false);
954 simdjson_inline operator std::string_view() noexcept(false);
955 simdjson_inline operator raw_json_string() noexcept(false);
956 simdjson_inline operator bool() noexcept(false);
957 simdjson_inline operator value() noexcept(false);
958#endif
959 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
960 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
961 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
962 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
963 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
964 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
965 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
966 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
967 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
968 simdjson_result<value> operator[](int) & noexcept = delete;
969 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
970 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
971
972 simdjson_inline simdjson_result<json_type> type() noexcept;
973 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
974 simdjson_inline simdjson_result<bool> is_string() noexcept;
975
976 simdjson_inline simdjson_result<const char *> current_location() noexcept;
977 simdjson_inline int32_t current_depth() const noexcept;
978 simdjson_inline bool is_negative() noexcept;
979 simdjson_inline simdjson_result<bool> is_integer() noexcept;
980 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
981 simdjson_inline simdjson_result<number> get_number() noexcept;
982 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
983 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
984 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
985#if SIMDJSON_SUPPORTS_CONCEPTS
986 template <typename Func>
987 requires std::invocable<Func, value>
988#else
989 template <typename Func>
990#endif
991 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
992
993private:
994 document *doc{nullptr};
995};
996} // namespace ondemand
997} // namespace SIMDJSON_IMPLEMENTATION
998} // namespace simdjson
999
1000namespace simdjson {
1001
1002template<>
1003struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document> {
1004public:
1005 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document &&value) noexcept;
1006 simdjson_inline simdjson_result(error_code error) noexcept;
1007 simdjson_inline simdjson_result() noexcept = default;
1008 simdjson_inline error_code rewind() noexcept;
1009
1010 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
1011 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
1012 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
1013 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
1014 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
1015 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
1016 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
1017 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
1018 simdjson_inline simdjson_result<double> get_double() noexcept;
1019 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
1020 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
1021 template <typename string_type>
1022 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
1023 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
1024 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
1025 simdjson_inline simdjson_result<bool> get_bool() noexcept;
1026 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
1027 simdjson_inline simdjson_result<bool> is_null() noexcept;
1028
1029 template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
1030 template<typename T> simdjson_deprecated simdjson_inline simdjson_result<T> get() && noexcept;
1031
1032 template<typename T> simdjson_inline error_code get(T &out) & noexcept;
1033 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
1034#if SIMDJSON_EXCEPTIONS
1035
1036 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator*;
1037 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator->;
1038 template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false>::type>
1039 explicit simdjson_inline operator T() noexcept(false);
1040 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1041 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1042 simdjson_inline operator uint64_t() noexcept(false);
1043 simdjson_inline operator int64_t() noexcept(false);
1044 simdjson_inline operator double() noexcept(false);
1045 simdjson_inline operator std::string_view() noexcept(false);
1046 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1047 simdjson_inline operator bool() noexcept(false);
1048 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1049#endif
1050 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1051 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1052 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1053 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> begin() & noexcept;
1054 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> end() & noexcept;
1055 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1056 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1057 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1058 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1059 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1060 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1061 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1062 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
1063 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1064 simdjson_inline simdjson_result<bool> is_string() noexcept;
1065 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1066 simdjson_inline int32_t current_depth() const noexcept;
1067 simdjson_inline bool at_end() const noexcept;
1068 simdjson_inline bool is_negative() noexcept;
1069 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1070 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1071 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1073 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1074
1075 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1076 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1077#if SIMDJSON_SUPPORTS_CONCEPTS
1078 template <typename Func>
1079 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
1080#else
1081 template <typename Func>
1082#endif
1083 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
1084#if SIMDJSON_STATIC_REFLECTION
1085 template<constevalutil::fixed_string... FieldNames, typename T>
1086 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1087 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1088#endif // SIMDJSON_STATIC_REFLECTION
1089};
1090
1091
1092} // namespace simdjson
1093
1094
1095
1096namespace simdjson {
1097
1098template<>
1099struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> {
1100public:
1102 simdjson_inline simdjson_result() noexcept = default;
1103 simdjson_inline error_code rewind() noexcept;
1104
1105 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
1106 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
1107 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
1108 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
1109 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
1110 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
1111 simdjson_inline simdjson_result<uint32_t> get_uint32() noexcept;
1112 simdjson_inline simdjson_result<int32_t> get_int32() noexcept;
1113 simdjson_inline simdjson_result<double> get_double() noexcept;
1114 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
1115 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
1116 template <typename string_type>
1117 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
1118 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
1119 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
1120 simdjson_inline simdjson_result<bool> get_bool() noexcept;
1121 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
1122 simdjson_inline simdjson_result<bool> is_null() noexcept;
1123
1124 template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
1125 template<typename T> simdjson_inline simdjson_result<T> get() && noexcept;
1126
1127 template<typename T> simdjson_inline error_code get(T &out) & noexcept;
1128 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
1129#if SIMDJSON_EXCEPTIONS
1130 template <class T>
1131 explicit simdjson_inline operator T() noexcept(false);
1132 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1133 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1134 simdjson_inline operator uint64_t() noexcept(false);
1135 simdjson_inline operator int64_t() noexcept(false);
1136 simdjson_inline operator double() noexcept(false);
1137 simdjson_inline operator std::string_view() noexcept(false);
1138 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1139 simdjson_inline operator bool() noexcept(false);
1140 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1141#endif
1142 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1143 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1144 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1147 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1148 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1149 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1150 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1151 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1152 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1153 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1155 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1156 simdjson_inline simdjson_result<bool> is_string() noexcept;
1157 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1158 simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
1159 simdjson_inline simdjson_result<bool> is_negative() noexcept;
1160 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1161 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1162 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1164 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1165
1166 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1167 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1168#if SIMDJSON_SUPPORTS_CONCEPTS
1169 template <typename Func>
1170 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
1171#else
1172 template <typename Func>
1173#endif
1174 simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept;
1175#if SIMDJSON_STATIC_REFLECTION
1176 template<constevalutil::fixed_string... FieldNames, typename T>
1177 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1178 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1179#endif // SIMDJSON_STATIC_REFLECTION
1180};
1181
1182
1183} // namespace simdjson
1184
1185#endif // SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
A document_reference is a thin wrapper around a document reference instance.
Definition document.h:842
simdjson_warn_unused simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition document.h:905
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_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:820
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< 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:252
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< 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< 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< 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:819
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:206
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:21
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:280
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