simdjson  3.7.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 
127  inline simdjson_result<element> at(size_t index) const noexcept;
128 
129 private:
130  simdjson_inline array(const internal::tape_ref &tape) noexcept;
131  internal::tape_ref tape;
132  friend class element;
133  friend struct simdjson_result<element>;
134  template<typename T>
135  friend class simdjson::internal::string_builder;
136 };
137 
138 
139 } // namespace dom
140 
142 template<>
143 struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
144 public:
145  simdjson_inline simdjson_result() noexcept;
146  simdjson_inline simdjson_result(dom::array value) noexcept;
147  simdjson_inline simdjson_result(error_code error) noexcept;
148 
149  inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
150  inline simdjson_result<dom::element> at(size_t index) const noexcept;
151 
152 #if SIMDJSON_EXCEPTIONS
153  inline dom::array::iterator begin() const noexcept(false);
154  inline dom::array::iterator end() const noexcept(false);
155  inline size_t size() const noexcept(false);
156 #endif // SIMDJSON_EXCEPTIONS
157 };
158 
159 
160 
161 } // namespace simdjson
162 
163 #if defined(__cpp_lib_ranges)
164 #include <ranges>
165 
166 namespace std {
167 namespace ranges {
168 template<>
169 inline constexpr bool enable_view<simdjson::dom::array> = true;
170 #if SIMDJSON_EXCEPTIONS
171 template<>
172 inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
173 #endif // SIMDJSON_EXCEPTIONS
174 } // namespace ranges
175 } // namespace std
176 #endif // defined(__cpp_lib_ranges)
177 
178 #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:142
iterator & operator++() noexcept
Get the next value.
Definition: array-inl.h:133
reference operator*() const noexcept
Get the actual value.
Definition: array-inl.h:130
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