simdjson 4.0.7
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
83 inline size_t size() const noexcept;
112
117
118
123
138
156
165
170
171private:
172 simdjson_inline array(const internal::tape_ref &tape) noexcept;
173 internal::tape_ref tape{};
174 friend class element;
175 friend struct simdjson_result<element>;
176 template<typename T>
177 friend class simdjson::internal::string_builder;
178};
179
180
181} // namespace dom
182
184template<>
185struct simdjson_result<dom::array> : public internal::simdjson_result_base<dom::array> {
186public:
187 simdjson_inline simdjson_result() noexcept;
188 simdjson_inline simdjson_result(dom::array value) noexcept;
189 simdjson_inline simdjson_result(error_code error) noexcept;
190
191 inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
192 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;
193 inline simdjson_result<std::vector<dom::element>> at_path_with_wildcard(std::string_view json_path) const noexcept;
194 inline simdjson_result<dom::element> at_path(std::string_view json_path) const noexcept;
195 inline simdjson_result<dom::element> at(size_t index) const noexcept;
196 inline std::vector<dom::element>& get_values(std::vector<dom::element>& out) const noexcept;
197
198#if SIMDJSON_EXCEPTIONS
199 inline dom::array::iterator begin() const noexcept(false);
200 inline dom::array::iterator end() const noexcept(false);
201 inline size_t size() const noexcept(false);
202#endif // SIMDJSON_EXCEPTIONS
203};
204
205
206
207} // namespace simdjson
208
209#if SIMDJSON_SUPPORTS_RANGES
210namespace std {
211namespace ranges {
212template<>
213inline constexpr bool enable_view<simdjson::dom::array> = true;
214#if SIMDJSON_EXCEPTIONS
215template<>
216inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::array>> = true;
217#endif // SIMDJSON_EXCEPTIONS
218} // namespace ranges
219} // namespace std
220#endif // SIMDJSON_SUPPORTS_RANGES
221
222#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:267
iterator & operator++() noexcept
Get the next value.
Definition array-inl.h:258
reference operator*() const noexcept
Get the actual value.
Definition array-inl.h:255
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:238
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:162
size_t number_of_slots() const noexcept
Get the total number of slots used by this array on the tape.
Definition array-inl.h:90
iterator end() const noexcept
One past the last array element.
Definition array-inl.h:82
size_t size() const noexcept
Get the size of the array (number of immediate children).
Definition array-inl.h:86
simdjson_result< element > at(size_t index) const noexcept
Get the value at the given index.
Definition array-inl.h:228
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:94
simdjson_inline array() noexcept
Create a new, invalid array.
Definition array-inl.h:76
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:135
iterator begin() const noexcept
Return the first array element.
Definition array-inl.h:78
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:141
A JSON element.
Definition element.h:33
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:278
simdjson_inline error_code error() const noexcept
The error.
Definition error-inl.h:168