simdjson  3.9.4
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 
127  inline simdjson_result<element> at(size_t index) const noexcept;
128 
132  inline operator element() const noexcept;
133 
134 private:
135  simdjson_inline array(const internal::tape_ref &tape) noexcept;
136  internal::tape_ref tape;
137  friend class element;
138  friend struct simdjson_result<element>;
139  template<typename T>
140  friend class simdjson::internal::string_builder;
141 };
142 
143 
144 } // namespace dom
145 
147 template<>
148 struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
149 public:
150  simdjson_inline simdjson_result() noexcept;
151  simdjson_inline simdjson_result(dom::array value) noexcept;
152  simdjson_inline simdjson_result(error_code error) noexcept;
153 
154  inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
155  inline simdjson_result<dom::element> at(size_t index) const noexcept;
156 
157 #if SIMDJSON_EXCEPTIONS
158  inline dom::array::iterator begin() const noexcept(false);
159  inline dom::array::iterator end() const noexcept(false);
160  inline size_t size() const noexcept(false);
161 #endif // SIMDJSON_EXCEPTIONS
162 };
163 
164 
165 
166 } // namespace simdjson
167 
168 #if defined(__cpp_lib_ranges)
169 #include <ranges>
170 
171 namespace std {
172 namespace ranges {
173 template<>
174 inline constexpr bool enable_view<simdjson::dom::array> = true;
175 #if SIMDJSON_EXCEPTIONS
176 template<>
177 inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
178 #endif // SIMDJSON_EXCEPTIONS
179 } // namespace ranges
180 } // namespace std
181 #endif // defined(__cpp_lib_ranges)
182 
183 #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:146
iterator & operator++() noexcept
Get the next value.
Definition: array-inl.h:137
reference operator*() const noexcept
Get the actual value.
Definition: array-inl.h:134
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:71
iterator end() const noexcept
One past the last array element.
Definition: array-inl.h:63
size_t size() const noexcept
Get the size of the array (number of immediate children).
Definition: array-inl.h:67
simdjson_result< element > at(size_t index) const noexcept
Get the value at the given index.
Definition: array-inl.h:116
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:75
simdjson_inline array() noexcept
Create a new, invalid array.
Definition: array-inl.h:57
iterator begin() const noexcept
Return the first array element.
Definition: array-inl.h:59
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:492
The result of a simdjson operation that could fail.
Definition: error.h:215