1#ifndef SIMDJSON_GENERIC_ONDEMAND_VALUE_H
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_VALUE_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/implementation_simdjson_result_base.h"
7#include "simdjson/generic/ondemand/value_iterator.h"
8#include "simdjson/generic/ondemand/deserialize.h"
16namespace SIMDJSON_IMPLEMENTATION {
29 simdjson_inline
value() noexcept = default;
48#if SIMDJSON_SUPPORTS_CONCEPTS
49 noexcept(nothrow_gettable<T, value>)
54 static_assert(std::is_default_constructible<T>::value,
"The specified type is not default constructible.");
56 SIMDJSON_TRY(get<T>(out));
74#if SIMDJSON_SUPPORTS_CONCEPTS
75 noexcept(nothrow_gettable<T, value>)
80 #if SIMDJSON_SUPPORTS_CONCEPTS
81 if constexpr (custom_deserializable<T, value>) {
82 return deserialize(*
this, out);
83 }
else if constexpr (concepts::optional_type<T>) {
84 using value_type =
typename std::remove_cvref_t<T>::value_type;
97 return get<value_type>(out.value());
99 static_assert(!
sizeof(T),
"The get<T> method with type T is not implemented by the simdjson library. "
100 "And you do not seem to have added support for it. Indeed, we have that "
101 "simdjson::custom_deserializable<T> is false and the type T is not a default type "
102 "such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
103 "int64_t, uint32_t, int32_t, uint16_t, int16_t, uint8_t, int8_t, double, float, or bool.");
104 static_cast<void>(out);
110 static_assert(!
sizeof(T),
"The get method with given type is not implemented by the simdjson library. "
111 "The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
112 "int64_t, uint32_t, int32_t, uint16_t, int16_t, uint8_t, int8_t, double, float, and bool. We recommend you use get_double(), get_float(), "
113 "get_bool(), get_uint64(), get_int64(), get_uint32(), get_int32(), get_uint16(), get_int16(), get_uint8(), get_int8(), "
114 " get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
115 " You may also add support for custom types, see our documentation.");
116 static_cast<void>(out);
273#if SIMDJSON_SUPPORTS_FLOAT32_T
286#if SIMDJSON_SUPPORTS_FLOAT64_T
325#if SIMDJSON_SUPPORTS_CHAR8_T
358 template <
typename string_type>
359 simdjson_warn_unused simdjson_inline
error_code get_string(string_type& receiver,
bool allow_replacement =
false) noexcept;
403#if SIMDJSON_EXCEPTIONS
414 explicit simdjson_inline
operator T() noexcept(false);
421 simdjson_inline operator
array() noexcept(false);
428 simdjson_inline operator
object() noexcept(false);
435 simdjson_inline operator uint64_t() noexcept(false);
442 simdjson_inline operator int64_t() noexcept(false);
449 simdjson_inline operator
double() noexcept(false);
461 simdjson_inline operator std::
string_view() noexcept(false);
477 simdjson_inline operator
bool() noexcept(false);
825#if SIMDJSON_SUPPORTS_CONCEPTS
826 template <
typename Func>
827 requires std::invocable<Func, value>
829 template <
typename Func>
837 simdjson_inline
value(
const value_iterator &iter)
noexcept;
842 simdjson_inline
void skip() noexcept;
849 static simdjson_inline
value start(const value_iterator &iter) noexcept;
854 static simdjson_inline
value resume(const value_iterator &iter) noexcept;
864 value_iterator iter{};
905#if SIMDJSON_SUPPORTS_FLOAT32_T
908#if SIMDJSON_SUPPORTS_FLOAT64_T
912#if SIMDJSON_SUPPORTS_CHAR8_T
915 template <
typename string_type>
916 simdjson_warn_unused simdjson_inline
error_code get_string(string_type& receiver,
bool allow_replacement =
false)
noexcept;
923#if SIMDJSON_SUPPORTS_CONCEPTS
924 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::value>);
930#if SIMDJSON_SUPPORTS_CONCEPTS
931 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::value>);
936#if SIMDJSON_EXCEPTIONS
938 explicit simdjson_inline
operator T()
noexcept(
false);
941 simdjson_inline
operator uint64_t()
noexcept(
false);
942 simdjson_inline
operator int64_t()
noexcept(
false);
943 simdjson_inline
operator double()
noexcept(
false);
944 simdjson_inline
operator std::string_view()
noexcept(
false);
946 simdjson_inline
operator bool()
noexcept(
false);
1049#if SIMDJSON_SUPPORTS_CONCEPTS
1050 template <
typename Func>
1051 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
1053 template <
typename Func>
1055 simdjson_inline
error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback)
noexcept;
A forward-only JSON array.
A forward-only JSON array.
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.
static simdjson_inline value start(const value_iterator &iter) noexcept
Start a value at the current position.
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
simdjson_inline simdjson_result< const char * > current_location() noexcept
Returns the current location in the document if in bounds.
simdjson_inline simdjson_result< float > get_float_in_string() noexcept
Cast this JSON value (inside string) to a float (binary32).
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< T > get() noexcept
Get this value as the given type.
simdjson_inline bool is_negative() noexcept
Checks whether the value is a negative number.
simdjson_inline simdjson_result< float > get_float() noexcept
Cast this JSON value to a float (binary32).
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< array > get_array() noexcept
Cast this JSON value to an array.
simdjson_inline std::string_view raw_json_token() noexcept
Get the raw JSON for this token.
simdjson_inline simdjson_result< object > get_object() noexcept
Cast this JSON value to an object.
simdjson_inline simdjson_result< uint8_t > get_uint8() noexcept
Cast this JSON value to an 8-bit unsigned 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< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
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< bool > is_integer() noexcept
Checks whether the value is an integer number.
simdjson_inline simdjson_result< int8_t > get_int8() noexcept
Cast this JSON value to an 8-bit signed integer.
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
simdjson_inline simdjson_result< value > at_path(std::string_view at_path) noexcept
Get the value associated with the given JSONPath expression.
simdjson_inline simdjson_result< object > start_or_resume_object() noexcept
Get the object, starting or resuming it as necessary.
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to a unsigned integer.
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
simdjson_inline simdjson_result< int16_t > get_int16() noexcept
Cast this JSON value to a 16-bit signed integer.
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the value is a scalar (string, number, null, Boolean).
simdjson_inline operator std::string_view() noexcept(false)
Cast this JSON value to a string.
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Get a string_view pointing at this value in the JSON document.
static simdjson_inline value resume(const value_iterator &iter) noexcept
Resume a value.
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
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< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a "wobbly" string.
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
simdjson_inline value() noexcept=default
Create a new invalid value.
simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func &&callback) noexcept
Call the provided callback for each value matching the given JSONPath expression with wildcard suppor...
simdjson_warn_unused simdjson_inline error_code get(T &out) noexcept
Get this value as the given type.
simdjson_inline simdjson_result< json_type > type() noexcept
Get the type of this JSON value.
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
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< value > at(size_t index) noexcept
Get the value at the given index in the array.
simdjson_inline simdjson_result< uint16_t > get_uint16() noexcept
Cast this JSON value to a 16-bit unsigned integer.
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
simdjson_inline void skip() noexcept
Skip this value, allowing iteration to continue.
simdjson_inline simdjson_result< int32_t > get_int32() noexcept
Cast this JSON value to a 32-bit signed integer.
simdjson_inline simdjson_result< uint32_t > get_uint32() noexcept
Cast this JSON value to a 32-bit unsigned integer.
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the value is a string.
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.