1 #ifndef SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_INL_H
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"
20 namespace SIMDJSON_IMPLEMENTATION {
24 : iter{std::forward<json_iterator>(_iter)}
26 logger::log_start_value(iter,
"document");
29 simdjson_inline document document::start(json_iterator &&iter) noexcept {
30 return document(std::forward<json_iterator>(iter));
38 return iter.to_string();
42 return iter.current_location();
55 return iter.is_alive();
57 simdjson_inline value_iterator document::resume_value_iterator() noexcept {
58 return value_iterator(&
iter, 1,
iter.root_position());
60 simdjson_inline value_iterator document::get_root_value_iterator() noexcept {
61 return resume_value_iterator();
67 return object::resume(resume_value_iterator());
76 #if SIMDJSON_DEVELOPMENT_CHECKS
83 iter.assert_at_root();
84 switch (*
iter.peek()) {
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());
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());
106 auto value = get_root_value_iterator();
110 auto value = get_root_value_iterator();
111 return object::start_root(
value);
123 return get_root_value_iterator().get_root_uint64(
true);
126 return get_root_value_iterator().get_root_uint64_in_string(
true);
129 return get_root_value_iterator().get_root_int64(
true);
132 return get_root_value_iterator().get_root_int64_in_string(
true);
135 return get_root_value_iterator().get_root_double(
true);
138 return get_root_value_iterator().get_root_double_in_string(
true);
141 return get_root_value_iterator().get_root_string(
true, allow_replacement);
143 template <
typename string_type>
145 return get_root_value_iterator().get_root_string(receiver,
true, allow_replacement);
148 return get_root_value_iterator().get_root_wobbly_string(
true);
151 return get_root_value_iterator().get_root_raw_json_string(
true);
154 return get_root_value_iterator().get_root_bool(
true);
157 return get_root_value_iterator().is_root_null(
true);
163 template<> simdjson_inline simdjson_result<std::string_view>
document::get() & noexcept {
return get_string(
false); }
164 template<> simdjson_inline simdjson_result<double>
document::get() & noexcept {
return get_double(); }
165 template<> simdjson_inline simdjson_result<uint64_t>
document::get() & noexcept {
return get_uint64(); }
166 template<> simdjson_inline simdjson_result<int64_t>
document::get() & noexcept {
return get_int64(); }
167 template<> simdjson_inline simdjson_result<bool>
document::get() & noexcept {
return get_bool(); }
168 template<> simdjson_inline simdjson_result<value>
document::get() & noexcept {
return get_value(); }
172 template<> simdjson_inline
error_code document::get(raw_json_string& out) & noexcept {
return get_raw_json_string().get(out); }
173 template<> simdjson_inline
error_code document::get(std::string_view& out) & noexcept {
return get_string(
false).get(out); }
175 template<> simdjson_inline
error_code document::get(uint64_t& out) & noexcept {
return get_uint64().get(out); }
180 template<> simdjson_deprecated simdjson_inline simdjson_result<raw_json_string>
document::get() && noexcept {
return get_raw_json_string(); }
181 template<> simdjson_deprecated simdjson_inline simdjson_result<std::string_view>
document::get() && noexcept {
return get_string(
false); }
182 template<> simdjson_deprecated simdjson_inline simdjson_result<double>
document::get() && noexcept {
return std::forward<document>(*this).get_double(); }
183 template<> simdjson_deprecated simdjson_inline simdjson_result<uint64_t>
document::get() && noexcept {
return std::forward<document>(*this).get_uint64(); }
184 template<> simdjson_deprecated simdjson_inline simdjson_result<int64_t>
document::get() && noexcept {
return std::forward<document>(*this).get_int64(); }
185 template<> simdjson_deprecated simdjson_inline simdjson_result<bool>
document::get() && noexcept {
return std::forward<document>(*this).get_bool(); }
186 template<> simdjson_deprecated simdjson_inline simdjson_result<value>
document::get() && noexcept {
return get_value(); }
188 #if SIMDJSON_EXCEPTIONS
190 simdjson_deprecated simdjson_inline document::operator T() && noexcept(
false) {
return get<T>(); }
192 simdjson_inline document::operator T() & noexcept(
false) {
return get<T>(); }
193 simdjson_inline document::operator
array() & noexcept(
false) {
return get_array(); }
194 simdjson_inline document::operator
object() & noexcept(
false) {
return get_object(); }
195 simdjson_inline document::operator uint64_t() noexcept(false) {
return get_uint64(); }
196 simdjson_inline document::operator int64_t() noexcept(false) {
return get_int64(); }
197 simdjson_inline document::operator double() noexcept(false) {
return get_double(); }
198 simdjson_inline document::operator std::string_view() noexcept(false) {
return get_string(
false); }
199 simdjson_inline document::operator
raw_json_string() noexcept(false) {
return get_raw_json_string(); }
200 simdjson_inline document::operator bool() noexcept(false) {
return get_bool(); }
201 simdjson_inline document::operator
value() noexcept(false) {
return get_value(); }
205 auto a = get_array();
212 auto a = get_object();
219 auto a = get_array();
223 return get_array().begin();
230 return start_or_resume_object().find_field(key);
233 return start_or_resume_object().find_field(key);
236 return start_or_resume_object().find_field_unordered(key);
239 return start_or_resume_object().find_field_unordered(key);
242 return start_or_resume_object()[key];
245 return start_or_resume_object()[key];
249 auto error =
iter.skip_child(0);
250 if(error) {
iter.abandon(); }
255 auto _iter = get_root_value_iterator();
256 const uint8_t * starting_point{_iter.peek_start()};
258 if(error) {
return error; }
262 const uint8_t * final_point{
iter.unsafe_pointer()};
263 return std::string_view(
reinterpret_cast<const char*
>(starting_point),
size_t(final_point - starting_point));
267 return get_root_value_iterator().type();
272 auto error =
type().get(this_type);
273 if(error) {
return error; }
279 auto error =
type().get(this_type);
280 if(error) {
return error; }
285 return get_root_value_iterator().is_root_negative();
289 return get_root_value_iterator().is_root_integer(
true);
293 return get_root_value_iterator().get_root_number_type(
true);
297 return get_root_value_iterator().get_root_number(
true);
302 auto _iter = get_root_value_iterator();
303 return std::string_view(
reinterpret_cast<const char*
>(_iter.peek_start()), _iter.peek_root_length());
308 if (json_pointer.empty()) {
309 return this->get_value();
312 SIMDJSON_TRY(type().get(t));
316 return (*this).get_array().at_pointer(json_pointer);
318 return (*this).get_object().at_pointer(json_pointer);
326 if (json_path.empty()) {
327 return this->get_value();
330 SIMDJSON_TRY(type().get(t));
333 return (*this).get_array().at_path(json_path);
335 return (*this).get_object().at_path(json_path);
347 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
348 SIMDJSON_IMPLEMENTATION::ondemand::document &&value
350 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
351 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(value)
355 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
358 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
363 simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::count_elements() & noexcept {
364 if (error()) {
return error(); }
365 return first.count_elements();
367 simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::count_fields() & noexcept {
368 if (error()) {
return error(); }
369 return first.count_fields();
371 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at(
size_t index) & noexcept {
372 if (error()) {
return error(); }
373 return first.at(index);
375 simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::rewind() noexcept {
380 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::begin() & noexcept {
381 if (error()) {
return error(); }
382 return first.begin();
384 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::end() & noexcept {
387 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field_unordered(std::string_view key) & noexcept {
388 if (error()) {
return error(); }
389 return first.find_field_unordered(key);
391 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field_unordered(
const char *key) & noexcept {
392 if (error()) {
return error(); }
393 return first.find_field_unordered(key);
395 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator[](std::string_view key) & noexcept {
396 if (error()) {
return error(); }
399 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator[](
const char *key) & noexcept {
400 if (error()) {
return error(); }
403 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field(std::string_view key) & noexcept {
404 if (error()) {
return error(); }
405 return first.find_field(key);
407 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field(
const char *key) & noexcept {
408 if (error()) {
return error(); }
409 return first.find_field(key);
411 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_array() & noexcept {
412 if (error()) {
return error(); }
413 return first.get_array();
415 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_object() & noexcept {
416 if (error()) {
return error(); }
417 return first.get_object();
419 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64() noexcept {
421 return first.get_uint64();
423 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64_in_string() noexcept {
425 return first.get_uint64_in_string();
427 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64() noexcept {
429 return first.get_int64();
431 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64_in_string() noexcept {
433 return first.get_int64_in_string();
435 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double() noexcept {
437 return first.get_double();
439 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double_in_string() noexcept {
441 return first.get_double_in_string();
443 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_string(
bool allow_replacement) noexcept {
444 if (error()) {
return error(); }
445 return first.get_string(allow_replacement);
447 template <
typename string_type>
448 simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_string(string_type& receiver,
bool allow_replacement) noexcept {
449 if (error()) {
return error(); }
450 return first.get_string(receiver, allow_replacement);
452 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_wobbly_string() noexcept {
454 return first.get_wobbly_string();
456 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_raw_json_string() noexcept {
458 return first.get_raw_json_string();
460 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_bool() noexcept {
462 return first.get_bool();
464 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_value() noexcept {
466 return first.get_value();
468 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_null() noexcept {
470 return first.is_null();
475 if (error()) {
return error(); }
476 return first.get<T>();
480 if (error()) {
return error(); }
481 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>();
485 if (error()) {
return error(); }
486 return first.get<T>(out);
490 if (error()) {
return error(); }
491 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>(out);
494 template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() & noexcept =
delete;
495 template<> simdjson_deprecated simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() && noexcept {
496 if (error()) {
return error(); }
497 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
499 template<> simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) & noexcept =
delete;
500 template<> simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) && noexcept {
501 if (error()) {
return error(); }
502 out = std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
506 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::type() noexcept {
511 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_scalar() noexcept {
513 return first.is_scalar();
516 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_string() noexcept {
518 return first.is_string();
521 simdjson_inline
bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_negative() noexcept {
523 return first.is_negative();
526 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_integer() noexcept {
528 return first.is_integer();
531 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number_type() noexcept {
533 return first.get_number_type();
536 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number() noexcept {
538 return first.get_number();
542 #if SIMDJSON_EXCEPTIONS
543 template <class T, typename std::enable_if<std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value ==
false>::type>
544 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator T() noexcept(false) {
545 if (error()) {
throw simdjson_error(error()); }
548 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(
false) {
549 if (error()) {
throw simdjson_error(error()); }
552 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(
false) {
553 if (error()) {
throw simdjson_error(error()); }
556 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator uint64_t() noexcept(false) {
557 if (error()) {
throw simdjson_error(error()); }
560 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator int64_t() noexcept(false) {
561 if (error()) {
throw simdjson_error(error()); }
564 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator double() noexcept(false) {
565 if (error()) {
throw simdjson_error(error()); }
568 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator std::string_view() noexcept(false) {
569 if (error()) {
throw simdjson_error(error()); }
572 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
573 if (error()) {
throw simdjson_error(error()); }
576 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator bool() noexcept(false) {
577 if (error()) {
throw simdjson_error(error()); }
580 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
581 if (error()) {
throw simdjson_error(error()); }
587 simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_location() noexcept {
589 return first.current_location();
592 simdjson_inline
bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_end() const noexcept {
594 return first.at_end();
598 simdjson_inline int32_t simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_depth() const noexcept {
600 return first.current_depth();
605 return first.raw_json_token();
609 if (error()) {
return error(); }
610 return first.at_pointer(json_pointer);
613 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_path(std::string_view json_path) noexcept {
614 if (error()) {
return error(); }
615 return first.at_path(json_path);
622 namespace SIMDJSON_IMPLEMENTATION {
625 simdjson_inline document_reference::document_reference() noexcept : doc{
nullptr} {}
626 simdjson_inline document_reference::document_reference(document &d) noexcept : doc(&d) {}
627 simdjson_inline
void document_reference::rewind() noexcept { doc->
rewind(); }
628 simdjson_inline simdjson_result<array> document_reference::get_array() & noexcept {
return doc->get_array(); }
629 simdjson_inline simdjson_result<object> document_reference::get_object() & noexcept {
return doc->get_object(); }
645 simdjson_inline
simdjson_result<uint64_t> document_reference::get_uint64_in_string() noexcept {
return doc->get_root_value_iterator().get_root_uint64_in_string(
false); }
646 simdjson_inline
simdjson_result<int64_t> document_reference::get_int64() noexcept {
return doc->get_root_value_iterator().get_root_int64(
false); }
647 simdjson_inline
simdjson_result<int64_t> document_reference::get_int64_in_string() noexcept {
return doc->get_root_value_iterator().get_root_int64_in_string(
false); }
648 simdjson_inline simdjson_result<double> document_reference::get_double() noexcept {
return doc->get_root_value_iterator().get_root_double(
false); }
649 simdjson_inline simdjson_result<double> document_reference::get_double_in_string() noexcept {
return doc->get_root_value_iterator().get_root_double(
false); }
650 simdjson_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); }
651 template <
typename string_type>
652 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); }
653 simdjson_inline simdjson_result<std::string_view> document_reference::get_wobbly_string() noexcept {
return doc->get_root_value_iterator().get_root_wobbly_string(
false); }
654 simdjson_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); }
655 simdjson_inline simdjson_result<bool> document_reference::get_bool() noexcept {
return doc->get_root_value_iterator().get_root_bool(
false); }
656 simdjson_inline simdjson_result<value> document_reference::get_value() noexcept {
return doc->
get_value(); }
657 simdjson_inline simdjson_result<bool> document_reference::is_null() noexcept {
return doc->get_root_value_iterator().is_root_null(
false); }
658 template<> simdjson_inline simdjson_result<array> document_reference::get() & noexcept {
return get_array(); }
659 template<> simdjson_inline simdjson_result<object> document_reference::get() & noexcept {
return get_object(); }
660 template<> simdjson_inline simdjson_result<raw_json_string> document_reference::get() & noexcept {
return get_raw_json_string(); }
661 template<> simdjson_inline simdjson_result<std::string_view> document_reference::get() & noexcept {
return get_string(
false); }
662 template<> simdjson_inline simdjson_result<double> document_reference::get() & noexcept {
return get_double(); }
663 template<> simdjson_inline simdjson_result<uint64_t> document_reference::get() & noexcept {
return get_uint64(); }
664 template<> simdjson_inline simdjson_result<int64_t> document_reference::get() & noexcept {
return get_int64(); }
665 template<> simdjson_inline simdjson_result<bool> document_reference::get() & noexcept {
return get_bool(); }
666 template<> simdjson_inline simdjson_result<value> document_reference::get() & noexcept {
return get_value(); }
667 #if SIMDJSON_EXCEPTIONS
669 simdjson_inline document_reference::operator T() noexcept(false) {
return get<T>(); }
670 simdjson_inline document_reference::operator
array() & noexcept(
false) {
return array(*doc); }
671 simdjson_inline document_reference::operator
object() & noexcept(
false) {
return object(*doc); }
672 simdjson_inline document_reference::operator uint64_t() noexcept(false) {
return get_uint64(); }
673 simdjson_inline document_reference::operator int64_t() noexcept(false) {
return get_int64(); }
674 simdjson_inline document_reference::operator double() noexcept(false) {
return get_double(); }
675 simdjson_inline document_reference::operator std::string_view() noexcept(false) {
return std::string_view(*doc); }
676 simdjson_inline document_reference::operator raw_json_string() noexcept(false) {
return get_raw_json_string(); }
677 simdjson_inline document_reference::operator bool() noexcept(false) {
return get_bool(); }
678 simdjson_inline document_reference::operator value() noexcept(false) {
return value(*doc); }
680 simdjson_inline simdjson_result<size_t> document_reference::count_elements() & noexcept {
return doc->count_elements(); }
681 simdjson_inline simdjson_result<size_t> document_reference::count_fields() & noexcept {
return doc->count_fields(); }
682 simdjson_inline simdjson_result<value> document_reference::at(
size_t index) & noexcept {
return doc->at(index); }
683 simdjson_inline simdjson_result<array_iterator> document_reference::begin() & noexcept {
return doc->begin(); }
684 simdjson_inline simdjson_result<array_iterator> document_reference::end() & noexcept {
return doc->end(); }
685 simdjson_inline simdjson_result<value> document_reference::find_field(std::string_view key) & noexcept {
return doc->find_field(key); }
686 simdjson_inline simdjson_result<value> document_reference::find_field(
const char *key) & noexcept {
return doc->find_field(key); }
687 simdjson_inline simdjson_result<value> document_reference::operator[](std::string_view key) & noexcept {
return (*doc)[key]; }
688 simdjson_inline simdjson_result<value> document_reference::operator[](
const char *key) & noexcept {
return (*doc)[key]; }
689 simdjson_inline simdjson_result<value> document_reference::find_field_unordered(std::string_view key) & noexcept {
return doc->find_field_unordered(key); }
690 simdjson_inline simdjson_result<value> document_reference::find_field_unordered(
const char *key) & noexcept {
return doc->find_field_unordered(key); }
691 simdjson_inline simdjson_result<json_type> document_reference::type() noexcept {
return doc->
type(); }
692 simdjson_inline simdjson_result<bool> document_reference::is_scalar() noexcept {
return doc->
is_scalar(); }
693 simdjson_inline simdjson_result<bool> document_reference::is_string() noexcept {
return doc->
is_string(); }
694 simdjson_inline simdjson_result<const char *> document_reference::current_location() noexcept {
return doc->
current_location(); }
695 simdjson_inline int32_t document_reference::current_depth() const noexcept {
return doc->
current_depth(); }
696 simdjson_inline
bool document_reference::is_negative() noexcept {
return doc->
is_negative(); }
697 simdjson_inline simdjson_result<bool> document_reference::is_integer() noexcept {
return doc->get_root_value_iterator().is_root_integer(
false); }
698 simdjson_inline simdjson_result<number_type> document_reference::get_number_type() noexcept {
return doc->get_root_value_iterator().get_root_number_type(
false); }
699 simdjson_inline simdjson_result<number> document_reference::get_number() noexcept {
return doc->get_root_value_iterator().get_root_number(
false); }
700 simdjson_inline simdjson_result<std::string_view> document_reference::raw_json_token() noexcept {
return doc->
raw_json_token(); }
701 simdjson_inline simdjson_result<value> document_reference::at_pointer(std::string_view json_pointer) noexcept {
return doc->at_pointer(json_pointer); }
702 simdjson_inline simdjson_result<value> document_reference::at_path(std::string_view json_path) noexcept {
return doc->at_path(json_path); }
703 simdjson_inline simdjson_result<std::string_view> document_reference::raw_json() noexcept {
return doc->
raw_json();}
704 simdjson_inline document_reference::operator document&()
const noexcept {
return *doc; }
713 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document_reference value,
error_code error)
714 noexcept : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(value), error) {}
717 simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::count_elements() & noexcept {
718 if (error()) {
return error(); }
719 return first.count_elements();
721 simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::count_fields() & noexcept {
722 if (error()) {
return error(); }
723 return first.count_fields();
725 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at(
size_t index) & noexcept {
726 if (error()) {
return error(); }
727 return first.at(index);
729 simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::rewind() noexcept {
734 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::begin() & noexcept {
735 if (error()) {
return error(); }
736 return first.begin();
738 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::end() & noexcept {
741 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field_unordered(std::string_view key) & noexcept {
742 if (error()) {
return error(); }
743 return first.find_field_unordered(key);
745 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field_unordered(
const char *key) & noexcept {
746 if (error()) {
return error(); }
747 return first.find_field_unordered(key);
749 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator[](std::string_view key) & noexcept {
750 if (error()) {
return error(); }
753 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator[](
const char *key) & noexcept {
754 if (error()) {
return error(); }
757 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field(std::string_view key) & noexcept {
758 if (error()) {
return error(); }
759 return first.find_field(key);
761 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field(
const char *key) & noexcept {
762 if (error()) {
return error(); }
763 return first.find_field(key);
765 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_array() & noexcept {
766 if (error()) {
return error(); }
767 return first.get_array();
769 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_object() & noexcept {
770 if (error()) {
return error(); }
771 return first.get_object();
773 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64() noexcept {
775 return first.get_uint64();
777 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64_in_string() noexcept {
779 return first.get_uint64_in_string();
781 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64() noexcept {
783 return first.get_int64();
785 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64_in_string() noexcept {
787 return first.get_int64_in_string();
789 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double() noexcept {
791 return first.get_double();
793 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double_in_string() noexcept {
795 return first.get_double_in_string();
797 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_string(
bool allow_replacement) noexcept {
798 if (error()) {
return error(); }
799 return first.get_string(allow_replacement);
801 template <
typename string_type>
802 simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_string(string_type& receiver,
bool allow_replacement) noexcept {
803 if (error()) {
return error(); }
804 return first.get_string(receiver, allow_replacement);
806 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_wobbly_string() noexcept {
808 return first.get_wobbly_string();
810 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_raw_json_string() noexcept {
812 return first.get_raw_json_string();
814 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_bool() noexcept {
816 return first.get_bool();
818 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_value() noexcept {
820 return first.get_value();
822 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_null() noexcept {
824 return first.is_null();
828 if (error()) {
return error(); }
829 return first.get<T>();
833 if (error()) {
return error(); }
834 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(first).get<T>();
838 if (error()) {
return error(); }
839 return first.get<T>(out);
843 if (error()) {
return error(); }
844 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(first).get<T>(out);
846 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::type() noexcept {
850 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_scalar() noexcept {
852 return first.is_scalar();
854 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_string() noexcept {
856 return first.is_string();
860 if (error()) {
return error(); }
866 if (error()) {
return error(); }
870 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_negative() noexcept {
872 return first.is_negative();
874 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_integer() noexcept {
876 return first.is_integer();
878 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number_type() noexcept {
880 return first.get_number_type();
882 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number() noexcept {
884 return first.get_number();
886 #if SIMDJSON_EXCEPTIONS
888 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator T() noexcept(false) {
889 static_assert(std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::value ==
false,
"You should not call get<T> when T is a document");
890 static_assert(std::is_same<T, SIMDJSON_IMPLEMENTATION::ondemand::document>::value ==
false,
"You should not call get<T> when T is a document");
891 if (error()) {
throw simdjson_error(error()); }
892 return first.get<T>();
894 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(
false) {
895 if (error()) {
throw simdjson_error(error()); }
898 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(
false) {
899 if (error()) {
throw simdjson_error(error()); }
902 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator uint64_t() noexcept(false) {
903 if (error()) {
throw simdjson_error(error()); }
906 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator int64_t() noexcept(false) {
907 if (error()) {
throw simdjson_error(error()); }
910 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator double() noexcept(false) {
911 if (error()) {
throw simdjson_error(error()); }
914 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator std::string_view() noexcept(false) {
915 if (error()) {
throw simdjson_error(error()); }
918 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
919 if (error()) {
throw simdjson_error(error()); }
922 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator bool() noexcept(false) {
923 if (error()) {
throw simdjson_error(error()); }
926 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
927 if (error()) {
throw simdjson_error(error()); }
932 simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::current_location() noexcept {
934 return first.current_location();
939 return first.raw_json_token();
943 if (error()) {
return error(); }
944 return first.at_pointer(json_pointer);
947 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at_path(std::string_view json_path) noexcept {
951 return first.at_path(json_path);
A forward-only JSON array.
static simdjson_inline simdjson_result< array > start_root(value_iterator &iter) noexcept
Begin array iteration from the root.
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_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< T > get() &noexcept
Get this value as the given type.
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.
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 error_code consume() noexcept
Consumes the document.
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< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
A forward-only JSON object field iterator.
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
json_type
The type of a JSON value.
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
@ string
A JSON string ( "a" or "hello world\n" ...)
@ array
A JSON array ( [ 1, 2, 3 ... ] )
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
@ SCALAR_DOCUMENT_AS_VALUE
A scalar document is treated as a value.
@ OUT_OF_ORDER_ITERATION
tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.