simdjson  3.1.5
Ridiculously Fast JSON
array_iterator-inl.h
1 namespace simdjson {
2 namespace SIMDJSON_IMPLEMENTATION {
3 namespace ondemand {
4 
5 simdjson_inline array_iterator::array_iterator(const value_iterator &_iter) noexcept
6  : iter{_iter}
7 {}
8 
10  if (iter.error()) { iter.abandon(); return iter.error(); }
11  return value(iter.child());
12 }
13 simdjson_inline bool array_iterator::operator==(const array_iterator &other) const noexcept {
14  return !(*this != other);
15 }
16 simdjson_inline bool array_iterator::operator!=(const array_iterator &) const noexcept {
17  return iter.is_open();
18 }
19 simdjson_inline array_iterator &array_iterator::operator++() noexcept {
20  error_code error;
21  // PERF NOTE this is a safety rail ... users should exit loops as soon as they receive an error, so we'll never get here.
22  // However, it does not seem to make a perf difference, so we add it out of an abundance of caution.
23  if (( error = iter.error() )) { return *this; }
24  if (( error = iter.skip_child() )) { return *this; }
25  if (( error = iter.has_next_element().error() )) { return *this; }
26  return *this;
27 }
28 
29 } // namespace ondemand
30 } // namespace SIMDJSON_IMPLEMENTATION
31 } // namespace simdjson
32 
33 namespace simdjson {
34 
35 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(
36  SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value
37 ) noexcept
38  : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(value))
39 {
40  first.iter.assert_is_valid();
41 }
42 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(error_code error) noexcept
43  : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>({}, error)
44 {
45 }
46 
47 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator*() noexcept {
48  if (error()) { return error(); }
49  return *first;
50 }
51 simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator==(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other) const noexcept {
52  if (!first.iter.is_valid()) { return !error(); }
53  return first == other.first;
54 }
55 simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator!=(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other) const noexcept {
56  if (!first.iter.is_valid()) { return error(); }
57  return first != other.first;
58 }
59 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator++() noexcept {
60  // Clear the error if there is one, so we don't yield it twice
61  if (error()) { second = SUCCESS; return *this; }
62  ++(first);
63  return *this;
64 }
65 
66 } // namespace simdjson
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.
An ephemeral JSON value returned during iteration.
Definition: value.h:17
We want to support argument-dependent lookup (ADL).
error_code
All possible errors returned by simdjson.
Definition: error.h:17
@ SUCCESS
No error.
Definition: error.h:18
The result of a simdjson operation that could fail.
Definition: error.h:205
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:132