simdjson  3.1.1
Ridiculously Fast JSON
array.h
1 #ifndef SIMDJSON_DOM_ARRAY_H
2 #define SIMDJSON_DOM_ARRAY_H
3 
4 #include "simdjson/common_defs.h"
5 #include "simdjson/error.h"
6 #include "simdjson/internal/tape_ref.h"
7 
8 namespace simdjson {
9 
10 namespace internal {
11 template<typename T>
12 class string_builder;
13 }
14 namespace dom {
15 
16 class document;
17 class element;
18 
22 class array {
23 public:
25  simdjson_inline array() noexcept;
26 
27  class iterator {
28  public:
29  using value_type = element;
30  using difference_type = std::ptrdiff_t;
31 
35  inline value_type operator*() const noexcept;
41  inline iterator& operator++() noexcept;
47  inline iterator operator++(int) noexcept;
53  inline bool operator!=(const iterator& other) const noexcept;
54  inline bool operator==(const iterator& other) const noexcept;
55 
56  inline bool operator<(const iterator& other) const noexcept;
57  inline bool operator<=(const iterator& other) const noexcept;
58  inline bool operator>=(const iterator& other) const noexcept;
59  inline bool operator>(const iterator& other) const noexcept;
60 
61  iterator() noexcept = default;
62  iterator(const iterator&) noexcept = default;
63  iterator& operator=(const iterator&) noexcept = default;
64  private:
65  simdjson_inline iterator(const internal::tape_ref &tape) noexcept;
66  internal::tape_ref tape;
67  friend class array;
68  };
69 
75  inline iterator begin() const noexcept;
81  inline iterator end() const noexcept;
87  inline size_t size() const noexcept;
98  inline size_t number_of_slots() const noexcept;
115  inline simdjson_result<element> at_pointer(std::string_view json_pointer) const noexcept;
116 
133  inline simdjson_result<element> at(size_t index) const noexcept;
134 
135 private:
136  simdjson_inline array(const internal::tape_ref &tape) noexcept;
137  internal::tape_ref tape;
138  friend class element;
139  friend struct simdjson_result<element>;
140  template<typename T>
141  friend class simdjson::internal::string_builder;
142 };
143 
144 
145 } // namespace dom
146 
148 template<>
149 struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
150 public:
151  simdjson_inline simdjson_result() noexcept;
152  simdjson_inline simdjson_result(dom::array value) noexcept;
153  simdjson_inline simdjson_result(error_code error) noexcept;
154 
155  inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
156  inline simdjson_result<dom::element> at(size_t index) const noexcept;
157 
158 #if SIMDJSON_EXCEPTIONS
159  inline dom::array::iterator begin() const noexcept(false);
160  inline dom::array::iterator end() const noexcept(false);
161  inline size_t size() const noexcept(false);
162 #endif // SIMDJSON_EXCEPTIONS
163 };
164 
165 
166 
167 } // namespace simdjson
168 
169 #if defined(__cpp_lib_ranges)
170 #include <ranges>
171 
172 namespace std {
173 namespace ranges {
174 template<>
175 inline constexpr bool enable_view<simdjson::dom::array> = true;
176 #if SIMDJSON_EXCEPTIONS
177 template<>
178 inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
179 #endif // SIMDJSON_EXCEPTIONS
180 } // namespace ranges
181 } // namespace std
182 #endif // defined(__cpp_lib_ranges)
183 
184 #endif // SIMDJSON_DOM_ARRAY_H
bool operator!=(const iterator &other) const noexcept
Check if these values come from the same place in the JSON.
Definition: array-inl.h:138
iterator & operator++() noexcept
Get the next value.
Definition: array-inl.h:129
value_type operator*() const noexcept
Get the actual value.
Definition: array-inl.h:126
JSON array.
Definition: array.h:22
size_t number_of_slots() const noexcept
Get the total number of slots used by this array on the tape.
Definition: array-inl.h:67
iterator end() const noexcept
One past the last array element.
Definition: array-inl.h:59
size_t size() const noexcept
Get the size of the array (number of immediate children).
Definition: array-inl.h:63
simdjson_result< element > at(size_t index) const noexcept
Get the value at the given index.
Definition: array-inl.h:112
simdjson_result< element > at_pointer(std::string_view json_pointer) const noexcept
Get the value associated with the given JSON pointer.
Definition: array-inl.h:71
simdjson_inline array() noexcept
Create a new, invalid array.
Definition: array-inl.h:53
iterator begin() const noexcept
Return the first array element.
Definition: array-inl.h:55
A JSON element.
Definition: element.h:40
We want to support argument-dependent lookup (ADL).
error_code
All possible errors returned by simdjson.
Definition: error.h:17
The result of a JSON navigation that may fail.
Definition: element.h:482
The result of a simdjson operation that could fail.
Definition: error.h:205