simdjson 4.0.7
Ridiculously Fast JSON
Loading...
Searching...
No Matches
array_iterator-inl.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_ARRAY_ITERATOR_INL_H
2
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"
9#endif // SIMDJSON_CONDITIONAL_INCLUDE
10
11namespace simdjson {
12namespace SIMDJSON_IMPLEMENTATION {
13namespace ondemand {
14
15simdjson_inline array_iterator::array_iterator(const value_iterator &_iter) noexcept
16 : iter{_iter}
17{}
18
20 if (iter.error()) { iter.abandon(); return iter.error(); }
21 return value(iter.child());
22}
23simdjson_inline bool array_iterator::operator==(const array_iterator &other) const noexcept {
24 return !(*this != other);
25}
26simdjson_inline bool array_iterator::operator!=(const array_iterator &) const noexcept {
27 return iter.is_open();
28}
30 error_code error;
31 // PERF NOTE this is a safety rail ... users should exit loops as soon as they receive an error, so we'll never get here.
32 // However, it does not seem to make a perf difference, so we add it out of an abundance of caution.
33 if (( error = iter.error() )) { return *this; }
34 if (( error = iter.skip_child() )) { return *this; }
35 if (( error = iter.has_next_element().error() )) { return *this; }
36 return *this;
37}
38
39simdjson_inline bool array_iterator::at_end() const noexcept {
40 return iter.at_end();
41}
42} // namespace ondemand
43} // namespace SIMDJSON_IMPLEMENTATION
44} // namespace simdjson
45
46namespace simdjson {
47
48simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(
49 SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value
50) noexcept
51 : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(value))
52{
53 first.iter.assert_is_valid();
54}
55simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(error_code error) noexcept
56 : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>({}, error)
57{
58}
59
60simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator*() noexcept {
61 if (error()) { return error(); }
62 return *first;
63}
64simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator==(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other) const noexcept {
65 if (!first.iter.is_valid()) { return !error(); }
66 return first == other.first;
67}
68simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator!=(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other) const noexcept {
69 if (!first.iter.is_valid()) { return error(); }
70 return first != other.first;
71}
72simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator++() noexcept {
73 // Clear the error if there is one, so we don't yield it twice
74 if (error()) { second = SUCCESS; return *this; }
75 ++(first);
76 return *this;
77}
78simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::at_end() const noexcept {
79 return !first.iter.is_valid() || first.at_end();
80}
81} // namespace simdjson
82
83#endif // SIMDJSON_GENERIC_ONDEMAND_ARRAY_ITERATOR_INL_H
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.
Definition value.h:21
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
@ SUCCESS
No error.
Definition error.h:20