simdjson 4.2.3
Ridiculously Fast JSON
Loading...
Searching...
No Matches
document-inl.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_INL_H
2
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_INL_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/ondemand/array_iterator.h"
7#include "simdjson/generic/ondemand/document.h"
8#include "simdjson/generic/ondemand/json_type.h"
9#include "simdjson/generic/ondemand/raw_json_string.h"
10#include "simdjson/generic/ondemand/value.h"
11#include "simdjson/generic/ondemand/value-inl.h"
12#include "simdjson/generic/ondemand/array-inl.h"
13#include "simdjson/generic/ondemand/json_iterator-inl.h"
14#include "simdjson/generic/ondemand/object-inl.h"
15#include "simdjson/generic/ondemand/value_iterator-inl.h"
16#include "simdjson/generic/ondemand/deserialize.h"
17#endif // SIMDJSON_CONDITIONAL_INCLUDE
18
19namespace simdjson {
20namespace SIMDJSON_IMPLEMENTATION {
21namespace ondemand {
22
23simdjson_inline document::document(ondemand::json_iterator &&_iter) noexcept
24 : iter{std::forward<json_iterator>(_iter)}
25{
26 logger::log_start_value(iter, "document");
27}
28
29simdjson_inline document document::start(json_iterator &&iter) noexcept {
30 return document(std::forward<json_iterator>(iter));
31}
32
33inline void document::rewind() noexcept {
34 iter.rewind();
35}
36
37inline std::string document::to_debug_string() noexcept {
38 return iter.to_string();
39}
40
42 return iter.current_location();
43}
44
45inline int32_t document::current_depth() const noexcept {
46 return iter.depth();
47}
48
49inline bool document::at_end() const noexcept {
50 return iter.at_end();
51}
52
53
54inline bool document::is_alive() noexcept {
55 return iter.is_alive();
56}
57simdjson_inline value_iterator document::resume_value_iterator() noexcept {
58 return value_iterator(&iter, 1, iter.root_position());
59}
60simdjson_inline value_iterator document::get_root_value_iterator() noexcept {
61 return resume_value_iterator();
62}
63simdjson_inline simdjson_result<object> document::start_or_resume_object() noexcept {
64 if (iter.at_root()) {
65 return get_object();
66 } else {
67 return object::resume(resume_value_iterator());
68 }
69}
70simdjson_inline simdjson_result<value> document::get_value() noexcept {
71 // Make sure we start any arrays or objects before returning, so that start_root_<object/array>()
72 // gets called.
73
74 // It is the convention throughout the code that the macro `SIMDJSON_DEVELOPMENT_CHECKS` determines whether
75 // we check for OUT_OF_ORDER_ITERATION. Proper on::demand code should never trigger this error.
76#if SIMDJSON_DEVELOPMENT_CHECKS
77 if (!iter.at_root()) { return OUT_OF_ORDER_ITERATION; }
78#endif
79 // assert_at_root() serves two purposes: in Debug mode, whether or not
80 // SIMDJSON_DEVELOPMENT_CHECKS is set or not, it checks that we are at the root of
81 // the document (this will typically be redundant). In release mode, it generates
82 // SIMDJSON_ASSUME statements to allow the compiler to make assumptions.
83 iter.assert_at_root();
84 switch (*iter.peek()) {
85 case '[': {
86 // The following lines check that the document ends with ].
87 auto value_iterator = get_root_value_iterator();
88 auto error = value_iterator.check_root_array();
89 if(error) { return error; }
90 return value(get_root_value_iterator());
91 }
92 case '{': {
93 // The following lines would check that the document ends with }.
94 auto value_iterator = get_root_value_iterator();
95 auto error = value_iterator.check_root_object();
96 if(error) { return error; }
97 return value(get_root_value_iterator());
98 }
99 default:
100 // Unfortunately, scalar documents are a special case in simdjson and they cannot
101 // be safely converted to value instances.
103 }
104}
105simdjson_inline simdjson_result<array> document::get_array() & noexcept {
106 auto value = get_root_value_iterator();
107 return array::start_root(value);
108}
109simdjson_inline simdjson_result<object> document::get_object() & noexcept {
110 auto value = get_root_value_iterator();
111 return object::start_root(value);
112}
113
123 return get_root_value_iterator().get_root_uint64(true);
124}
126 return get_root_value_iterator().get_root_uint64_in_string(true);
127}
129 return get_root_value_iterator().get_root_int64(true);
130}
132 return get_root_value_iterator().get_root_int64_in_string(true);
133}
135 return get_root_value_iterator().get_root_double(true);
136}
138 return get_root_value_iterator().get_root_double_in_string(true);
139}
140simdjson_inline simdjson_result<std::string_view> document::get_string(bool allow_replacement) noexcept {
141 return get_root_value_iterator().get_root_string(true, allow_replacement);
142}
143template <typename string_type>
144simdjson_warn_unused simdjson_inline error_code document::get_string(string_type& receiver, bool allow_replacement) noexcept {
145 return get_root_value_iterator().get_root_string(receiver, true, allow_replacement);
146}
148 return get_root_value_iterator().get_root_wobbly_string(true);
149}
151 return get_root_value_iterator().get_root_raw_json_string(true);
152}
153simdjson_inline simdjson_result<bool> document::get_bool() noexcept {
154 return get_root_value_iterator().get_root_bool(true);
155}
156simdjson_inline simdjson_result<bool> document::is_null() noexcept {
157 return get_root_value_iterator().is_root_null(true);
158}
159
160template<> simdjson_inline simdjson_result<array> document::get() & noexcept { return get_array(); }
161template<> simdjson_inline simdjson_result<object> document::get() & noexcept { return get_object(); }
162template<> simdjson_inline simdjson_result<raw_json_string> document::get() & noexcept { return get_raw_json_string(); }
163template<> simdjson_inline simdjson_result<std::string_view> document::get() & noexcept { return get_string(false); }
164template<> simdjson_inline simdjson_result<double> document::get() & noexcept { return get_double(); }
165template<> simdjson_inline simdjson_result<uint64_t> document::get() & noexcept { return get_uint64(); }
166template<> simdjson_inline simdjson_result<int64_t> document::get() & noexcept { return get_int64(); }
167template<> simdjson_inline simdjson_result<bool> document::get() & noexcept { return get_bool(); }
168template<> simdjson_inline simdjson_result<value> document::get() & noexcept { return get_value(); }
169
170template<> simdjson_warn_unused simdjson_inline error_code document::get(array& out) & noexcept { return get_array().get(out); }
171template<> simdjson_warn_unused simdjson_inline error_code document::get(object& out) & noexcept { return get_object().get(out); }
172template<> simdjson_warn_unused simdjson_inline error_code document::get(raw_json_string& out) & noexcept { return get_raw_json_string().get(out); }
173template<> simdjson_warn_unused simdjson_inline error_code document::get(std::string_view& out) & noexcept { return get_string(false).get(out); }
174template<> simdjson_warn_unused simdjson_inline error_code document::get(double& out) & noexcept { return get_double().get(out); }
175template<> simdjson_warn_unused simdjson_inline error_code document::get(uint64_t& out) & noexcept { return get_uint64().get(out); }
176template<> simdjson_warn_unused simdjson_inline error_code document::get(int64_t& out) & noexcept { return get_int64().get(out); }
177template<> simdjson_warn_unused simdjson_inline error_code document::get(bool& out) & noexcept { return get_bool().get(out); }
178template<> simdjson_warn_unused simdjson_inline error_code document::get(value& out) & noexcept { return get_value().get(out); }
179
180template<> simdjson_deprecated simdjson_inline simdjson_result<raw_json_string> document::get() && noexcept { return get_raw_json_string(); }
181template<> simdjson_deprecated simdjson_inline simdjson_result<std::string_view> document::get() && noexcept { return get_string(false); }
182template<> simdjson_deprecated simdjson_inline simdjson_result<double> document::get() && noexcept { return std::forward<document>(*this).get_double(); }
183template<> simdjson_deprecated simdjson_inline simdjson_result<uint64_t> document::get() && noexcept { return std::forward<document>(*this).get_uint64(); }
184template<> simdjson_deprecated simdjson_inline simdjson_result<int64_t> document::get() && noexcept { return std::forward<document>(*this).get_int64(); }
185template<> simdjson_deprecated simdjson_inline simdjson_result<bool> document::get() && noexcept { return std::forward<document>(*this).get_bool(); }
186template<> simdjson_deprecated simdjson_inline simdjson_result<value> document::get() && noexcept { return get_value(); }
187
188#if SIMDJSON_EXCEPTIONS
189template <class T>
190simdjson_deprecated simdjson_inline document::operator T() && noexcept(false) { return get<T>(); }
191template <class T>
192simdjson_inline document::operator T() & noexcept(false) { return get<T>(); }
193simdjson_inline document::operator array() & noexcept(false) { return get_array(); }
194simdjson_inline document::operator object() & noexcept(false) { return get_object(); }
195simdjson_inline document::operator uint64_t() noexcept(false) { return get_uint64(); }
196simdjson_inline document::operator int64_t() noexcept(false) { return get_int64(); }
197simdjson_inline document::operator double() noexcept(false) { return get_double(); }
198simdjson_inline document::operator std::string_view() noexcept(false) simdjson_lifetime_bound { return get_string(false); }
199simdjson_inline document::operator raw_json_string() noexcept(false) simdjson_lifetime_bound { return get_raw_json_string(); }
200simdjson_inline document::operator bool() noexcept(false) { return get_bool(); }
201simdjson_inline document::operator value() noexcept(false) { return get_value(); }
202
203#endif
205 auto a = get_array();
206 simdjson_result<size_t> answer = a.count_elements();
207 /* If there was an array, we are now left pointing at its first element. */
208 if(answer.error() == SUCCESS) { rewind(); }
209 return answer;
210}
212 auto a = get_object();
213 simdjson_result<size_t> answer = a.count_fields();
214 /* If there was an object, we are now left pointing at its first element. */
215 if(answer.error() == SUCCESS) { rewind(); }
216 return answer;
217}
218simdjson_inline simdjson_result<value> document::at(size_t index) & noexcept {
219 auto a = get_array();
220 return a.at(index);
221}
223 return get_array().begin();
224}
225simdjson_inline simdjson_result<array_iterator> document::end() & noexcept {
226 return {};
227}
228
229simdjson_inline simdjson_result<value> document::find_field(std::string_view key) & noexcept {
230 return start_or_resume_object().find_field(key);
231}
232simdjson_inline simdjson_result<value> document::find_field(const char *key) & noexcept {
233 return start_or_resume_object().find_field(key);
234}
235simdjson_inline simdjson_result<value> document::find_field_unordered(std::string_view key) & noexcept {
236 return start_or_resume_object().find_field_unordered(key);
237}
238simdjson_inline simdjson_result<value> document::find_field_unordered(const char *key) & noexcept {
239 return start_or_resume_object().find_field_unordered(key);
240}
241simdjson_inline simdjson_result<value> document::operator[](std::string_view key) & noexcept {
242 return start_or_resume_object()[key];
243}
244simdjson_inline simdjson_result<value> document::operator[](const char *key) & noexcept {
245 return start_or_resume_object()[key];
246}
247
248simdjson_warn_unused simdjson_inline error_code document::consume() noexcept {
249 bool scalar = false;
250 auto error = is_scalar().get(scalar);
251 if(error) { return error; }
252 if(scalar) {
253 iter.return_current_and_advance();
254 return SUCCESS;
255 }
256 error = iter.skip_child(0);
257 if(error) { iter.abandon(); }
258 return error;
259}
260
262 auto _iter = get_root_value_iterator();
263 const uint8_t * starting_point{_iter.peek_start()};
264 auto error = consume();
265 if(error) { return error; }
266 // After 'consume()', we could be left pointing just beyond the document, but that
267 // is ok because we are not going to dereference the final pointer position, we just
268 // use it to compute the length in bytes.
269 const uint8_t * final_point{iter.unsafe_pointer()};
270 return std::string_view(reinterpret_cast<const char*>(starting_point), size_t(final_point - starting_point));
271}
272
273simdjson_inline simdjson_result<json_type> document::type() noexcept {
274 return get_root_value_iterator().type();
275}
276
277simdjson_inline simdjson_result<bool> document::is_scalar() noexcept {
278 // For more speed, we could do:
279 // return iter.is_single_token();
280 json_type this_type;
281 auto error = type().get(this_type);
282 if(error) { return error; }
283 return ! ((this_type == json_type::array) || (this_type == json_type::object));
284}
285
286simdjson_inline simdjson_result<bool> document::is_string() noexcept {
287 json_type this_type;
288 auto error = type().get(this_type);
289 if(error) { return error; }
290 return (this_type == json_type::string);
291}
292
293simdjson_inline bool document::is_negative() noexcept {
294 return get_root_value_iterator().is_root_negative();
295}
296
297simdjson_inline simdjson_result<bool> document::is_integer() noexcept {
298 return get_root_value_iterator().is_root_integer(true);
299}
300
302 return get_root_value_iterator().get_root_number_type(true);
303}
304
306 return get_root_value_iterator().get_root_number(true);
307}
308
309
311 auto _iter = get_root_value_iterator();
312 return std::string_view(reinterpret_cast<const char*>(_iter.peek_start()), _iter.peek_root_length());
313}
314
315simdjson_inline simdjson_result<value> document::at_pointer(std::string_view json_pointer) noexcept {
316 rewind(); // Rewind the document each time at_pointer is called
317 if (json_pointer.empty()) {
318 return this->get_value();
319 }
320 json_type t;
321 SIMDJSON_TRY(type().get(t));
322 switch (t)
323 {
324 case json_type::array:
325 return (*this).get_array().at_pointer(json_pointer);
327 return (*this).get_object().at_pointer(json_pointer);
328 default:
330 }
331}
332
333simdjson_inline simdjson_result<value> document::at_path(std::string_view json_path) noexcept {
334 rewind(); // Rewind the document each time at_pointer is called
335 if (json_path.empty()) {
336 return this->get_value();
337 }
338 json_type t;
339 SIMDJSON_TRY(type().get(t));
340 switch (t) {
341 case json_type::array:
342 return (*this).get_array().at_path(json_path);
344 return (*this).get_object().at_path(json_path);
345 default:
347 }
348}
349
350simdjson_inline simdjson_result<std::vector<value>> document::at_path_with_wildcard(std::string_view json_path) noexcept {
351 rewind(); // Rewind the document each time at_path_with_wildcard is called
352 if (json_path.empty()) {
354 }
355 json_type t;
356 SIMDJSON_TRY(type().get(t));
357 switch (t) {
358 case json_type::array:
359 return (*this).get_array().at_path_with_wildcard(json_path);
361 return (*this).get_object().at_path_with_wildcard(json_path);
362 default:
364 }
365}
366
367#if SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
368
369template<constevalutil::fixed_string... FieldNames, typename T>
370 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
371simdjson_warn_unused simdjson_inline error_code document::extract_into(T& out) & noexcept {
372 // Helper to check if a field name matches any of the requested fields
373 auto should_extract = [](std::string_view field_name) constexpr -> bool {
374 return ((FieldNames.view() == field_name) || ...);
375 };
376
377 // Iterate through all members of T using reflection
378 template for (constexpr auto mem : std::define_static_array(
379 std::meta::nonstatic_data_members_of(^^T, std::meta::access_context::unchecked()))) {
380
381 if constexpr (!std::meta::is_const(mem) && std::meta::is_public(mem)) {
382 constexpr std::string_view key = std::define_static_string(std::meta::identifier_of(mem));
383
384 // Only extract this field if it's in our list of requested fields
385 if constexpr (should_extract(key)) {
386 // Try to find and extract the field
387 if constexpr (concepts::optional_type<decltype(out.[:mem:])>) {
388 // For optional fields, it's ok if they're missing
389 auto field_result = find_field_unordered(key);
390 if (!field_result.error()) {
391 auto error = field_result.get(out.[:mem:]);
392 if (error && error != NO_SUCH_FIELD) {
393 return error;
394 }
395 } else if (field_result.error() != NO_SUCH_FIELD) {
396 return field_result.error();
397 } else {
398 out.[:mem:].reset();
399 }
400 } else {
401 // For required fields (in the requested list), fail if missing
402 SIMDJSON_TRY((*this)[key].get(out.[:mem:]));
403 }
404 }
405 }
406 };
407
408 return SUCCESS;
409}
410
411#endif // SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
412
413} // namespace ondemand
414} // namespace SIMDJSON_IMPLEMENTATION
415} // namespace simdjson
416
417namespace simdjson {
418
419simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
420 SIMDJSON_IMPLEMENTATION::ondemand::document &&value
421) noexcept :
422 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
423 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(value)
424 )
425{
426}
427simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
428 error_code error
429) noexcept :
430 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
431 error
432 )
433{
434}
435simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::count_elements() & noexcept {
436 if (error()) { return error(); }
437 return first.count_elements();
438}
439simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::count_fields() & noexcept {
440 if (error()) { return error(); }
441 return first.count_fields();
442}
443simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at(size_t index) & noexcept {
444 if (error()) { return error(); }
445 return first.at(index);
446}
447simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::rewind() noexcept {
448 if (error()) { return error(); }
449 first.rewind();
450 return SUCCESS;
451}
452simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::begin() & noexcept {
453 if (error()) { return error(); }
454 return first.begin();
455}
456simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::end() & noexcept {
457 return {};
458}
459simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field_unordered(std::string_view key) & noexcept {
460 if (error()) { return error(); }
461 return first.find_field_unordered(key);
462}
463simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field_unordered(const char *key) & noexcept {
464 if (error()) { return error(); }
465 return first.find_field_unordered(key);
466}
467simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator[](std::string_view key) & noexcept {
468 if (error()) { return error(); }
469 return first[key];
470}
471simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator[](const char *key) & noexcept {
472 if (error()) { return error(); }
473 return first[key];
474}
475simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field(std::string_view key) & noexcept {
476 if (error()) { return error(); }
477 return first.find_field(key);
478}
479simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field(const char *key) & noexcept {
480 if (error()) { return error(); }
481 return first.find_field(key);
482}
483simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_array() & noexcept {
484 if (error()) { return error(); }
485 return first.get_array();
486}
487simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_object() & noexcept {
488 if (error()) { return error(); }
489 return first.get_object();
490}
491simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64() noexcept {
492 if (error()) { return error(); }
493 return first.get_uint64();
494}
495simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64_in_string() noexcept {
496 if (error()) { return error(); }
497 return first.get_uint64_in_string();
498}
499simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64() noexcept {
500 if (error()) { return error(); }
501 return first.get_int64();
502}
503simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64_in_string() noexcept {
504 if (error()) { return error(); }
505 return first.get_int64_in_string();
506}
507simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double() noexcept {
508 if (error()) { return error(); }
509 return first.get_double();
510}
511simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double_in_string() noexcept {
512 if (error()) { return error(); }
513 return first.get_double_in_string();
514}
515simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_string(bool allow_replacement) noexcept {
516 if (error()) { return error(); }
517 return first.get_string(allow_replacement);
518}
519template <typename string_type>
520simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_string(string_type& receiver, bool allow_replacement) noexcept {
521 if (error()) { return error(); }
522 return first.get_string(receiver, allow_replacement);
523}
524simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_wobbly_string() noexcept {
525 if (error()) { return error(); }
526 return first.get_wobbly_string();
527}
528simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_raw_json_string() noexcept {
529 if (error()) { return error(); }
530 return first.get_raw_json_string();
531}
532simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_bool() noexcept {
533 if (error()) { return error(); }
534 return first.get_bool();
535}
536simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_value() noexcept {
537 if (error()) { return error(); }
538 return first.get_value();
539}
540simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_null() noexcept {
541 if (error()) { return error(); }
542 return first.is_null();
543}
544
545template<typename T>
546simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get() & noexcept {
547 if (error()) { return error(); }
548 return first.get<T>();
549}
550template<typename T>
551simdjson_deprecated simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get() && noexcept {
552 if (error()) { return error(); }
553 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>();
554}
555template<typename T>
556simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get(T &out) & noexcept {
557 if (error()) { return error(); }
558 return first.get<T>(out);
559}
560template<typename T>
561simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get(T &out) && noexcept {
562 if (error()) { return error(); }
563 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>(out);
564}
565
566template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() & noexcept = delete;
567template<> simdjson_deprecated simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() && noexcept {
568 if (error()) { return error(); }
569 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
570}
571template<> simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) & noexcept = delete;
572template<> simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) && noexcept {
573 if (error()) { return error(); }
574 out = std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
575 return SUCCESS;
576}
577
578simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::type() noexcept {
579 if (error()) { return error(); }
580 return first.type();
581}
582
583simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_scalar() noexcept {
584 if (error()) { return error(); }
585 return first.is_scalar();
586}
587
588simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_string() noexcept {
589 if (error()) { return error(); }
590 return first.is_string();
591}
592
593simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_negative() noexcept {
594 if (error()) { return error(); }
595 return first.is_negative();
596}
597
598simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_integer() noexcept {
599 if (error()) { return error(); }
600 return first.is_integer();
601}
602
603simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number_type() noexcept {
604 if (error()) { return error(); }
605 return first.get_number_type();
606}
607
608simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number() noexcept {
609 if (error()) { return error(); }
610 return first.get_number();
611}
612
613
614#if SIMDJSON_EXCEPTIONS
615template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false>::type>
616simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator T() noexcept(false) {
617 if (error()) { throw simdjson_error(error()); }
618 return first;
619}
620simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) {
621 if (error()) { throw simdjson_error(error()); }
622 return first;
623}
624simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) {
625 if (error()) { throw simdjson_error(error()); }
626 return first;
627}
628simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator uint64_t() noexcept(false) {
629 if (error()) { throw simdjson_error(error()); }
630 return first;
631}
632simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator int64_t() noexcept(false) {
633 if (error()) { throw simdjson_error(error()); }
634 return first;
635}
636simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator double() noexcept(false) {
637 if (error()) { throw simdjson_error(error()); }
638 return first;
639}
640simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator std::string_view() noexcept(false) {
641 if (error()) { throw simdjson_error(error()); }
642 return first;
643}
644simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
645 if (error()) { throw simdjson_error(error()); }
646 return first;
647}
648simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator bool() noexcept(false) {
649 if (error()) { throw simdjson_error(error()); }
650 return first;
651}
652simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
653 if (error()) { throw simdjson_error(error()); }
654 return first;
655}
656#endif
657
658
659simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_location() noexcept {
660 if (error()) { return error(); }
661 return first.current_location();
662}
663
664simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_end() const noexcept {
665 if (error()) { return error(); }
666 return first.at_end();
667}
668
669
670simdjson_inline int32_t simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_depth() const noexcept {
671 if (error()) { return error(); }
672 return first.current_depth();
673}
674
675simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::raw_json_token() noexcept {
676 if (error()) { return error(); }
677 return first.raw_json_token();
678}
679
680simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_pointer(std::string_view json_pointer) noexcept {
681 if (error()) { return error(); }
682 return first.at_pointer(json_pointer);
683}
684
685simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_path(std::string_view json_path) noexcept {
686 if (error()) { return error(); }
687 return first.at_path(json_path);
688}
689
690simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_path_with_wildcard(std::string_view json_path) noexcept {
691 if (error()) { return error(); }
692 return first.at_path_with_wildcard(json_path);
693}
694
695#if SIMDJSON_STATIC_REFLECTION
696template<constevalutil::fixed_string... FieldNames, typename T>
697 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
698simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::extract_into(T& out) & noexcept {
699 if (error()) { return error(); }
700 return first.extract_into<FieldNames...>(out);
701}
702#endif // SIMDJSON_STATIC_REFLECTION
703
704} // namespace simdjson
705
706
707namespace simdjson {
708namespace SIMDJSON_IMPLEMENTATION {
709namespace ondemand {
710
711simdjson_inline document_reference::document_reference() noexcept : doc{nullptr} {}
712simdjson_inline document_reference::document_reference(document &d) noexcept : doc(&d) {}
713simdjson_inline void document_reference::rewind() noexcept { doc->rewind(); }
714simdjson_inline simdjson_result<array> document_reference::get_array() & noexcept { return doc->get_array(); }
715simdjson_inline simdjson_result<object> document_reference::get_object() & noexcept { return doc->get_object(); }
730simdjson_inline simdjson_result<uint64_t> document_reference::get_uint64() noexcept { return doc->get_root_value_iterator().get_root_uint64(false); }
731simdjson_inline simdjson_result<uint64_t> document_reference::get_uint64_in_string() noexcept { return doc->get_root_value_iterator().get_root_uint64_in_string(false); }
732simdjson_inline simdjson_result<int64_t> document_reference::get_int64() noexcept { return doc->get_root_value_iterator().get_root_int64(false); }
733simdjson_inline simdjson_result<int64_t> document_reference::get_int64_in_string() noexcept { return doc->get_root_value_iterator().get_root_int64_in_string(false); }
734simdjson_inline simdjson_result<double> document_reference::get_double() noexcept { return doc->get_root_value_iterator().get_root_double(false); }
735simdjson_inline simdjson_result<double> document_reference::get_double_in_string() noexcept { return doc->get_root_value_iterator().get_root_double(false); }
736simdjson_inline simdjson_result<std::string_view> document_reference::get_string(bool allow_replacement) noexcept { return doc->get_root_value_iterator().get_root_string(false, allow_replacement); }
737template <typename string_type>
738simdjson_warn_unused simdjson_inline error_code document_reference::get_string(string_type& receiver, bool allow_replacement) noexcept { return doc->get_root_value_iterator().get_root_string(receiver, false, allow_replacement); }
739simdjson_inline simdjson_result<std::string_view> document_reference::get_wobbly_string() noexcept { return doc->get_root_value_iterator().get_root_wobbly_string(false); }
740simdjson_inline simdjson_result<raw_json_string> document_reference::get_raw_json_string() noexcept { return doc->get_root_value_iterator().get_root_raw_json_string(false); }
741simdjson_inline simdjson_result<bool> document_reference::get_bool() noexcept { return doc->get_root_value_iterator().get_root_bool(false); }
742simdjson_inline simdjson_result<value> document_reference::get_value() noexcept { return doc->get_value(); }
743simdjson_inline simdjson_result<bool> document_reference::is_null() noexcept { return doc->get_root_value_iterator().is_root_null(false); }
744template<> simdjson_inline simdjson_result<array> document_reference::get() & noexcept { return get_array(); }
745template<> simdjson_inline simdjson_result<object> document_reference::get() & noexcept { return get_object(); }
746template<> simdjson_inline simdjson_result<raw_json_string> document_reference::get() & noexcept { return get_raw_json_string(); }
747template<> simdjson_inline simdjson_result<std::string_view> document_reference::get() & noexcept { return get_string(false); }
748template<> simdjson_inline simdjson_result<double> document_reference::get() & noexcept { return get_double(); }
749template<> simdjson_inline simdjson_result<uint64_t> document_reference::get() & noexcept { return get_uint64(); }
750template<> simdjson_inline simdjson_result<int64_t> document_reference::get() & noexcept { return get_int64(); }
751template<> simdjson_inline simdjson_result<bool> document_reference::get() & noexcept { return get_bool(); }
752template<> simdjson_inline simdjson_result<value> document_reference::get() & noexcept { return get_value(); }
753#if SIMDJSON_EXCEPTIONS
754template <class T>
755simdjson_inline document_reference::operator T() noexcept(false) { return get<T>(); }
756simdjson_inline document_reference::operator array() & noexcept(false) { return array(*doc); }
757simdjson_inline document_reference::operator object() & noexcept(false) { return object(*doc); }
758simdjson_inline document_reference::operator uint64_t() noexcept(false) { return get_uint64(); }
759simdjson_inline document_reference::operator int64_t() noexcept(false) { return get_int64(); }
760simdjson_inline document_reference::operator double() noexcept(false) { return get_double(); }
761simdjson_inline document_reference::operator std::string_view() noexcept(false) { return std::string_view(*doc); }
762simdjson_inline document_reference::operator raw_json_string() noexcept(false) { return get_raw_json_string(); }
763simdjson_inline document_reference::operator bool() noexcept(false) { return get_bool(); }
764simdjson_inline document_reference::operator value() noexcept(false) { return value(*doc); }
765#endif
766simdjson_inline simdjson_result<size_t> document_reference::count_elements() & noexcept { return doc->count_elements(); }
767simdjson_inline simdjson_result<size_t> document_reference::count_fields() & noexcept { return doc->count_fields(); }
768simdjson_inline simdjson_result<value> document_reference::at(size_t index) & noexcept { return doc->at(index); }
769simdjson_inline simdjson_result<array_iterator> document_reference::begin() & noexcept { return doc->begin(); }
770simdjson_inline simdjson_result<array_iterator> document_reference::end() & noexcept { return doc->end(); }
771simdjson_inline simdjson_result<value> document_reference::find_field(std::string_view key) & noexcept { return doc->find_field(key); }
772simdjson_inline simdjson_result<value> document_reference::find_field(const char *key) & noexcept { return doc->find_field(key); }
773simdjson_inline simdjson_result<value> document_reference::operator[](std::string_view key) & noexcept { return (*doc)[key]; }
774simdjson_inline simdjson_result<value> document_reference::operator[](const char *key) & noexcept { return (*doc)[key]; }
775simdjson_inline simdjson_result<value> document_reference::find_field_unordered(std::string_view key) & noexcept { return doc->find_field_unordered(key); }
776simdjson_inline simdjson_result<value> document_reference::find_field_unordered(const char *key) & noexcept { return doc->find_field_unordered(key); }
777simdjson_inline simdjson_result<json_type> document_reference::type() noexcept { return doc->type(); }
778simdjson_inline simdjson_result<bool> document_reference::is_scalar() noexcept { return doc->is_scalar(); }
779simdjson_inline simdjson_result<bool> document_reference::is_string() noexcept { return doc->is_string(); }
780simdjson_inline simdjson_result<const char *> document_reference::current_location() noexcept { return doc->current_location(); }
781simdjson_inline int32_t document_reference::current_depth() const noexcept { return doc->current_depth(); }
782simdjson_inline bool document_reference::is_negative() noexcept { return doc->is_negative(); }
783simdjson_inline simdjson_result<bool> document_reference::is_integer() noexcept { return doc->get_root_value_iterator().is_root_integer(false); }
784simdjson_inline simdjson_result<number_type> document_reference::get_number_type() noexcept { return doc->get_root_value_iterator().get_root_number_type(false); }
785simdjson_inline simdjson_result<number> document_reference::get_number() noexcept { return doc->get_root_value_iterator().get_root_number(false); }
786simdjson_inline simdjson_result<std::string_view> document_reference::raw_json_token() noexcept { return doc->raw_json_token(); }
787simdjson_inline simdjson_result<value> document_reference::at_pointer(std::string_view json_pointer) noexcept { return doc->at_pointer(json_pointer); }
788simdjson_inline simdjson_result<value> document_reference::at_path(std::string_view json_path) noexcept { return doc->at_path(json_path); }
789simdjson_inline simdjson_result<std::vector<value>> document_reference::at_path_with_wildcard(std::string_view json_path) noexcept { return doc->at_path_with_wildcard(json_path); }
790simdjson_inline simdjson_result<std::string_view> document_reference::raw_json() noexcept { return doc->raw_json();}
791simdjson_inline document_reference::operator document&() const noexcept { return *doc; }
792#if SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
793template<constevalutil::fixed_string... FieldNames, typename T>
794 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
795simdjson_warn_unused simdjson_inline error_code document_reference::extract_into(T& out) & noexcept {
796 return doc->extract_into<FieldNames...>(out);
797}
798#endif // SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
799} // namespace ondemand
800} // namespace SIMDJSON_IMPLEMENTATION
801} // namespace simdjson
802
803
804
805namespace simdjson {
806simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document_reference value, error_code error)
807 noexcept : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(value), error) {}
808
809
810simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::count_elements() & noexcept {
811 if (error()) { return error(); }
812 return first.count_elements();
813}
814simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::count_fields() & noexcept {
815 if (error()) { return error(); }
816 return first.count_fields();
817}
818simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at(size_t index) & noexcept {
819 if (error()) { return error(); }
820 return first.at(index);
821}
822simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::rewind() noexcept {
823 if (error()) { return error(); }
824 first.rewind();
825 return SUCCESS;
826}
827simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::begin() & noexcept {
828 if (error()) { return error(); }
829 return first.begin();
830}
831simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::end() & noexcept {
832 return {};
833}
834simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field_unordered(std::string_view key) & noexcept {
835 if (error()) { return error(); }
836 return first.find_field_unordered(key);
837}
838simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field_unordered(const char *key) & noexcept {
839 if (error()) { return error(); }
840 return first.find_field_unordered(key);
841}
842simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator[](std::string_view key) & noexcept {
843 if (error()) { return error(); }
844 return first[key];
845}
846simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator[](const char *key) & noexcept {
847 if (error()) { return error(); }
848 return first[key];
849}
850simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field(std::string_view key) & noexcept {
851 if (error()) { return error(); }
852 return first.find_field(key);
853}
854simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field(const char *key) & noexcept {
855 if (error()) { return error(); }
856 return first.find_field(key);
857}
858simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_array() & noexcept {
859 if (error()) { return error(); }
860 return first.get_array();
861}
862simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_object() & noexcept {
863 if (error()) { return error(); }
864 return first.get_object();
865}
866simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64() noexcept {
867 if (error()) { return error(); }
868 return first.get_uint64();
869}
870simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64_in_string() noexcept {
871 if (error()) { return error(); }
872 return first.get_uint64_in_string();
873}
874simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64() noexcept {
875 if (error()) { return error(); }
876 return first.get_int64();
877}
878simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64_in_string() noexcept {
879 if (error()) { return error(); }
880 return first.get_int64_in_string();
881}
882simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double() noexcept {
883 if (error()) { return error(); }
884 return first.get_double();
885}
886simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double_in_string() noexcept {
887 if (error()) { return error(); }
888 return first.get_double_in_string();
889}
890simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_string(bool allow_replacement) noexcept {
891 if (error()) { return error(); }
892 return first.get_string(allow_replacement);
893}
894template <typename string_type>
895simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_string(string_type& receiver, bool allow_replacement) noexcept {
896 if (error()) { return error(); }
897 return first.get_string(receiver, allow_replacement);
898}
899simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_wobbly_string() noexcept {
900 if (error()) { return error(); }
901 return first.get_wobbly_string();
902}
903simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_raw_json_string() noexcept {
904 if (error()) { return error(); }
905 return first.get_raw_json_string();
906}
907simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_bool() noexcept {
908 if (error()) { return error(); }
909 return first.get_bool();
910}
911simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_value() noexcept {
912 if (error()) { return error(); }
913 return first.get_value();
914}
915simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_null() noexcept {
916 if (error()) { return error(); }
917 return first.is_null();
918}
919template<typename T>
920simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get() & noexcept {
921 if (error()) { return error(); }
922 return first.get<T>();
923}
924template<typename T>
925simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get() && noexcept {
926 if (error()) { return error(); }
927 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(first).get<T>();
928}
929template <class T>
930simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get(T &out) & noexcept {
931 if (error()) { return error(); }
932 return first.get<T>(out);
933}
934template <class T>
935simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get(T &out) && noexcept {
936 if (error()) { return error(); }
937 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(first).get<T>(out);
938}
939simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::type() noexcept {
940 if (error()) { return error(); }
941 return first.type();
942}
943simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_scalar() noexcept {
944 if (error()) { return error(); }
945 return first.is_scalar();
946}
947simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_string() noexcept {
948 if (error()) { return error(); }
949 return first.is_string();
950}
951template <>
952simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get(SIMDJSON_IMPLEMENTATION::ondemand::document_reference &out) & noexcept {
953 if (error()) { return error(); }
954 out = first;
955 return SUCCESS;
956}
957template <>
958simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get(SIMDJSON_IMPLEMENTATION::ondemand::document_reference &out) && noexcept {
959 if (error()) { return error(); }
960 out = first;
961 return SUCCESS;
962}
963simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_negative() noexcept {
964 if (error()) { return error(); }
965 return first.is_negative();
966}
967simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_integer() noexcept {
968 if (error()) { return error(); }
969 return first.is_integer();
970}
971simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number_type() noexcept {
972 if (error()) { return error(); }
973 return first.get_number_type();
974}
975simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number() noexcept {
976 if (error()) { return error(); }
977 return first.get_number();
978}
979#if SIMDJSON_EXCEPTIONS
980template <class T>
981simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator T() noexcept(false) {
982 static_assert(std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::value == false, "You should not call get<T> when T is a document");
983 static_assert(std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value == false, "You should not call get<T> when T is a document");
984 if (error()) { throw simdjson_error(error()); }
985 return first.get<T>();
986}
987simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) {
988 if (error()) { throw simdjson_error(error()); }
989 return first;
990}
991simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) {
992 if (error()) { throw simdjson_error(error()); }
993 return first;
994}
995simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator uint64_t() noexcept(false) {
996 if (error()) { throw simdjson_error(error()); }
997 return first;
998}
999simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator int64_t() noexcept(false) {
1000 if (error()) { throw simdjson_error(error()); }
1001 return first;
1002}
1003simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator double() noexcept(false) {
1004 if (error()) { throw simdjson_error(error()); }
1005 return first;
1006}
1007simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator std::string_view() noexcept(false) {
1008 if (error()) { throw simdjson_error(error()); }
1009 return first;
1010}
1011simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
1012 if (error()) { throw simdjson_error(error()); }
1013 return first;
1014}
1015simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator bool() noexcept(false) {
1016 if (error()) { throw simdjson_error(error()); }
1017 return first;
1018}
1019simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
1020 if (error()) { throw simdjson_error(error()); }
1021 return first;
1022}
1023#endif
1024
1025simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::current_location() noexcept {
1026 if (error()) { return error(); }
1027 return first.current_location();
1028}
1029
1031 if (error()) { return error(); }
1032 return first.raw_json_token();
1033}
1034
1036 if (error()) { return error(); }
1037 return first.at_pointer(json_pointer);
1038}
1039
1040simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at_path(std::string_view json_path) noexcept {
1041 if (error()) {
1042 return error();
1043 }
1044 return first.at_path(json_path);
1045}
1046simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at_path_with_wildcard(std::string_view json_path) noexcept {
1047 if (error()) {
1048 return error();
1049 }
1050 return first.at_path_with_wildcard(json_path);
1051}
1052#if SIMDJSON_STATIC_REFLECTION
1053template<constevalutil::fixed_string... FieldNames, typename T>
1054 requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
1055simdjson_warn_unused simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::extract_into(T& out) & noexcept {
1056 if (error()) { return error(); }
1057 return first.extract_into<FieldNames...>(out);
1058}
1059#endif // SIMDJSON_STATIC_REFLECTION
1060} // namespace simdjson
1061
1062#endif // SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_INL_H
static simdjson_inline simdjson_result< array > start_root(value_iterator &iter) noexcept
Begin array iteration from the root.
Definition array-inl.h:68
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
The document_reference instances are used primarily/solely for streams of JSON documents.
simdjson_inline simdjson_result< value > at(size_t index) &noexcept
Get the value at the given index in the array.
simdjson_warn_unused simdjson_inline error_code consume() noexcept
Consumes the document.
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
bool is_alive() noexcept
Some unrecoverable error conditions may render the document instance unusable.
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
simdjson_inline simdjson_result< object > get_object() &noexcept
Cast this JSON value to an object.
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the document is a string.
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
simdjson_inline bool is_negative() noexcept
Checks whether the document is a negative number.
simdjson_inline document() noexcept=default
Create a new invalid document.
simdjson_inline simdjson_result< std::string_view > raw_json_token() noexcept
Get the raw JSON for this token.
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to an unsigned integer.
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
simdjson_inline simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
simdjson_inline simdjson_result< json_type > type() noexcept
Get the type of this JSON value.
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
simdjson_inline simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
json_iterator iter
Current position in the document.
Definition document.h:793
simdjson_inline simdjson_result< std::vector< value > > at_path_with_wildcard(std::string_view json_path) noexcept
Get all values matching the given JSONPath expression with wildcard support.
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
std::string to_debug_string() noexcept
Returns debugging information.
void rewind() noexcept
Reset the iterator inside the document instance so we are pointing back at the beginning of the docum...
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Consumes the document and returns a string_view instance corresponding to the document as represented...
simdjson_inline simdjson_result< value > find_field_unordered(std::string_view key) &noexcept
Look up a field by name on an object, without regard to key order.
simdjson_inline simdjson_result< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
simdjson_inline simdjson_result< value > get_value() noexcept
Cast this JSON value to a value when the document is an object or an array.
simdjson_inline simdjson_result< value > find_field(std::string_view key) &noexcept
Look up a field by name on an object (order-sensitive).
simdjson_inline simdjson_result< number_type > get_number_type() noexcept
Determine the number type (integer or floating-point number) as quickly as possible.
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the document is a scalar (string, number, null, Boolean).
simdjson_inline simdjson_result< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a string.
bool at_end() const noexcept
Returns true if this document has been fully parsed.
simdjson_inline simdjson_result< array > get_array() &noexcept
Cast this JSON value to an array.
simdjson_inline simdjson_result< bool > is_integer() noexcept
Checks whether the document is an integer number.
simdjson_result< const char * > current_location() const noexcept
Returns the current location in the document if in bounds.
simdjson_inline simdjson_result< T > get() &noexcept
Get this value as the given type.
Definition document.h:186
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
A forward-only JSON object field iterator.
Definition object.h:21
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
Definition value.h:22
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
@ string
A JSON string ( "a" or "hello world\n" ...)
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
@ SCALAR_DOCUMENT_AS_VALUE
A scalar document is treated as a value.
Definition error.h:49
@ OUT_OF_ORDER_ITERATION
tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
Definition error.h:46
@ NO_SUCH_FIELD
JSON field not found in object.
Definition error.h:40
@ SUCCESS
No error.
Definition error.h:20
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
Definition error.h:42
The result of a simdjson operation that could fail.
Definition error.h:280
simdjson_inline error_code error() const noexcept
The error.
Definition error-inl.h:168
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
Definition error-inl.h:163