1#ifndef SIMDJSON_GENERIC_ONDEMAND_ARRAY_ITERATOR_INL_H
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_ARRAY_ITERATOR_INL_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/ondemand/array_iterator.h"
7#include "simdjson/generic/ondemand/value-inl.h"
8#include "simdjson/generic/ondemand/value_iterator-inl.h"
12namespace SIMDJSON_IMPLEMENTATION {
19#if SIMDJSON_DEVELOPMENT_CHECKS
21 : parent{_parent}, iter{_iter}
23 if (parent) parent->set_locked(
true);
26simdjson_inline array_iterator::~array_iterator() noexcept
28 if (parent) parent->set_locked(
false);
32 : has_been_referenced{other.has_been_referenced},
34 iter{std::move(other.iter)}
36 other.parent =
nullptr;
39simdjson_inline array_iterator& array_iterator::operator=(array_iterator&& other)
noexcept {
43 parent->set_locked(
false);
44 has_been_referenced = other.has_been_referenced;
45 parent = other.parent;
46 iter = std::move(other.iter);
48 other.parent =
nullptr;
54 : has_been_referenced{other.has_been_referenced},
59simdjson_inline array_iterator& array_iterator::operator=(
const array_iterator& other)
noexcept {
63 parent->set_locked(
false);
64 has_been_referenced = other.has_been_referenced;
73#if SIMDJSON_DEVELOPMENT_CHECKS
74 SIMDJSON_ASSUME(!has_been_referenced);
75 has_been_referenced =
true;
77 if (iter.error()) { iter.abandon();
return iter.error(); }
78 return value(iter.child());
81 return !(*
this != other);
84 return iter.is_open();
87#if SIMDJSON_DEVELOPMENT_CHECKS
88 has_been_referenced =
false;
93 if (( error = iter.error() )) {
return *
this; }
94 if (( error = iter.skip_child() )) {
return *
this; }
95 if (( error = iter.has_next_element().error() )) {
return *
this; }
100 return iter.at_end();
108simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(
109 SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value
111 : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(value))
113 first.iter.assert_is_valid();
115simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(
error_code error) noexcept
116 : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>({}, error)
120simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator*() noexcept {
121 if (error()) {
return error(); }
124simdjson_inline
bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator==(
const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other)
const noexcept {
125 if (!first.iter.is_valid()) {
return !error(); }
126 return first == other.first;
128simdjson_inline
bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator!=(
const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other)
const noexcept {
129 if (!first.iter.is_valid()) {
return error(); }
130 return first != other.first;
132simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator++() noexcept {
134 if (error()) { second =
SUCCESS;
return *
this; }
138simdjson_inline
bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::at_end() const noexcept {
139 return !first.iter.is_valid() || first.at_end();
A forward-only JSON array.
simdjson_inline simdjson_result< value > operator*() noexcept
Get the current element.
simdjson_inline bool operator==(const array_iterator &) const noexcept
Check if we are at the end of the JSON.
simdjson_inline array_iterator & operator++() noexcept
Move to the next element.
simdjson_inline array_iterator() noexcept=default
Create a new, invalid array iterator.
simdjson_inline bool operator!=(const array_iterator &) const noexcept
Check if there are more elements in the JSON array.
simdjson_warn_unused simdjson_inline bool at_end() const noexcept
Check if the array is at the end.
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.
The result of a simdjson operation that could fail.