simdjson  3.11.0
Ridiculously Fast JSON
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 
12 namespace simdjson {
13 namespace SIMDJSON_IMPLEMENTATION {
14 namespace ondemand {
15 
23 class document {
24 public:
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_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_DESERIALIZATION
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_DESERIALIZATION
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_inline error_code get(T &out) &
232 #if SIMDJSON_SUPPORTS_DESERIALIZATION
233  noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
234 #else
235  noexcept
236 #endif
237  {
238 #if SIMDJSON_SUPPORTS_DESERIALIZATION
239  if constexpr (custom_deserializable<T, document>) {
240  return deserialize(*this, out);
241  } else {
242 #endif // SIMDJSON_SUPPORTS_DESERIALIZATION
243  // Unless the simdjson library or the user provides an inline implementation, calling this method should
244  // immediately fail.
245  static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
246  "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
247  "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
248  " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
249  " You may also add support for custom types, see our documentation.");
250  static_cast<void>(out); // to get rid of unused errors
251  return UNINITIALIZED;
252 #if SIMDJSON_SUPPORTS_DESERIALIZATION
253  }
254 #endif
255  }
257  template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) && noexcept;
258 
259 #if SIMDJSON_EXCEPTIONS
269  template <class T>
270  explicit simdjson_inline operator T() & noexcept(false);
271  template <class T>
272  explicit simdjson_deprecated simdjson_inline operator T() && noexcept(false);
273 
280  simdjson_inline operator array() & noexcept(false);
287  simdjson_inline operator object() & noexcept(false);
294  simdjson_inline operator uint64_t() noexcept(false);
301  simdjson_inline operator int64_t() noexcept(false);
308  simdjson_inline operator double() noexcept(false);
318  simdjson_inline operator std::string_view() noexcept(false);
327  simdjson_inline operator raw_json_string() noexcept(false);
334  simdjson_inline operator bool() noexcept(false);
346  simdjson_inline operator value() noexcept(false);
347 #endif
360  simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
375  simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
383  simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
389  simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
395  simdjson_inline simdjson_result<array_iterator> end() & noexcept;
396 
429  simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
431  simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
432 
463  simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
465  simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
467  simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
469  simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
470  simdjson_result<value> operator[](int) & noexcept = delete;
471 
483  simdjson_inline simdjson_result<json_type> type() noexcept;
484 
492  simdjson_inline simdjson_result<bool> is_scalar() noexcept;
493 
500  simdjson_inline simdjson_result<bool> is_string() noexcept;
501 
507  simdjson_inline bool is_negative() noexcept;
517  simdjson_inline simdjson_result<bool> is_integer() noexcept;
542  simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
543 
570  simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
571 
594  simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
595 
601  inline void rewind() noexcept;
605  inline std::string to_debug_string() noexcept;
610  inline bool is_alive() noexcept;
611 
615  inline simdjson_result<const char *> current_location() const noexcept;
616 
622  inline bool at_end() const noexcept;
623 
633  simdjson_inline int32_t current_depth() const noexcept;
634 
674  simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
675 
697  simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
698 
704  simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
705 protected:
709  simdjson_inline error_code consume() noexcept;
710 
711  simdjson_inline document(ondemand::json_iterator &&iter) noexcept;
712  simdjson_inline const uint8_t *text(uint32_t idx) const noexcept;
713 
714  simdjson_inline value_iterator resume_value_iterator() noexcept;
715  simdjson_inline value_iterator get_root_value_iterator() noexcept;
716  simdjson_inline simdjson_result<object> start_or_resume_object() noexcept;
717  static simdjson_inline document start(ondemand::json_iterator &&iter) noexcept;
718 
719  //
720  // Fields
721  //
722  json_iterator iter{};
723  static constexpr depth_t DOCUMENT_DEPTH = 0;
724 
725  friend class array_iterator;
726  friend class value;
727  friend class ondemand::parser;
728  friend class object;
729  friend class array;
730  friend class field;
731  friend class token;
732  friend class document_stream;
733  friend class document_reference;
734 };
735 
736 
746 public:
747  simdjson_inline document_reference() noexcept;
748  simdjson_inline document_reference(document &d) noexcept;
749  simdjson_inline document_reference(const document_reference &other) noexcept = default;
750  simdjson_inline document_reference& operator=(const document_reference &other) noexcept = default;
751  simdjson_inline void rewind() noexcept;
752  simdjson_inline simdjson_result<array> get_array() & noexcept;
753  simdjson_inline simdjson_result<object> get_object() & noexcept;
754  simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
755  simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
756  simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
757  simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
758  simdjson_inline simdjson_result<double> get_double() noexcept;
759  simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
760  simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
761  template <typename string_type>
762  simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
763  simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
764  simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
765  simdjson_inline simdjson_result<bool> get_bool() noexcept;
766  simdjson_inline simdjson_result<value> get_value() noexcept;
767 
768  simdjson_inline simdjson_result<bool> is_null() noexcept;
769  template <typename T>
770  simdjson_inline simdjson_result<T> get() &
771 #if SIMDJSON_SUPPORTS_DESERIALIZATION
772  noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
773 #else
774  noexcept
775 #endif
776  {
777  static_assert(std::is_default_constructible<T>::value, "Cannot initialize the specified type.");
778  T out{};
779  SIMDJSON_TRY(get<T>(out));
780  return out;
781  }
782  template<typename T>
783  simdjson_inline simdjson_result<T> get() &&
784 #if SIMDJSON_SUPPORTS_DESERIALIZATION
785  noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> : true)
786 #else
787  noexcept
788 #endif
789  {
790  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.");
791  return static_cast<document&>(*this).get<T>();
792  }
793 
805  template<typename T>
806  simdjson_inline error_code get(T &out) &
807 #if SIMDJSON_SUPPORTS_DESERIALIZATION
808  noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document_reference> : true)
809 #else
810  noexcept
811 #endif
812  {
813 #if SIMDJSON_SUPPORTS_DESERIALIZATION
814  if constexpr (custom_deserializable<T, document_reference>) {
815  return deserialize(*this, out);
816  } else {
817 #endif // SIMDJSON_SUPPORTS_DESERIALIZATION
818  // Unless the simdjson library or the user provides an inline implementation, calling this method should
819  // immediately fail.
820  static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
821  "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
822  "int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
823  " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
824  " You may also add support for custom types, see our documentation.");
825  static_cast<void>(out); // to get rid of unused errors
826  return UNINITIALIZED;
827 #if SIMDJSON_SUPPORTS_DESERIALIZATION
828  }
829 #endif
830  }
832  template<typename T> simdjson_inline error_code get(T &out) && noexcept;
833  simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
834  simdjson_inline operator document&() const noexcept;
835 #if SIMDJSON_EXCEPTIONS
836  template <class T>
837  explicit simdjson_inline operator T() noexcept(false);
838  simdjson_inline operator array() & noexcept(false);
839  simdjson_inline operator object() & noexcept(false);
840  simdjson_inline operator uint64_t() noexcept(false);
841  simdjson_inline operator int64_t() noexcept(false);
842  simdjson_inline operator double() noexcept(false);
843  simdjson_inline operator std::string_view() noexcept(false);
844  simdjson_inline operator raw_json_string() noexcept(false);
845  simdjson_inline operator bool() noexcept(false);
846  simdjson_inline operator value() noexcept(false);
847 #endif
848  simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
849  simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
850  simdjson_inline simdjson_result<value> at(size_t index) & noexcept;
851  simdjson_inline simdjson_result<array_iterator> begin() & noexcept;
852  simdjson_inline simdjson_result<array_iterator> end() & noexcept;
853  simdjson_inline simdjson_result<value> find_field(std::string_view key) & noexcept;
854  simdjson_inline simdjson_result<value> find_field(const char *key) & noexcept;
855  simdjson_inline simdjson_result<value> operator[](std::string_view key) & noexcept;
856  simdjson_inline simdjson_result<value> operator[](const char *key) & noexcept;
857  simdjson_result<value> operator[](int) & noexcept = delete;
858  simdjson_inline simdjson_result<value> find_field_unordered(std::string_view key) & noexcept;
859  simdjson_inline simdjson_result<value> find_field_unordered(const char *key) & noexcept;
860 
861  simdjson_inline simdjson_result<json_type> type() noexcept;
862  simdjson_inline simdjson_result<bool> is_scalar() noexcept;
863  simdjson_inline simdjson_result<bool> is_string() noexcept;
864 
865  simdjson_inline simdjson_result<const char *> current_location() noexcept;
866  simdjson_inline int32_t current_depth() const noexcept;
867  simdjson_inline bool is_negative() noexcept;
868  simdjson_inline simdjson_result<bool> is_integer() noexcept;
869  simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
870  simdjson_inline simdjson_result<number> get_number() noexcept;
871  simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
872  simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
873  simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
874 
875 private:
876  document *doc{nullptr};
877 };
878 } // namespace ondemand
879 } // namespace SIMDJSON_IMPLEMENTATION
880 } // namespace simdjson
881 
882 namespace simdjson {
883 
884 template<>
885 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document> {
886 public:
888  simdjson_inline simdjson_result(error_code error) noexcept;
889  simdjson_inline simdjson_result() noexcept = default;
890  simdjson_inline error_code rewind() noexcept;
891 
892  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
893  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
894  simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
895  simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
896  simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
897  simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
898  simdjson_inline simdjson_result<double> get_double() noexcept;
899  simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
900  simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
901  template <typename string_type>
902  simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
903  simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
904  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
905  simdjson_inline simdjson_result<bool> get_bool() noexcept;
906  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
907  simdjson_inline simdjson_result<bool> is_null() noexcept;
908 
909  template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
910  template<typename T> simdjson_deprecated simdjson_inline simdjson_result<T> get() && noexcept;
911 
912  template<typename T> simdjson_inline error_code get(T &out) & noexcept;
913  template<typename T> simdjson_inline error_code get(T &out) && noexcept;
914 #if SIMDJSON_EXCEPTIONS
915  template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false>::type>
916  explicit simdjson_inline operator T() noexcept(false);
917  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
918  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
919  simdjson_inline operator uint64_t() noexcept(false);
920  simdjson_inline operator int64_t() noexcept(false);
921  simdjson_inline operator double() noexcept(false);
922  simdjson_inline operator std::string_view() noexcept(false);
923  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
924  simdjson_inline operator bool() noexcept(false);
925  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
926 #endif
927  simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
928  simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
929  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
932  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
933  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
934  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
935  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
936  simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
937  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
938  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
940  simdjson_inline simdjson_result<bool> is_scalar() noexcept;
941  simdjson_inline simdjson_result<bool> is_string() noexcept;
942  simdjson_inline simdjson_result<const char *> current_location() noexcept;
943  simdjson_inline int32_t current_depth() const noexcept;
944  simdjson_inline bool at_end() const noexcept;
945  simdjson_inline bool is_negative() noexcept;
946  simdjson_inline simdjson_result<bool> is_integer() noexcept;
947  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
948  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
950  simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
951 
952  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
953  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
954 };
955 
956 
957 } // namespace simdjson
958 
959 
960 
961 namespace simdjson {
962 
963 template<>
964 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> {
965 public:
967  simdjson_inline simdjson_result() noexcept = default;
968  simdjson_inline error_code rewind() noexcept;
969 
970  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> get_array() & noexcept;
971  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> get_object() & noexcept;
972  simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
973  simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
974  simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
975  simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
976  simdjson_inline simdjson_result<double> get_double() noexcept;
977  simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
978  simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
979  template <typename string_type>
980  simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement = false) noexcept;
981  simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
982  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
983  simdjson_inline simdjson_result<bool> get_bool() noexcept;
984  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> get_value() noexcept;
985  simdjson_inline simdjson_result<bool> is_null() noexcept;
986 
987  template<typename T> simdjson_inline simdjson_result<T> get() & noexcept;
988  template<typename T> simdjson_inline simdjson_result<T> get() && noexcept;
989 
990  template<typename T> simdjson_inline error_code get(T &out) & noexcept;
991  template<typename T> simdjson_inline error_code get(T &out) && noexcept;
992 #if SIMDJSON_EXCEPTIONS
993  template <class T>
994  explicit simdjson_inline operator T() noexcept(false);
995  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false);
996  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false);
997  simdjson_inline operator uint64_t() noexcept(false);
998  simdjson_inline operator int64_t() noexcept(false);
999  simdjson_inline operator double() noexcept(false);
1000  simdjson_inline operator std::string_view() noexcept(false);
1001  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false);
1002  simdjson_inline operator bool() noexcept(false);
1003  simdjson_inline operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false);
1004 #endif
1005  simdjson_inline simdjson_result<size_t> count_elements() & noexcept;
1006  simdjson_inline simdjson_result<size_t> count_fields() & noexcept;
1007  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) & noexcept;
1008  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> begin() & noexcept;
1010  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(std::string_view key) & noexcept;
1011  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field(const char *key) & noexcept;
1012  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) & noexcept;
1013  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](const char *key) & noexcept;
1014  simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](int) & noexcept = delete;
1015  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(std::string_view key) & noexcept;
1016  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> find_field_unordered(const char *key) & noexcept;
1017  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> type() noexcept;
1018  simdjson_inline simdjson_result<bool> is_scalar() noexcept;
1019  simdjson_inline simdjson_result<bool> is_string() noexcept;
1020  simdjson_inline simdjson_result<const char *> current_location() noexcept;
1021  simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
1022  simdjson_inline simdjson_result<bool> is_negative() noexcept;
1023  simdjson_inline simdjson_result<bool> is_integer() noexcept;
1024  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> get_number_type() noexcept;
1025  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> get_number() noexcept;
1027  simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
1028 
1029  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
1030  simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
1031 };
1032 
1033 
1034 } // namespace simdjson
1035 
1036 #endif // SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
A document_reference is a thin wrapper around a document reference instance.
Definition: document.h:745
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
The document_reference instances are used primarily/solely for streams of JSON documents.
Definition: document-inl.h:644
simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition: document.h:806
simdjson_inline simdjson_result< value > at(size_t index) &noexcept
Get the value at the given index in the array.
Definition: document-inl.h:218
static constexpr depth_t DOCUMENT_DEPTH
document depth is always 0
Definition: document.h:723
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
Definition: document-inl.h:45
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
Definition: document-inl.h:222
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
Definition: document-inl.h:211
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
Definition: document-inl.h:140
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
Definition: document-inl.h:296
bool is_alive() noexcept
Some unrecoverable error conditions may render the document instance unusable.
Definition: document-inl.h:54
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
Definition: document-inl.h:153
simdjson_inline simdjson_result< object > get_object() &noexcept
Cast this JSON value to an object.
Definition: document-inl.h:109
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the document is a string.
Definition: document-inl.h:277
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
Definition: document-inl.h:122
simdjson_inline bool is_negative() noexcept
Checks whether the document is a negative number.
Definition: document-inl.h:284
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.
Definition: document-inl.h:301
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to an unsigned integer.
Definition: document-inl.h:125
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
Definition: document-inl.h:156
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
Definition: document-inl.h:128
simdjson_inline simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
Definition: document-inl.h:306
simdjson_inline simdjson_result< json_type > type() noexcept
Get the type of this JSON value.
Definition: document-inl.h:266
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
Definition: document-inl.h:225
simdjson_inline simdjson_result< T > get() &noexcept
Get this value as the given type.
Definition: document.h:185
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
Definition: document-inl.h:137
simdjson_inline simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
Definition: document-inl.h:324
json_iterator iter
Current position in the document.
Definition: document.h:722
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
Definition: document-inl.h:134
std::string to_debug_string() noexcept
Returns debugging information.
Definition: document-inl.h:37
void rewind() noexcept
Reset the iterator inside the document instance so we are pointing back at the beginning of the docum...
Definition: document-inl.h:33
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...
Definition: document-inl.h:254
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.
Definition: document-inl.h:235
simdjson_inline simdjson_result< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
Definition: document-inl.h:131
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
Definition: document-inl.h:204
simdjson_inline simdjson_result< value > get_value() noexcept
Cast this JSON value to a value when the document is an object or an array.
Definition: document-inl.h:70
simdjson_inline simdjson_result< value > find_field(std::string_view key) &noexcept
Look up a field by name on an object (order-sensitive).
Definition: document-inl.h:229
simdjson_inline simdjson_result< number_type > get_number_type() noexcept
Determine the number type (integer or floating-point number) as quickly as possible.
Definition: document-inl.h:292
simdjson_inline error_code consume() noexcept
Consumes the document.
Definition: document-inl.h:248
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the document is a scalar (string, number, null, Boolean).
Definition: document-inl.h:270
simdjson_inline simdjson_result< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a string.
Definition: document-inl.h:147
bool at_end() const noexcept
Returns true if this document has been fully parsed.
Definition: document-inl.h:49
simdjson_inline simdjson_result< array > get_array() &noexcept
Cast this JSON value to an array.
Definition: document-inl.h:105
simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
Definition: document.h:231
simdjson_inline simdjson_result< bool > is_integer() noexcept
Checks whether the document is an integer number.
Definition: document-inl.h:288
simdjson_result< const char * > current_location() const noexcept
Returns the current location in the document if in bounds.
Definition: document-inl.h:41
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
Definition: document-inl.h:150
A JSON field (key/value pair) in an object.
Definition: field.h:22
A forward-only JSON object field iterator.
Definition: object.h:17
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:32
The result of a simdjson operation that could fail.
Definition: error.h:215
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:131
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
Definition: error-inl.h:126
simdjson_inline T & value() &noexcept(false)
Get the result value.