1#ifndef SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_H
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"
13namespace SIMDJSON_IMPLEMENTATION {
33 simdjson_inline
document &operator=(const
document &other) noexcept = delete;
119 template <typename string_type>
120 simdjson_warn_unused simdjson_inline
error_code get_string(string_type& receiver,
bool allow_replacement = false) noexcept;
184 template <typename T>
186#if SIMDJSON_SUPPORTS_CONCEPTS
187 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> :
true)
192 static_assert(std::is_default_constructible<T>::value,
"Cannot initialize the specified type.");
194 SIMDJSON_TRY(get<T>(out));
209#if SIMDJSON_SUPPORTS_CONCEPTS
210 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> :
true)
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.");
232#if SIMDJSON_SUPPORTS_CONCEPTS
233 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> :
true)
238#if SIMDJSON_SUPPORTS_CONCEPTS
239 if constexpr (custom_deserializable<T, document>) {
240 return deserialize(*
this, out);
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);
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);
264 template<
typename T> simdjson_deprecated simdjson_inline
error_code get(T &out) &&
noexcept;
266#if SIMDJSON_EXCEPTIONS
277 explicit simdjson_inline
operator T() &
noexcept(
false);
279 explicit simdjson_deprecated simdjson_inline
operator T() &&
noexcept(
false);
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);
624 inline
void rewind() noexcept;
645 inline
bool at_end() const noexcept;
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;
764 simdjson_inline
document(ondemand::json_iterator &&
iter) noexcept;
765 simdjson_inline const uint8_t *text(uint32_t idx) const noexcept;
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;
780 friend class ondemand::parser;
804 simdjson_inline
void rewind()
noexcept;
814 template <
typename string_type>
815 simdjson_warn_unused simdjson_inline
error_code get_string(string_type& receiver,
bool allow_replacement =
false)
noexcept;
822 template <
typename T>
824#if SIMDJSON_SUPPORTS_CONCEPTS
825 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> :
true)
830 static_assert(std::is_default_constructible<T>::value,
"Cannot initialize the specified type.");
832 SIMDJSON_TRY(get<T>(out));
837#if SIMDJSON_SUPPORTS_CONCEPTS
838 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document> :
true)
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.");
860#if SIMDJSON_SUPPORTS_CONCEPTS
861 noexcept(custom_deserializable<T, document> ? nothrow_custom_deserializable<T, document_reference> :
true)
866#if SIMDJSON_SUPPORTS_CONCEPTS
867 if constexpr (custom_deserializable<T, document_reference>) {
868 return deserialize(*
this, out);
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);
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);
892 template<
typename T> simdjson_inline
error_code get(T &out) &&
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;
899 simdjson_inline
operator document&()
const noexcept;
900#if SIMDJSON_EXCEPTIONS
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);
910 simdjson_inline operator
bool() noexcept(false);
911 simdjson_inline operator
value() noexcept(false);
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;
934 simdjson_inline
simdjson_result<number_type> get_number_type() noexcept;
936 simdjson_inline
simdjson_result<std::string_view> raw_json_token() noexcept;
950struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> :
public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document> {
952 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document &&value)
noexcept;
954 simdjson_inline simdjson_result() noexcept = default;
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;
974 template<typename T> simdjson_inline simdjson_result<T>
get() & noexcept;
975 template<typename T> simdjson_deprecated simdjson_inline simdjson_result<T>
get() && noexcept;
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
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);
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;
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;
1041 simdjson_inline
error_code rewind()
noexcept;
1052 template <
typename string_type>
1053 simdjson_warn_unused simdjson_inline
error_code get_string(string_type& receiver,
bool allow_replacement =
false)
noexcept;
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
1067 explicit simdjson_inline
operator T()
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);
1075 simdjson_inline
operator bool()
noexcept(
false);
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;
A forward-only JSON array.
A forward-only JSON array.
A document_reference is a thin wrapper around a document reference instance.
simdjson_warn_unused simdjson_inline error_code get(T &out) &noexcept
Get this value as the given type.
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
The document_reference instances are used primarily/solely for streams of JSON documents.
A forward-only stream of 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
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.
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.
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.
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.
A forward-only JSON object field iterator.
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
int32_t depth_t
Represents the depth of a JSON value (number of nested arrays/objects).
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
@ UNINITIALIZED
unknown error, or uninitialized document
The result of a simdjson operation that could fail.
A type representing a JSON number.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.