simdjson  3.2.3
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 
26  inline value_type operator*() const noexcept;
32  inline iterator& operator++() noexcept;
38  inline iterator operator++(int) noexcept;
44  inline bool operator!=(const iterator& other) const noexcept;
45  inline bool operator==(const iterator& other) const noexcept;
46 
47  inline bool operator<(const iterator& other) const noexcept;
48  inline bool operator<=(const iterator& other) const noexcept;
49  inline bool operator>=(const iterator& other) const noexcept;
50  inline bool operator>(const iterator& other) const noexcept;
51 
52  iterator() noexcept = default;
53  iterator(const iterator&) noexcept = default;
54  iterator& operator=(const iterator&) noexcept = default;
55  private:
56  simdjson_inline iterator(const internal::tape_ref &tape) noexcept;
57  internal::tape_ref tape;
58  friend class array;
59  };
60 
66  inline iterator begin() const noexcept;
72  inline iterator end() const noexcept;
78  inline size_t size() const noexcept;
89  inline size_t number_of_slots() const noexcept;
106  inline simdjson_result<element> at_pointer(std::string_view json_pointer) const noexcept;
107 
124  inline simdjson_result<element> at(size_t index) const noexcept;
125 
126 private:
127  simdjson_inline array(const internal::tape_ref &tape) noexcept;
128  internal::tape_ref tape;
129  friend class element;
130  friend struct simdjson_result<element>;
131  template<typename T>
132  friend class simdjson::internal::string_builder;
133 };
134 
135 
136 } // namespace dom
137 
139 template<>
140 struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
141 public:
142  simdjson_inline simdjson_result() noexcept;
143  simdjson_inline simdjson_result(dom::array value) noexcept;
144  simdjson_inline simdjson_result(error_code error) noexcept;
145 
146  inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
147  inline simdjson_result<dom::element> at(size_t index) const noexcept;
148 
149 #if SIMDJSON_EXCEPTIONS
150  inline dom::array::iterator begin() const noexcept(false);
151  inline dom::array::iterator end() const noexcept(false);
152  inline size_t size() const noexcept(false);
153 #endif // SIMDJSON_EXCEPTIONS
154 };
155 
156 
157 
158 } // namespace simdjson
159 
160 #if defined(__cpp_lib_ranges)
161 #include <ranges>
162 
163 namespace std {
164 namespace ranges {
165 template<>
166 inline constexpr bool enable_view<simdjson::dom::array> = true;
167 #if SIMDJSON_EXCEPTIONS
168 template<>
169 inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
170 #endif // SIMDJSON_EXCEPTIONS
171 } // namespace ranges
172 } // namespace std
173 #endif // defined(__cpp_lib_ranges)
174 
175 #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
value_type 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:473
The result of a simdjson operation that could fail.
Definition: error.h:207