1namespace simdjson {
2namespace SIMDJSON_IMPLEMENTATION {
3namespace ondemand {
4
5simdjson_inline array_iterator::array_iterator(const value_iterator &_iter) noexcept
6 : iter{_iter}
7{}
8
9simdjson_inline simdjson_result<value> array_iterator::operator*() noexcept {
10 if (iter.error()) { iter.abandon(); return iter.error(); }
11 return value(iter.child());
12}
13simdjson_inline bool array_iterator::operator==(const array_iterator &other) const noexcept {
14 return !(*this != other);
15}
16simdjson_inline bool array_iterator::operator!=(const array_iterator &) const noexcept {
17 return iter.is_open();
18}
19simdjson_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
33namespace simdjson {
34
35simdjson_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>(t&: value))
39{
40 first.iter.assert_is_valid();
41}
42simdjson_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
47simdjson_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}
51simdjson_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}
55simdjson_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}
59simdjson_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
67