simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
array.h
1#ifndef SIMDJSON_DOM_ARRAY_H
2#define SIMDJSON_DOM_ARRAY_H
3
4#include <vector>
5
6#include "simdjson/dom/base.h"
7#include "simdjson/internal/tape_ref.h"
8
9namespace simdjson {
10namespace dom {
11
15class array {
16public:
18 simdjson_inline array() noexcept;
19
20 class iterator {
21 public:
22 using value_type = element;
23 using difference_type = std::ptrdiff_t;
24 using pointer = void;
25 using reference = value_type;
26 using iterator_category = std::forward_iterator_tag;
27
31 inline reference operator*() const noexcept;
37 inline iterator& operator++() noexcept;
43 inline iterator operator++(int) noexcept;
49 inline bool operator!=(const iterator& other) const noexcept;
50 inline bool operator==(const iterator& other) const noexcept;
51
52 inline bool operator<(const iterator& other) const noexcept;
53 inline bool operator<=(const iterator& other) const noexcept;
54 inline bool operator>=(const iterator& other) const noexcept;
55 inline bool operator>(const iterator& other) const noexcept;
56
57 iterator() noexcept = default;
58 iterator(const iterator&) noexcept = default;
59 iterator& operator=(const iterator&) noexcept = default;
60 private:
61 simdjson_inline iterator(const internal::tape_ref &tape) noexcept;
62 internal::tape_ref tape{};
63 friend class array;
64 };
65
72 public:
73 using value_type = element;
74 using difference_type = std::ptrdiff_t;
75 using pointer = void;
76 using reference = value_type;
77 using iterator_category = std::forward_iterator_tag;
78
79 inline reference operator*() const noexcept;
80 inline reverse_iterator& operator++() noexcept;
81 inline reverse_iterator operator++(int) noexcept;
82 inline bool operator==(const reverse_iterator& other) const noexcept;
83 inline bool operator!=(const reverse_iterator& other) const noexcept;
84
85 reverse_iterator() noexcept = default;
86 reverse_iterator(const reverse_iterator&) noexcept = default;
87 reverse_iterator& operator=(const reverse_iterator&) noexcept = default;
88 private:
89 simdjson_inline reverse_iterator(const internal::tape_ref &tape, size_t array_start) noexcept;
90 internal::tape_ref tape{};
91 size_t array_start{};
92 friend class array;
93 };
94
104 inline reverse_iterator rbegin() const noexcept;
106 inline reverse_iterator rend() const noexcept;
107
113 inline iterator begin() const noexcept;
119 inline iterator end() const noexcept;
125 inline size_t size() const noexcept;
136 inline size_t number_of_slots() const noexcept;
153 inline simdjson_result<element> at_pointer(std::string_view json_pointer) const noexcept;
154
158 inline void process_json_path_of_child_elements(std::vector<element>::iterator& current, std::vector<element>::iterator& end, const std::string_view& path_suffix, std::vector<element>& accumulator) const noexcept;
159
160
164 inline simdjson_result<std::vector<element>> at_path_with_wildcard(std::string_view json_path) const noexcept;
165
179 inline simdjson_result<element> at_path(std::string_view json_path) const noexcept;
180
197 inline simdjson_result<element> at(size_t index) const noexcept;
198
206 inline std::vector<element>& get_values(std::vector<element>& out) const noexcept;
207
211 inline operator element() const noexcept;
212
213private:
214 simdjson_inline array(const internal::tape_ref &tape) noexcept;
215 internal::tape_ref tape{};
216 friend class element;
217 friend struct simdjson_result<element>;
218 template<typename T>
219 friend class simdjson::internal::string_builder;
220};
221
222
223} // namespace dom
224
226template<>
227struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
228public:
229 simdjson_inline simdjson_result() noexcept;
230 simdjson_inline simdjson_result(dom::array value) noexcept;
231 simdjson_inline simdjson_result(error_code error) noexcept;
232
233 inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
234 inline void process_json_path_of_child_elements(std::vector<dom::element>::iterator& current, std::vector<dom::element>::iterator& end, const std::string_view& path_suffix, std::vector<dom::element>& accumulator) const noexcept;
235 inline simdjson_result<std::vector<dom::element>> at_path_with_wildcard(std::string_view json_path) const noexcept;
236 inline simdjson_result<dom::element> at_path(std::string_view json_path) const noexcept;
237 inline simdjson_result<dom::element> at(size_t index) const noexcept;
238 inline std::vector<dom::element>& get_values(std::vector<dom::element>& out) const noexcept;
239
240#if SIMDJSON_EXCEPTIONS
241 inline dom::array::iterator begin() const noexcept(false);
242 inline dom::array::iterator end() const noexcept(false);
243 inline dom::array::reverse_iterator rbegin() const noexcept(false);
244 inline dom::array::reverse_iterator rend() const noexcept(false);
245 inline size_t size() const noexcept(false);
246#endif // SIMDJSON_EXCEPTIONS
247};
248
249
250
251} // namespace simdjson
252
253#if SIMDJSON_SUPPORTS_RANGES
254namespace std {
255namespace ranges {
256template<>
257inline constexpr bool enable_view<simdjson::dom::array> = true;
258#if SIMDJSON_EXCEPTIONS
259template<>
260inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
261#endif // SIMDJSON_EXCEPTIONS
262} // namespace ranges
263} // namespace std
264#endif // SIMDJSON_SUPPORTS_RANGES
265
266#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:296
iterator & operator++() noexcept
Get the next value.
Definition array-inl.h:287
reference operator*() const noexcept
Get the actual value.
Definition array-inl.h:284
A forward iterator that visits the array's elements in reverse order.
Definition array.h:71
JSON array.
Definition array.h:15
std::vector< element > & get_values(std::vector< element > &out) const noexcept
Gets the values of items in an array element This function has linear-time complexity: the values are...
Definition array-inl.h:243
simdjson_result< std::vector< element > > at_path_with_wildcard(std::string_view json_path) const noexcept
Adds support for JSONPath expression with wildcards '*'.
Definition array-inl.h:167
size_t number_of_slots() const noexcept
Get the total number of slots used by this array on the tape.
Definition array-inl.h:108
iterator end() const noexcept
One past the last array element.
Definition array-inl.h:91
size_t size() const noexcept
Get the size of the array (number of immediate children).
Definition array-inl.h:95
simdjson_result< element > at(size_t index) const noexcept
Get the value at the given index.
Definition array-inl.h:233
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:112
reverse_iterator rbegin() const noexcept
Return the last array element, or rend() for an empty array.
Definition array-inl.h:99
simdjson_inline array() noexcept
Create a new, invalid array.
Definition array-inl.h:85
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:141
reverse_iterator rend() const noexcept
Return the reverse traversal sentinel, before the first element.
Definition array-inl.h:104
iterator begin() const noexcept
Return the first array element.
Definition array-inl.h:87
void process_json_path_of_child_elements(std::vector< element >::iterator &current, std::vector< element >::iterator &end, const std::string_view &path_suffix, std::vector< element > &accumulator) const noexcept
Recursive function which processes the JSON path of each child element.
Definition array-inl.h:147
A JSON element.
Definition element.h:36
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 simdjson operation that could fail.
Definition error.h:281
simdjson_inline error_code error() const noexcept
The error.
Definition error-inl.h:168