1#include "simdjson/error.h"
2
3namespace simdjson {
4namespace SIMDJSON_IMPLEMENTATION {
5namespace ondemand {
6
7class field;
8
9class object_iterator {
10public:
11 /**
12 * Create a new invalid object_iterator.
13 *
14 * Exists so you can declare a variable and later assign to it before use.
15 */
16 simdjson_inline object_iterator() noexcept = default;
17
18 //
19 // Iterator interface
20 //
21
22 // Reads key and value, yielding them to the user.
23 // MUST ONLY BE CALLED ONCE PER ITERATION.
24 simdjson_inline simdjson_result<field> operator*() noexcept;
25 // Assumes it's being compared with the end. true if depth < iter->depth.
26 simdjson_inline bool operator==(const object_iterator &) const noexcept;
27 // Assumes it's being compared with the end. true if depth >= iter->depth.
28 simdjson_inline bool operator!=(const object_iterator &) const noexcept;
29 // Checks for ']' and ','
30 simdjson_inline object_iterator &operator++() noexcept;
31
32private:
33 /**
34 * The underlying JSON iterator.
35 *
36 * PERF NOTE: expected to be elided in favor of the parent document: this is set when the object
37 * is first used, and never changes afterwards.
38 */
39 value_iterator iter{};
40
41 simdjson_inline object_iterator(const value_iterator &iter) noexcept;
42 friend struct simdjson_result<object_iterator>;
43 friend class object;
44};
45
46} // namespace ondemand
47} // namespace SIMDJSON_IMPLEMENTATION
48} // namespace simdjson
49
50namespace simdjson {
51
52template<>
53struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> {
54public:
55 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::object_iterator &&value) noexcept; ///< @private
56 simdjson_inline simdjson_result(error_code error) noexcept; ///< @private
57 simdjson_inline simdjson_result() noexcept = default;
58
59 //
60 // Iterator interface
61 //
62
63 // Reads key and value, yielding them to the user.
64 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field> operator*() noexcept; // MUST ONLY BE CALLED ONCE PER ITERATION.
65 // Assumes it's being compared with the end. true if depth < iter->depth.
66 simdjson_inline bool operator==(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> &) const noexcept;
67 // Assumes it's being compared with the end. true if depth >= iter->depth.
68 simdjson_inline bool operator!=(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> &) const noexcept;
69 // Checks for ']' and ','
70 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> &operator++() noexcept;
71};
72
73} // namespace simdjson
74