simdjson 4.1.0
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#endif // SIMDJSON_CONDITIONAL_INCLUDE
10
11
12namespace simdjson {
13namespace SIMDJSON_IMPLEMENTATION {
14namespace ondemand {
15
23class document {
24public:
30 simdjson_inline document() noexcept = default;
31 simdjson_inline document(const document &other) noexcept = delete; // pass your documents by reference, not by copy
32 simdjson_inline document(document &&other) noexcept = default;
33 simdjson_inline document &operator=(const document &other) noexcept = delete;
34 simdjson_inline document &operator=(document &&other) noexcept = default;
35
42 simdjson_inline simdjson_result<array> get_array() & noexcept;
49 simdjson_inline simdjson_result<object> get_object() & noexcept;
56 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
63 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
70 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
77 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
84 simdjson_inline simdjson_result<double> get_double() noexcept;
85
92 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
105 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
119 template <typename string_type>
120 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
132 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
141 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
148 simdjson_inline simdjson_result<bool> get_bool() noexcept;
161 simdjson_inline simdjson_result<value> get_value() noexcept;
162
171 simdjson_inline simdjson_result<bool> is_null() noexcept;
172
184 template <typename T>
185 simdjson_inline simdjson_result<T> get() &
186#if SIMDJSON_SUPPORTS_CONCEPTS
187 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
188#else
189 noexcept
190#endif
191 {
192 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
193 T out{};
194 SIMDJSON_TRY(get<T>(out));
195 return out;
196 }
207 template<typename T>
208 simdjson_inline simdjson_result<T> get() &&
209#if SIMDJSON_SUPPORTS_CONCEPTS
210 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
211#else
212 noexcept
213#endif
214 {
215 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.");
216 return static_cast<document&>(*this).get<T>();
217 }
218
230 template<typename T>
231 simdjson_warn_unused simdjson_inline error_code get(T &out) &
232#if SIMDJSON_SUPPORTS_CONCEPTS
233 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
234#else
235 noexcept
236#endif
237 {
238#if SIMDJSON_SUPPORTS_CONCEPTS
239 if constexpr (custom_deserializable<T, document>) {
240 return deserialize(*this, out);
241 } else {
242 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
243 "And you do not seem to have added support for it. Indeed, we have that "
244 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
245 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
246 "int64_t, double, or bool.");
247 static_cast<void>(out); // to get rid of unused errors
248 return UNINITIALIZED;
249 }
250#else // SIMDJSON_SUPPORTS_CONCEPTS
251 // Unless the simdjson library or the user provides an inline implementation, calling this method should
252 // immediately fail.
253 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
254 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
255 "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
256 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
257 " You may also add support for custom types, see our documentation.");
258 static_cast<void>(out); // to get rid of unused errors
259 return UNINITIALIZED;
260#endif // SIMDJSON_SUPPORTS_CONCEPTS
261 }
262
264 template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) && noexcept;
265
266#if SIMDJSON_EXCEPTIONS
276 template <class T>
277 explicit simdjson_inline operator T() & noexcept(false);
278 template <class T>
279 explicit simdjson_deprecated simdjson_inline operator T() && noexcept(false);
280
287 simdjson_inline operator array() & noexcept(false);
294 simdjson_inline operator object() & noexcept(false);
301 simdjson_inline operator uint64_t() noexcept(false);
308 simdjson_inline operator int64_t() noexcept(false);
315 simdjson_inline operator double() noexcept(false);
325 simdjson_inline operator std::string_view() noexcept(false) simdjson_lifetime_bound;
334 simdjson_inline operator raw_json_string() noexcept(false) simdjson_lifetime_bound;
341 simdjson_inline operator bool() noexcept(false);
353 simdjson_inline operator value() noexcept(false);
354#endif
367 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
382 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
390 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
396 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
402 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
403
436 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
438 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
439
470 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
472 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
474 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
476 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
477 simdjson_result<value> operator[](int) & noexcept = delete;
478
506 simdjson_inline simdjson_result<json_type> type() noexcept;
507
515 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
516
523 simdjson_inline simdjson_result<bool> is_string() noexcept;
524
530 simdjson_inline bool is_negative() noexcept;
540 simdjson_inline simdjson_result<bool> is_integer() noexcept;
565 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
566
593 simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
594
617 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
618
624 inline void rewind() noexcept;
628 inline std::string to_debug_string() noexcept;
633 inline bool is_alive() noexcept;
634
638 inline simdjson_result<const char *> current_location() const noexcept;
639
645 inline bool at_end() const noexcept;
646
656 simdjson_inline int32_t current_depth() const noexcept;
657
697 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
698
720 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
721
727 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
728
729#if SIMDJSON_STATIC_REFLECTION
754 template<constevalutil::fixed_string... FieldNames, typename T>
755 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
756 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
757#endif // SIMDJSON_STATIC_REFLECTION
758protected:
762 simdjson_warn_unused simdjson_inline error_code consume() noexcept;
763
764 simdjson_inline document(ondemand::json_iterator &&iter) noexcept;
765 simdjson_inline const uint8_t *text(uint32_t idx) const noexcept;
766
767 simdjson_inline value_iterator resume_value_iterator() noexcept;
768 simdjson_inline value_iterator get_root_value_iterator() noexcept;
769 simdjson_inline simdjson_result<object> start_or_resume_object() noexcept;
770 static simdjson_inline document start(ondemand::json_iterator &&iter) noexcept;
771
772 //
773 // Fields
774 //
775 json_iterator iter{};
776 static constexpr depth_t DOCUMENT_DEPTH = 0;
777
778 friend class array_iterator;
779 friend class value;
780 friend class ondemand::parser;
781 friend class object;
782 friend class array;
783 friend class field;
784 friend class token;
785 friend class document_stream;
786 friend class document_reference;
787};
788
789
799public:
800 simdjson_inline document_reference() noexcept;
801 simdjson_inline document_reference(document &d) noexcept;
802 simdjson_inline document_reference(const document_reference &other) noexcept = default;
803 simdjson_inline document_reference& operator=(const document_reference &other) noexcept = default;
804 simdjson_inline void rewind() noexcept;
805 simdjson_inline simdjson_result<array> get_array() & noexcept;
806 simdjson_inline simdjson_result<object> get_object() & noexcept;
807 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
808 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
809 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
810 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
811 simdjson_inline simdjson_result<double> get_double() noexcept;
812 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
813 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
814 template <typename string_type>
815 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
816 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
817 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
818 simdjson_inline simdjson_result<bool> get_bool() noexcept;
819 simdjson_inline simdjson_result<value> get_value() noexcept;
820
821 simdjson_inline simdjson_result<bool> is_null() noexcept;
822 template <typename T>
823 simdjson_inline simdjson_result<T> get() &
824#if SIMDJSON_SUPPORTS_CONCEPTS
825 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
826#else
827 noexcept
828#endif
829 {
830 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
831 T out{};
832 SIMDJSON_TRY(get<T>(out));
833 return out;
834 }
835 template<typename T>
836 simdjson_inline simdjson_result<T> get() &&
837#if SIMDJSON_SUPPORTS_CONCEPTS
838 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
839#else
840 noexcept
841#endif
842 {
843 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.");
844 return static_cast<document&>(*this).get<T>();
845 }
846
858 template<typename T>
859 simdjson_warn_unused simdjson_inline error_code get(T &out) &
860#if SIMDJSON_SUPPORTS_CONCEPTS
861 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document_reference> : true)
862#else
863 noexcept
864#endif
865 {
866#if SIMDJSON_SUPPORTS_CONCEPTS
867 if constexpr (custom_deserializable<T, document_reference>) {
868 return deserialize(*this, out);
869 } else {
870 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
871 "And you do not seem to have added support for it. Indeed, we have that "
872 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
873 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
874 "int64_t, double, or bool.");
875 static_cast<void>(out); // to get rid of unused errors
876 return UNINITIALIZED;
877 }
878#else // SIMDJSON_SUPPORTS_CONCEPTS
879 // Unless the simdjson library or the user provides an inline implementation, calling this method should
880 // immediately fail.
881 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
882 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
883 "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
884 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
885 " You may also add support for custom types, see our documentation.");
886 static_cast<void>(out); // to get rid of unused errors
887 return UNINITIALIZED;
888#endif // SIMDJSON_SUPPORTS_CONCEPTS
889 }
890
892 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
893 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
894#if SIMDJSON_STATIC_REFLECTION
895 template<constevalutil::fixed_string... FieldNames, typename T>
896 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
897 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
898#endif // SIMDJSON_STATIC_REFLECTION
899 simdjson_inline operator document&() const noexcept;
900#if SIMDJSON_EXCEPTIONS
901 template <class T>
902 explicit simdjson_inline operator T() noexcept(false);
903 simdjson_inline operator array() & noexcept(false);
904 simdjson_inline operator object() & noexcept(false);
905 simdjson_inline operator uint64_t() noexcept(false);
906 simdjson_inline operator int64_t() noexcept(false);
907 simdjson_inline operator double() noexcept(false);
908 simdjson_inline operator std::string_view() noexcept(false);
909 simdjson_inline operator raw_json_string() noexcept(false);
910 simdjson_inline operator bool() noexcept(false);
911 simdjson_inline operator value() noexcept(false);
912#endif
913 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
914 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
915 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
916 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
917 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
918 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
919 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
920 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
921 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
922 simdjson_result<value> operator[](int) & noexcept = delete;
923 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
924 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
925
926 simdjson_inline simdjson_result<json_type> type() noexcept;
927 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
928 simdjson_inline simdjson_result<bool> is_string() noexcept;
929
930 simdjson_inline simdjson_result<const char *> current_location() noexcept;
931 simdjson_inline int32_t current_depth() const noexcept;
932 simdjson_inline bool is_negative() noexcept;
933 simdjson_inline simdjson_result<bool> is_integer() noexcept;
934 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
935 simdjson_inline simdjson_result<number> get_number() noexcept;
936 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
937 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
938 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
939
940private:
941 document *doc{nullptr};
942};
943} // namespace ondemand
944} // namespace SIMDJSON_IMPLEMENTATION
945} // namespace simdjson
946
947namespace simdjson {
948
949template<>
950struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document> {
951public:
952 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document &&value) noexcept;
953 simdjson_inline simdjson_result(error_code error) noexcept;
954 simdjson_inline simdjson_result() noexcept = default;
955 simdjson_inline error_code rewind() noexcept;
956
957 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
958 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
959 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
960 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
961 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
962 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
963 simdjson_inline simdjson_result<double> get_double() noexcept;
964 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
965 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
966 template <typename string_type>
967 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
968 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
969 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
970 simdjson_inline simdjson_result<bool> get_bool() noexcept;
971 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
972 simdjson_inline simdjson_result<bool> is_null() noexcept;
973
974 template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
975 template<typename T> simdjson_deprecated simdjson_inline simdjson_result<T> get() && noexcept;
976
977 template<typename T> simdjson_inline error_code get(T &out) & noexcept;
978 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
979#if SIMDJSON_EXCEPTIONS
980
981 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator*;
982 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator->;
983 template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false>::type>
984 explicit simdjson_inline operator T() noexcept(false);
985 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
986 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
987 simdjson_inline operator uint64_t() noexcept(false);
988 simdjson_inline operator int64_t() noexcept(false);
989 simdjson_inline operator double() noexcept(false);
990 simdjson_inline operator std::string_view() noexcept(false);
991 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
992 simdjson_inline operator bool() noexcept(false);
993 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
994#endif
995 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
996 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
997 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
998 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> begin() & noexcept;
999 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> end() & noexcept;
1000 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1001 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1002 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1003 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1004 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1005 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1006 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1007 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
1008 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1009 simdjson_inline simdjson_result<bool> is_string() noexcept;
1010 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1011 simdjson_inline int32_t current_depth() const noexcept;
1012 simdjson_inline bool at_end() const noexcept;
1013 simdjson_inline bool is_negative() noexcept;
1014 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1015 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1016 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1018 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1019
1020 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1021 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1022#if SIMDJSON_STATIC_REFLECTION
1023 template<constevalutil::fixed_string... FieldNames, typename T>
1024 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1025 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1026#endif // SIMDJSON_STATIC_REFLECTION
1027};
1028
1029
1030} // namespace simdjson
1031
1032
1033
1034namespace simdjson {
1035
1036template<>
1037struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> {
1038public:
1040 simdjson_inline simdjson_result() noexcept = default;
1041 simdjson_inline error_code rewind() noexcept;
1042
1043 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
1044 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
1045 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
1046 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
1047 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
1048 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
1049 simdjson_inline simdjson_result<double> get_double() noexcept;
1050 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
1051 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
1052 template <typename string_type>
1053 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
1054 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
1055 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
1056 simdjson_inline simdjson_result<bool> get_bool() noexcept;
1057 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
1058 simdjson_inline simdjson_result<bool> is_null() noexcept;
1059
1060 template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
1061 template<typename T> simdjson_inline simdjson_result<T> get() && noexcept;
1062
1063 template<typename T> simdjson_inline error_code get(T &out) & noexcept;
1064 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
1065#if SIMDJSON_EXCEPTIONS
1066 template <class T>
1067 explicit simdjson_inline operator T() noexcept(false);
1068 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1069 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1070 simdjson_inline operator uint64_t() noexcept(false);
1071 simdjson_inline operator int64_t() noexcept(false);
1072 simdjson_inline operator double() noexcept(false);
1073 simdjson_inline operator std::string_view() noexcept(false);
1074 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1075 simdjson_inline operator bool() noexcept(false);
1076 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1077#endif
1078 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1079 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1080 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1083 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1084 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1085 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1086 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1087 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1088 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1089 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1091 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1092 simdjson_inline simdjson_result<bool> is_string() noexcept;
1093 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1094 simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
1095 simdjson_inline simdjson_result<bool> is_negative() noexcept;
1096 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1097 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1098 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1100 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1101
1102 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1103 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1104#if SIMDJSON_STATIC_REFLECTION
1105 template<constevalutil::fixed_string... FieldNames, typename T>
1106 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1107 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1108#endif // SIMDJSON_STATIC_REFLECTION
1109};
1110
1111
1112} // namespace simdjson
1113
1114#endif // SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
A document_reference is a thin wrapper around a document reference instance.
Definition document.h:798
simdjson_warn_unused simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition document.h:859
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:776
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:231
bool is_alive() noexcept
Some unrecoverable error conditions may render the document instance unusable.
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< 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:775
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< 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:185
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:20
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
Definition value.h:21
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:278
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