1#ifndef SIMDJSON_GENERIC_ONDEMAND_ARRAY_INL_H
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_ARRAY_INL_H
5#include "simdjson/jsonpathutil.h"
6#include "simdjson/generic/ondemand/base.h"
7#include "simdjson/generic/ondemand/array.h"
8#include "simdjson/generic/ondemand/array_iterator-inl.h"
9#include "simdjson/generic/ondemand/json_iterator.h"
10#include "simdjson/generic/ondemand/value.h"
11#include "simdjson/generic/ondemand/value_iterator-inl.h"
15namespace SIMDJSON_IMPLEMENTATION {
64 simdjson_unused
bool has_value;
65 SIMDJSON_TRY( iter.start_array().get(has_value) );
69 simdjson_unused
bool has_value;
70 SIMDJSON_TRY( iter.start_root_array().get(has_value) );
75 SIMDJSON_TRY(iter.started_array().get(has_value));
80#if SIMDJSON_DEVELOPMENT_CHECKS
87#if SIMDJSON_DEVELOPMENT_CHECKS
97 auto error =
iter.json_iter().skip_child(
iter.depth()-1);
98 if(error) {
iter.abandon(); }
103 const uint8_t * starting_point{
iter.peek_start()};
105 if(error) {
return error; }
109 const uint8_t * final_point{
iter._json_iter->unsafe_pointer()};
110 return std::string_view(
reinterpret_cast<const char*
>(starting_point),
size_t(final_point - starting_point));
113SIMDJSON_PUSH_DISABLE_WARNINGS
114SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
116#if SIMDJSON_DEVELOPMENT_CHECKS
121 for(simdjson_unused
auto v : *
this) { count++; }
123 if(iter.error()) {
return iter.
error(); }
129SIMDJSON_POP_DISABLE_WARNINGS
132#if SIMDJSON_DEVELOPMENT_CHECKS
136 auto error = iter.reset_array().get(is_not_empty);
137 if(error) {
return error; }
138 return !is_not_empty;
142#if SIMDJSON_DEVELOPMENT_CHECKS
145 return iter.reset_array();
148#if SIMDJSON_DEVELOPMENT_CHECKS
149simdjson_inline
void array::set_locked(
bool _locked)
noexcept {
156 json_pointer = json_pointer.substr(1);
161 size_t array_index = 0;
163 SIMDJSON_TRY(internal::parse_json_pointer_array_index(json_pointer, array_index, i));
165 auto child = at(array_index);
172 if (i < json_pointer.length()) {
173 child = child.at_pointer(json_pointer.substr(i));
181 return at_pointer(json_pointer);
184#if SIMDJSON_SUPPORTS_CONCEPTS
185template <
typename Func>
186 requires std::invocable<Func, value>
188template <
typename Func>
191 auto result_pair = get_next_key_and_json_path(json_path);
192 std::string_view key = result_pair.first;
193 std::string_view remaining_path = result_pair.second;
202 for(
auto element: *
this) {
204 SIMDJSON_TRY(element.get(val));
205 if (remaining_path.empty()) {
208 error_code err = element.for_each_at_path_with_wildcard(remaining_path, callback);
209 if(err) {
return err; }
218 if(c <
'0' || c >
'9'){
221 idx = idx*10 + (c -
'0');
224 auto element = at(idx);
226 SIMDJSON_TRY(element.get(val));
227 if (remaining_path.empty()){
231 return element.for_each_at_path_with_wildcard(remaining_path, callback);
237#if SIMDJSON_DEVELOPMENT_CHECKS
241 for (
auto value : *
this) {
242 if (i == index) {
return value; }
254simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::simdjson_result(
255 SIMDJSON_IMPLEMENTATION::ondemand::array &&value
257 : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array>(
258 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::array>(value)
262simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::simdjson_result(
265 : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array>(error)
269simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::begin() &
noexcept {
270 if (error()) {
return error(); }
271 return first.begin();
273simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::begin() &&
noexcept {
274 if (error()) {
return error(); }
275 return std::move(first).begin();
277simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::end() noexcept {
278 if (error()) {
return error(); }
281simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::count_elements() &
noexcept {
282 if (error()) {
return error(); }
283 return first.count_elements();
285simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::is_empty() &
noexcept {
286 if (error()) {
return error(); }
287 return first.is_empty();
289simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::at(
size_t index)
noexcept {
290 if (error()) {
return error(); }
291 return first.at(index);
293simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::at_pointer(std::string_view json_pointer)
noexcept {
294 if (error()) {
return error(); }
295 return first.at_pointer(json_pointer);
297simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::at_path(std::string_view json_path)
noexcept {
298 if (error()) {
return error(); }
299 return first.at_path(json_path);
301#if SIMDJSON_SUPPORTS_CONCEPTS
302template <
typename Func>
303 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
305template <
typename Func>
307simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback)
noexcept {
308 if (error()) {
return error(); }
309 return first.for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
311simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::raw_json() noexcept {
312 if (error()) {
return error(); }
313 return first.raw_json();
A forward-only JSON array.
A forward-only JSON array.
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_inline simdjson_result< value > at(size_t index) noexcept
Get the value at the given index.
value_iterator iter
Iterator marking current position.
simdjson_inline simdjson_result< bool > is_empty() &noexcept
This method scans the beginning of the array and checks whether the array is empty.
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
static simdjson_inline simdjson_result< array > start(value_iterator &iter) noexcept
Begin array iteration.
simdjson_inline array() noexcept=default
Create a new invalid array.
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
static simdjson_inline simdjson_result< array > start_root(value_iterator &iter) noexcept
Begin array iteration from the root.
static simdjson_inline simdjson_result< array > started(value_iterator &iter) noexcept
Begin array iteration.
simdjson_warn_unused simdjson_inline error_code consume() noexcept
Go to the end of the array, no matter where you are right now.
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Consumes the array and returns a string_view instance corresponding to the array as represented in JS...
simdjson_inline simdjson_result< array_iterator > end() noexcept
Sentinel representing the end of the array.
simdjson_result< bool > reset() &noexcept
Reset the iterator so that we are pointing back at the beginning of the array.
An ephemeral JSON value returned during iteration.
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
@ OUT_OF_ORDER_ITERATION
tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
@ INDEX_OUT_OF_BOUNDS
JSON array index too large.
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
std::string json_path_to_pointer_conversion(std::string_view json_path)
Converts JSONPath to JSON Pointer.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.