1 | #include "simdjson/error.h" |
---|---|
2 | |
3 | namespace simdjson { |
4 | namespace SIMDJSON_IMPLEMENTATION { |
5 | namespace ondemand { |
6 | |
7 | class array; |
8 | class value; |
9 | class document; |
10 | |
11 | /** |
12 | * A forward-only JSON array. |
13 | * |
14 | * This is an input_iterator, meaning: |
15 | * - It is forward-only |
16 | * - * must be called exactly once per element. |
17 | * - ++ must be called exactly once in between each * (*, ++, *, ++, * ...) |
18 | */ |
19 | class array_iterator { |
20 | public: |
21 | /** Create a new, invalid array iterator. */ |
22 | simdjson_inline array_iterator() noexcept = default; |
23 | |
24 | // |
25 | // Iterator interface |
26 | // |
27 | |
28 | /** |
29 | * Get the current element. |
30 | * |
31 | * Part of the std::iterator interface. |
32 | */ |
33 | simdjson_inline simdjson_result<value> operator*() noexcept; // MUST ONLY BE CALLED ONCE PER ITERATION. |
34 | /** |
35 | * Check if we are at the end of the JSON. |
36 | * |
37 | * Part of the std::iterator interface. |
38 | * |
39 | * @return true if there are no more elements in the JSON array. |
40 | */ |
41 | simdjson_inline bool operator==(const array_iterator &) const noexcept; |
42 | /** |
43 | * Check if there are more elements in the JSON array. |
44 | * |
45 | * Part of the std::iterator interface. |
46 | * |
47 | * @return true if there are more elements in the JSON array. |
48 | */ |
49 | simdjson_inline bool operator!=(const array_iterator &) const noexcept; |
50 | /** |
51 | * Move to the next element. |
52 | * |
53 | * Part of the std::iterator interface. |
54 | */ |
55 | simdjson_inline array_iterator &operator++() noexcept; |
56 | |
57 | private: |
58 | value_iterator iter{}; |
59 | |
60 | simdjson_inline array_iterator(const value_iterator &iter) noexcept; |
61 | |
62 | friend class array; |
63 | friend class value; |
64 | friend struct simdjson_result<array_iterator>; |
65 | }; |
66 | |
67 | } // namespace ondemand |
68 | } // namespace SIMDJSON_IMPLEMENTATION |
69 | } // namespace simdjson |
70 | |
71 | namespace simdjson { |
72 | |
73 | template<> |
74 | struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> { |
75 | public: |
76 | simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value) noexcept; ///< @private |
77 | simdjson_inline simdjson_result(error_code error) noexcept; ///< @private |
78 | simdjson_inline simdjson_result() noexcept = default; |
79 | |
80 | // |
81 | // Iterator interface |
82 | // |
83 | |
84 | simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator*() noexcept; // MUST ONLY BE CALLED ONCE PER ITERATION. |
85 | simdjson_inline bool operator==(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &) const noexcept; |
86 | simdjson_inline bool operator!=(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &) const noexcept; |
87 | simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &operator++() noexcept; |
88 | }; |
89 | |
90 | } // namespace simdjson |
91 |