simdjson 4.2.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;
85 simdjson_inline simdjson_result<double> get_double() noexcept;
86
93 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
106 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
120 template <typename string_type>
121 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
133 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
142 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
149 simdjson_inline simdjson_result<bool> get_bool() noexcept;
162 simdjson_inline simdjson_result<value> get_value() noexcept;
163
172 simdjson_inline simdjson_result<bool> is_null() noexcept;
173
185 template <typename T>
186 simdjson_inline simdjson_result<T> get() &
187#if SIMDJSON_SUPPORTS_CONCEPTS
188 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
189#else
190 noexcept
191#endif
192 {
193 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
194 T out{};
195 SIMDJSON_TRY(get<T>(out));
196 return out;
197 }
208 template<typename T>
209 simdjson_inline simdjson_result<T> get() &&
210#if SIMDJSON_SUPPORTS_CONCEPTS
211 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
212#else
213 noexcept
214#endif
215 {
216 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.");
217 return static_cast<document&>(*this).get<T>();
218 }
219
231 template<typename T>
232 simdjson_warn_unused simdjson_inline error_code get(T &out) &
233#if SIMDJSON_SUPPORTS_CONCEPTS
234 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
235#else
236 noexcept
237#endif
238 {
239#if SIMDJSON_SUPPORTS_CONCEPTS
240 if constexpr (custom_deserializable<T, document>) {
241 return deserialize(*this, out);
242 } else {
243 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
244 "And you do not seem to have added support for it. Indeed, we have that "
245 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
246 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
247 "int64_t, double, or bool.");
248 static_cast<void>(out); // to get rid of unused errors
249 return UNINITIALIZED;
250 }
251#else // SIMDJSON_SUPPORTS_CONCEPTS
252 // Unless the simdjson library or the user provides an inline implementation, calling this method should
253 // immediately fail.
254 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
255 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
256 "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
257 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
258 " You may also add support for custom types, see our documentation.");
259 static_cast<void>(out); // to get rid of unused errors
260 return UNINITIALIZED;
261#endif // SIMDJSON_SUPPORTS_CONCEPTS
262 }
263
265 template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) && noexcept;
266
267#if SIMDJSON_EXCEPTIONS
277 template <class T>
278 explicit simdjson_inline operator T() & noexcept(false);
279 template <class T>
280 explicit simdjson_deprecated simdjson_inline operator T() && noexcept(false);
281
288 simdjson_inline operator array() & noexcept(false);
295 simdjson_inline operator object() & noexcept(false);
302 simdjson_inline operator uint64_t() noexcept(false);
309 simdjson_inline operator int64_t() noexcept(false);
316 simdjson_inline operator double() noexcept(false);
326 simdjson_inline operator std::string_view() noexcept(false) simdjson_lifetime_bound;
335 simdjson_inline operator raw_json_string() noexcept(false) simdjson_lifetime_bound;
342 simdjson_inline operator bool() noexcept(false);
354 simdjson_inline operator value() noexcept(false);
355#endif
368 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
383 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
391 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
397 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
403 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
404
437 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
439 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
440
471 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
473 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
475 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
477 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
478 simdjson_result<value> operator[](int) & noexcept = delete;
479
507 simdjson_inline simdjson_result<json_type> type() noexcept;
508
516 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
517
524 simdjson_inline simdjson_result<bool> is_string() noexcept;
525
531 simdjson_inline bool is_negative() noexcept;
541 simdjson_inline simdjson_result<bool> is_integer() noexcept;
566 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
567
594 simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
595
618 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
619
625 inline void rewind() noexcept;
629 inline std::string to_debug_string() noexcept;
634 inline bool is_alive() noexcept;
635
639 inline simdjson_result<const char *> current_location() const noexcept;
640
646 inline bool at_end() const noexcept;
647
657 simdjson_inline int32_t current_depth() const noexcept;
658
698 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
699
721 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
722
738 simdjson_inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
739
745 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
746
747#if SIMDJSON_STATIC_REFLECTION
772 template<constevalutil::fixed_string... FieldNames, typename T>
773 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
774 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
775#endif // SIMDJSON_STATIC_REFLECTION
776protected:
780 simdjson_warn_unused simdjson_inline error_code consume() noexcept;
781
782 simdjson_inline document(ondemand::json_iterator &&iter) noexcept;
783 simdjson_inline const uint8_t *text(uint32_t idx) const noexcept;
784
785 simdjson_inline value_iterator resume_value_iterator() noexcept;
786 simdjson_inline value_iterator get_root_value_iterator() noexcept;
787 simdjson_inline simdjson_result<object> start_or_resume_object() noexcept;
788 static simdjson_inline document start(ondemand::json_iterator &&iter) noexcept;
789
790 //
791 // Fields
792 //
793 json_iterator iter{};
794 static constexpr depth_t DOCUMENT_DEPTH = 0;
795
796 friend class array_iterator;
797 friend class value;
798 friend class ondemand::parser;
799 friend class object;
800 friend class array;
801 friend class field;
802 friend class token;
803 friend class document_stream;
804 friend class document_reference;
805};
806
807
817public:
818 simdjson_inline document_reference() noexcept;
819 simdjson_inline document_reference(document &d) noexcept;
820 simdjson_inline document_reference(const document_reference &other) noexcept = default;
821 simdjson_inline document_reference& operator=(const document_reference &other) noexcept = default;
822 simdjson_inline void rewind() noexcept;
823 simdjson_inline simdjson_result<array> get_array() & noexcept;
824 simdjson_inline simdjson_result<object> get_object() & noexcept;
825 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
826 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
827 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
828 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
829 simdjson_inline simdjson_result<double> get_double() noexcept;
830 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
831 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
832 template <typename string_type>
833 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
834 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
835 simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
836 simdjson_inline simdjson_result<bool> get_bool() noexcept;
837 simdjson_inline simdjson_result<value> get_value() noexcept;
838
839 simdjson_inline simdjson_result<bool> is_null() noexcept;
840 template <typename T>
841 simdjson_inline simdjson_result<T> get() &
842#if SIMDJSON_SUPPORTS_CONCEPTS
843 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
844#else
845 noexcept
846#endif
847 {
848 static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
849 T out{};
850 SIMDJSON_TRY(get<T>(out));
851 return out;
852 }
853 template<typename T>
854 simdjson_inline simdjson_result<T> get() &&
855#if SIMDJSON_SUPPORTS_CONCEPTS
856 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
857#else
858 noexcept
859#endif
860 {
861 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.");
862 return static_cast<document&>(*this).get<T>();
863 }
864
876 template<typename T>
877 simdjson_warn_unused simdjson_inline error_code get(T &out) &
878#if SIMDJSON_SUPPORTS_CONCEPTS
879 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document_reference> : true)
880#else
881 noexcept
882#endif
883 {
884#if SIMDJSON_SUPPORTS_CONCEPTS
885 if constexpr (custom_deserializable<T, document_reference>) {
886 return deserialize(*this, out);
887 } else {
888 static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
889 "And you do not seem to have added support for it. Indeed, we have that "
890 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
891 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
892 "int64_t, double, or bool.");
893 static_cast<void>(out); // to get rid of unused errors
894 return UNINITIALIZED;
895 }
896#else // SIMDJSON_SUPPORTS_CONCEPTS
897 // Unless the simdjson library or the user provides an inline implementation, calling this method should
898 // immediately fail.
899 static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
900 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
901 "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
902 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
903 " You may also add support for custom types, see our documentation.");
904 static_cast<void>(out); // to get rid of unused errors
905 return UNINITIALIZED;
906#endif // SIMDJSON_SUPPORTS_CONCEPTS
907 }
908
910 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
911 simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
912#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
917 simdjson_inline operator document&() const noexcept;
918#if SIMDJSON_EXCEPTIONS
919 template <class T>
920 explicit simdjson_inline operator T() noexcept(false);
921 simdjson_inline operator array() & noexcept(false);
922 simdjson_inline operator object() & noexcept(false);
923 simdjson_inline operator uint64_t() noexcept(false);
924 simdjson_inline operator int64_t() noexcept(false);
925 simdjson_inline operator double() noexcept(false);
926 simdjson_inline operator std::string_view() noexcept(false);
927 simdjson_inline operator raw_json_string() noexcept(false);
928 simdjson_inline operator bool() noexcept(false);
929 simdjson_inline operator value() noexcept(false);
930#endif
931 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
932 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
933 simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
934 simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
935 simdjson_inline simdjson_result<array_iterator> end() & noexcept;
936 simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
937 simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
938 simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
939 simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
940 simdjson_result<value> operator[](int) & noexcept = delete;
941 simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
942 simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
943
944 simdjson_inline simdjson_result<json_type> type() noexcept;
945 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
946 simdjson_inline simdjson_result<bool> is_string() noexcept;
947
948 simdjson_inline simdjson_result<const char *> current_location() noexcept;
949 simdjson_inline int32_t current_depth() const noexcept;
950 simdjson_inline bool is_negative() noexcept;
951 simdjson_inline simdjson_result<bool> is_integer() noexcept;
952 simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
953 simdjson_inline simdjson_result<number> get_number() noexcept;
954 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
955 simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
956 simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
957 simdjson_inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
958
959private:
960 document *doc{nullptr};
961};
962} // namespace ondemand
963} // namespace SIMDJSON_IMPLEMENTATION
964} // namespace simdjson
965
966namespace simdjson {
967
968template<>
969struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document> {
970public:
971 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document &&value) noexcept;
972 simdjson_inline simdjson_result(error_code error) noexcept;
973 simdjson_inline simdjson_result() noexcept = default;
974 simdjson_inline error_code rewind() noexcept;
975
976 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
977 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
978 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
979 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
980 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
981 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
982 simdjson_inline simdjson_result<double> get_double() noexcept;
983 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
984 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
985 template <typename string_type>
986 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
987 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
988 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
989 simdjson_inline simdjson_result<bool> get_bool() noexcept;
990 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
991 simdjson_inline simdjson_result<bool> is_null() noexcept;
992
993 template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
994 template<typename T> simdjson_deprecated simdjson_inline simdjson_result<T> get() && noexcept;
995
996 template<typename T> simdjson_inline error_code get(T &out) & noexcept;
997 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
998#if SIMDJSON_EXCEPTIONS
999
1000 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator*;
1001 using SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator->;
1002 template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false>::type>
1003 explicit simdjson_inline operator T() noexcept(false);
1004 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1005 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1006 simdjson_inline operator uint64_t() noexcept(false);
1007 simdjson_inline operator int64_t() noexcept(false);
1008 simdjson_inline operator double() noexcept(false);
1009 simdjson_inline operator std::string_view() noexcept(false);
1010 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1011 simdjson_inline operator bool() noexcept(false);
1012 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1013#endif
1014 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1015 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1016 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1017 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> begin() & noexcept;
1018 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> end() & noexcept;
1019 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1020 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1021 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1022 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1023 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1024 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1025 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1026 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
1027 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1028 simdjson_inline simdjson_result<bool> is_string() noexcept;
1029 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1030 simdjson_inline int32_t current_depth() const noexcept;
1031 simdjson_inline bool at_end() const noexcept;
1032 simdjson_inline bool is_negative() noexcept;
1033 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1034 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1035 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1037 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1038
1039 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1040 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1041 simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
1042#if SIMDJSON_STATIC_REFLECTION
1043 template<constevalutil::fixed_string... FieldNames, typename T>
1044 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1045 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1046#endif // SIMDJSON_STATIC_REFLECTION
1047};
1048
1049
1050} // namespace simdjson
1051
1052
1053
1054namespace simdjson {
1055
1056template<>
1057struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> {
1058public:
1060 simdjson_inline simdjson_result() noexcept = default;
1061 simdjson_inline error_code rewind() noexcept;
1062
1063 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
1064 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
1065 simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
1066 simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
1067 simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
1068 simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
1069 simdjson_inline simdjson_result<double> get_double() noexcept;
1070 simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
1071 simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
1072 template <typename string_type>
1073 simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
1074 simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
1075 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
1076 simdjson_inline simdjson_result<bool> get_bool() noexcept;
1077 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
1078 simdjson_inline simdjson_result<bool> is_null() noexcept;
1079
1080 template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
1081 template<typename T> simdjson_inline simdjson_result<T> get() && noexcept;
1082
1083 template<typename T> simdjson_inline error_code get(T &out) & noexcept;
1084 template<typename T> simdjson_inline error_code get(T &out) && noexcept;
1085#if SIMDJSON_EXCEPTIONS
1086 template <class T>
1087 explicit simdjson_inline operator T() noexcept(false);
1088 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
1089 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
1090 simdjson_inline operator uint64_t() noexcept(false);
1091 simdjson_inline operator int64_t() noexcept(false);
1092 simdjson_inline operator double() noexcept(false);
1093 simdjson_inline operator std::string_view() noexcept(false);
1094 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1095 simdjson_inline operator bool() noexcept(false);
1096 simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1097#endif
1098 simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1099 simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1100 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1103 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1104 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1105 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1106 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1107 simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1108 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1109 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1111 simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1112 simdjson_inline simdjson_result<bool> is_string() noexcept;
1113 simdjson_inline simdjson_result<const char *> current_location() noexcept;
1114 simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
1115 simdjson_inline simdjson_result<bool> is_negative() noexcept;
1116 simdjson_inline simdjson_result<bool> is_integer() noexcept;
1117 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1118 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1120 simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1121
1122 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1123 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1124 simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
1125#if SIMDJSON_STATIC_REFLECTION
1126 template<constevalutil::fixed_string... FieldNames, typename T>
1127 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1128 simdjson_warn_unused simdjson_inline error_code extract_into(T& out) & noexcept;
1129#endif // SIMDJSON_STATIC_REFLECTION
1130};
1131
1132
1133} // namespace simdjson
1134
1135#endif // SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
A document_reference is a thin wrapper around a document reference instance.
Definition document.h:816
simdjson_warn_unused simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition document.h:877
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:794
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:232
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:793
simdjson_inline simdjson_result< std::vector< value > > at_path_with_wildcard(std::string_view json_path) noexcept
Get all values matching the given JSONPath expression with wildcard support.
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:186
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