simdjson  3.11.0
Ridiculously Fast JSON
array.h
1 #ifndef SIMDJSON_DOM_ARRAY_H
2 #define SIMDJSON_DOM_ARRAY_H
3 
4 #include "simdjson/dom/base.h"
5 #include "simdjson/internal/tape_ref.h"
6 
7 namespace simdjson {
8 namespace dom {
9 
13 class array {
14 public:
16  simdjson_inline array() noexcept;
17 
18  class iterator {
19  public:
20  using value_type = element;
21  using difference_type = std::ptrdiff_t;
22  using pointer = void;
23  using reference = value_type;
24  using iterator_category = std::forward_iterator_tag;
25 
29  inline reference operator*() const noexcept;
35  inline iterator& operator++() noexcept;
41  inline iterator operator++(int) noexcept;
47  inline bool operator!=(const iterator& other) const noexcept;
48  inline bool operator==(const iterator& other) const noexcept;
49 
50  inline bool operator<(const iterator& other) const noexcept;
51  inline bool operator<=(const iterator& other) const noexcept;
52  inline bool operator>=(const iterator& other) const noexcept;
53  inline bool operator>(const iterator& other) const noexcept;
54 
55  iterator() noexcept = default;
56  iterator(const iterator&) noexcept = default;
57  iterator& operator=(const iterator&) noexcept = default;
58  private:
59  simdjson_inline iterator(const internal::tape_ref &tape) noexcept;
60  internal::tape_ref tape;
61  friend class array;
62  };
63 
69  inline iterator begin() const noexcept;
75  inline iterator end() const noexcept;
81  inline size_t size() const noexcept;
92  inline size_t number_of_slots() const noexcept;
109  inline simdjson_result<element> at_pointer(std::string_view json_pointer) const noexcept;
110 
124  inline simdjson_result<element> at_path(std::string_view json_path) const noexcept;
125 
142  inline simdjson_result<element> at(size_t index) const noexcept;
143 
147  inline operator element() const noexcept;
148 
149 private:
150  simdjson_inline array(const internal::tape_ref &tape) noexcept;
151  internal::tape_ref tape;
152  friend class element;
153  friend struct simdjson_result<element>;
154  template<typename T>
155  friend class simdjson::internal::string_builder;
156 };
157 
158 
159 } // namespace dom
160 
162 template<>
163 struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
164 public:
165  simdjson_inline simdjson_result() noexcept;
166  simdjson_inline simdjson_result(dom::array value) noexcept;
167  simdjson_inline simdjson_result(error_code error) noexcept;
168 
169  inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
170  inline simdjson_result<dom::element> at_path(std::string_view json_path) const noexcept;
171  inline simdjson_result<dom::element> at(size_t index) const noexcept;
172 
173 #if SIMDJSON_EXCEPTIONS
174  inline dom::array::iterator begin() const noexcept(false);
175  inline dom::array::iterator end() const noexcept(false);
176  inline size_t size() const noexcept(false);
177 #endif // SIMDJSON_EXCEPTIONS
178 };
179 
180 
181 
182 } // namespace simdjson
183 
184 #if defined(__cpp_lib_ranges)
185 #include <ranges>
186 
187 namespace std {
188 namespace ranges {
189 template<>
190 inline constexpr bool enable_view<simdjson::dom::array> = true;
191 #if SIMDJSON_EXCEPTIONS
192 template<>
193 inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
194 #endif // SIMDJSON_EXCEPTIONS
195 } // namespace ranges
196 } // namespace std
197 #endif // defined(__cpp_lib_ranges)
198 
199 #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:160
iterator & operator++() noexcept
Get the next value.
Definition: array-inl.h:151
reference operator*() const noexcept
Get the actual value.
Definition: array-inl.h:148
JSON array.
Definition: array.h:13
size_t number_of_slots() const noexcept
Get the total number of slots used by this array on the tape.
Definition: array-inl.h:79
iterator end() const noexcept
One past the last array element.
Definition: array-inl.h:71
size_t size() const noexcept
Get the size of the array (number of immediate children).
Definition: array-inl.h:75
simdjson_result< element > at(size_t index) const noexcept
Get the value at the given index.
Definition: array-inl.h:130
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:83
simdjson_inline array() noexcept
Create a new, invalid array.
Definition: array-inl.h:65
simdjson_result< element > at_path(std::string_view json_path) const noexcept
Get the value associated with the given JSONPath expression.
Definition: array-inl.h:124
iterator begin() const noexcept
Return the first array element.
Definition: array-inl.h:67
A JSON element.
Definition: element.h:31
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
error_code
All possible errors returned by simdjson.
Definition: error.h:19
The result of a JSON navigation that may fail.
Definition: element.h:509
The result of a simdjson operation that could fail.
Definition: error.h:215