simdjson 4.0.7
Ridiculously Fast JSON
Loading...
Searching...
No Matches
object.h
1#ifndef SIMDJSON_DOM_OBJECT_H
2#define SIMDJSON_DOM_OBJECT_H
3
4#include <vector>
5
6#include "simdjson/dom/base.h"
7#include "simdjson/dom/element.h"
8#include "simdjson/internal/tape_ref.h"
9
10namespace simdjson {
11namespace dom {
12
16class object {
17public:
19 simdjson_inline object() noexcept;
20
21 class iterator {
22 public:
23 using value_type = const key_value_pair;
24 using difference_type = std::ptrdiff_t;
25 using pointer = void;
26 using reference = value_type;
27 using iterator_category = std::forward_iterator_tag;
28
32 inline reference operator*() const noexcept;
39 inline iterator& operator++() noexcept;
46 inline iterator operator++(int) noexcept;
52 inline bool operator!=(const iterator& other) const noexcept;
53 inline bool operator==(const iterator& other) const noexcept;
54
55 inline bool operator<(const iterator& other) const noexcept;
56 inline bool operator<=(const iterator& other) const noexcept;
57 inline bool operator>=(const iterator& other) const noexcept;
58 inline bool operator>(const iterator& other) const noexcept;
62 inline std::string_view key() const noexcept;
67 inline uint32_t key_length() const noexcept;
72 inline bool key_equals(std::string_view o) const noexcept;
78 inline bool key_equals_case_insensitive(std::string_view o) const noexcept;
82 inline const char *key_c_str() const noexcept;
86 inline element value() const noexcept;
87
88 iterator() noexcept = default;
89 iterator(const iterator&) noexcept = default;
90 iterator& operator=(const iterator&) noexcept = default;
91 private:
92 simdjson_inline iterator(const internal::tape_ref &tape) noexcept;
93
94 internal::tape_ref tape{};
95
96 friend class object;
97 };
98
104 inline iterator begin() const noexcept;
116 inline size_t size() const noexcept;
132 inline simdjson_result<element> operator[](std::string_view key) const noexcept;
133
151
176
181
186
201
216 inline simdjson_result<element> at_key(std::string_view key) const noexcept;
217
225
238
243
244private:
245 simdjson_inline object(const internal::tape_ref &tape) noexcept;
246
247 internal::tape_ref tape{};
248
249 friend class element;
250 friend struct simdjson_result<element>;
251 template<typename T>
252 friend class simdjson::internal::string_builder;
253};
254
259public:
261 std::string_view key;
264
265private:
266 simdjson_inline key_value_pair(std::string_view _key, element _value) noexcept;
267 friend class object;
268};
269
270} // namespace dom
271
273template<>
274struct simdjson_result<dom::object> : public internal::simdjson_result_base<dom::object> {
275public:
276 simdjson_inline simdjson_result() noexcept;
277 simdjson_inline simdjson_result(dom::object value) noexcept;
278 simdjson_inline simdjson_result(error_code error) noexcept;
279
280 inline simdjson_result<dom::element> operator[](std::string_view key) const noexcept;
281 inline simdjson_result<dom::element> operator[](const char *key) const noexcept;
282 simdjson_result<dom::element> operator[](int) const noexcept = delete;
283 inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
284 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;
285 inline simdjson_result<std::vector<dom::element>> at_path_with_wildcard(std::string_view json_path_new) const noexcept;
286 inline simdjson_result<dom::element> at_path(std::string_view json_path) const noexcept;
287 inline simdjson_result<dom::element> at_key(std::string_view key) const noexcept;
288 inline std::vector<dom::element>& get_values(std::vector<dom::element>& out) const noexcept;
289 inline simdjson_result<dom::element> at_key_case_insensitive(std::string_view key) const noexcept;
290
291#if SIMDJSON_EXCEPTIONS
292 inline dom::object::iterator begin() const noexcept(false);
293 inline dom::object::iterator end() const noexcept(false);
294 inline size_t size() const noexcept(false);
295#endif // SIMDJSON_EXCEPTIONS
296};
297
298} // namespace simdjson
299
300#if SIMDJSON_SUPPORTS_RANGES
301namespace std {
302namespace ranges {
303template<>
304inline constexpr bool enable_view<simdjson::dom::object> = true;
305#if SIMDJSON_EXCEPTIONS
306template<>
307inline constexpr bool enable_view<simdjson::simdjson_result<simdjson::dom::object>> = true;
308#endif // SIMDJSON_EXCEPTIONS
309} // namespace ranges
310} // namespace std
311#endif // SIMDJSON_SUPPORTS_RANGES
312
313#endif // SIMDJSON_DOM_OBJECT_H
JSON array.
Definition array.h:15
A JSON element.
Definition element.h:33
Key/value pair in an object.
Definition object.h:258
std::string_view key
key in the key-value pair
Definition object.h:261
element value
value in the key-value pair
Definition object.h:263
bool operator!=(const iterator &other) const noexcept
Check if these values come from the same place in the JSON.
Definition object-inl.h:291
element value() const noexcept
Get the value of this key/value pair.
Definition object-inl.h:328
bool key_equals(std::string_view o) const noexcept
Returns true if the key in this key/value pair is equal to the provided string_view.
Definition object-inl.h:345
const char * key_c_str() const noexcept
Get the key of this key/value pair.
Definition object-inl.h:325
uint32_t key_length() const noexcept
Get the length (in bytes) of the key in this key/value pair.
Definition object-inl.h:322
reference operator*() const noexcept
Get the actual key/value pair.
Definition object-inl.h:288
bool key_equals_case_insensitive(std::string_view o) const noexcept
Returns true if the key in this key/value pair is equal to the provided string_view in a case-insensi...
Definition object-inl.h:356
std::string_view key() const noexcept
Get the key of this key/value pair.
Definition object-inl.h:319
iterator & operator++() noexcept
Get the next key/value pair.
Definition object-inl.h:309
JSON object.
Definition object.h:16
std::vector< element > & get_values(std::vector< element > &out) const noexcept
Gets the values associated with keys of an object This function has linear-time complexity: the keys ...
Definition object-inl.h:256
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 object-inl.h:155
simdjson_result< element > at_key(std::string_view key) const noexcept
Get the value associated with the given key.
Definition object-inl.h:246
iterator end() const noexcept
One past the last key/value pair.
Definition object-inl.h:89
simdjson_result< std::vector< element > > at_path_with_wildcard(std::string_view json_path) const noexcept
Adds support for JSONPath expression with wildcards '*'.
Definition object-inl.h:175
size_t size() const noexcept
Get the size of the object (number of keys).
Definition object-inl.h:93
simdjson_result< element > at_path(std::string_view json_path) const noexcept
Get the value associated with the given JSONPath expression.
Definition object-inl.h:149
simdjson_result< element > at_key_case_insensitive(std::string_view key) const noexcept
Get the value associated with the given key in a case-insensitive manner.
Definition object-inl.h:270
simdjson_result< element > at_pointer(std::string_view json_pointer) const noexcept
Get the value associated with the given JSON pointer.
Definition object-inl.h:104
simdjson_inline object() noexcept
Create a new, invalid object.
Definition object-inl.h:83
iterator begin() const noexcept
Return the first key/value pair.
Definition object-inl.h:85
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