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