simdjson  3.11.0
Ridiculously Fast JSON
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 namespace simdjson {
20 namespace SIMDJSON_IMPLEMENTATION {
21 namespace ondemand {
22 
23 simdjson_inline document::document(ondemand::json_iterator &&_iter) noexcept
24  : iter{std::forward<json_iterator>(_iter)}
25 {
26  logger::log_start_value(iter, "document");
27 }
28 
29 simdjson_inline document document::start(json_iterator &&iter) noexcept {
30  return document(std::forward<json_iterator>(iter));
31 }
32 
33 inline void document::rewind() noexcept {
34  iter.rewind();
35 }
36 
37 inline std::string document::to_debug_string() noexcept {
38  return iter.to_string();
39 }
40 
42  return iter.current_location();
43 }
44 
45 inline int32_t document::current_depth() const noexcept {
46  return iter.depth();
47 }
48 
49 inline bool document::at_end() const noexcept {
50  return iter.at_end();
51 }
52 
53 
54 inline bool document::is_alive() noexcept {
55  return iter.is_alive();
56 }
57 simdjson_inline value_iterator document::resume_value_iterator() noexcept {
58  return value_iterator(&iter, 1, iter.root_position());
59 }
60 simdjson_inline value_iterator document::get_root_value_iterator() noexcept {
61  return resume_value_iterator();
62 }
63 simdjson_inline simdjson_result<object> document::start_or_resume_object() noexcept {
64  if (iter.at_root()) {
65  return get_object();
66  } else {
67  return object::resume(resume_value_iterator());
68  }
69 }
70 simdjson_inline simdjson_result<value> document::get_value() noexcept {
71  // Make sure we start any arrays or objects before returning, so that start_root_<object/array>()
72  // gets called.
73 
74  // It is the convention throughout the code that the macro `SIMDJSON_DEVELOPMENT_CHECKS` determines whether
75  // we check for OUT_OF_ORDER_ITERATION. Proper on::demand code should never trigger this error.
76 #if SIMDJSON_DEVELOPMENT_CHECKS
77  if (!iter.at_root()) { return OUT_OF_ORDER_ITERATION; }
78 #endif
79  // assert_at_root() serves two purposes: in Debug mode, whether or not
80  // SIMDJSON_DEVELOPMENT_CHECKS is set or not, it checks that we are at the root of
81  // the document (this will typically be redundant). In release mode, it generates
82  // SIMDJSON_ASSUME statements to allow the compiler to make assumptions.
83  iter.assert_at_root();
84  switch (*iter.peek()) {
85  case '[': {
86  // The following lines check that the document ends with ].
87  auto value_iterator = get_root_value_iterator();
88  auto error = value_iterator.check_root_array();
89  if(error) { return error; }
90  return value(get_root_value_iterator());
91  }
92  case '{': {
93  // The following lines would check that the document ends with }.
94  auto value_iterator = get_root_value_iterator();
95  auto error = value_iterator.check_root_object();
96  if(error) { return error; }
97  return value(get_root_value_iterator());
98  }
99  default:
100  // Unfortunately, scalar documents are a special case in simdjson and they cannot
101  // be safely converted to value instances.
103  }
104 }
105 simdjson_inline simdjson_result<array> document::get_array() & noexcept {
106  auto value = get_root_value_iterator();
107  return array::start_root(value);
108 }
109 simdjson_inline simdjson_result<object> document::get_object() & noexcept {
110  auto value = get_root_value_iterator();
111  return object::start_root(value);
112 }
113 
123  return get_root_value_iterator().get_root_uint64(true);
124 }
126  return get_root_value_iterator().get_root_uint64_in_string(true);
127 }
128 simdjson_inline simdjson_result<int64_t> document::get_int64() noexcept {
129  return get_root_value_iterator().get_root_int64(true);
130 }
132  return get_root_value_iterator().get_root_int64_in_string(true);
133 }
134 simdjson_inline simdjson_result<double> document::get_double() noexcept {
135  return get_root_value_iterator().get_root_double(true);
136 }
138  return get_root_value_iterator().get_root_double_in_string(true);
139 }
140 simdjson_inline simdjson_result<std::string_view> document::get_string(bool allow_replacement) noexcept {
141  return get_root_value_iterator().get_root_string(true, allow_replacement);
142 }
143 template <typename string_type>
144 simdjson_inline error_code document::get_string(string_type& receiver, bool allow_replacement) noexcept {
145  return get_root_value_iterator().get_root_string(receiver, true, allow_replacement);
146 }
148  return get_root_value_iterator().get_root_wobbly_string(true);
149 }
151  return get_root_value_iterator().get_root_raw_json_string(true);
152 }
153 simdjson_inline simdjson_result<bool> document::get_bool() noexcept {
154  return get_root_value_iterator().get_root_bool(true);
155 }
156 simdjson_inline simdjson_result<bool> document::is_null() noexcept {
157  return get_root_value_iterator().is_root_null(true);
158 }
159 
160 template<> simdjson_inline simdjson_result<array> document::get() & noexcept { return get_array(); }
161 template<> simdjson_inline simdjson_result<object> document::get() & noexcept { return get_object(); }
162 template<> simdjson_inline simdjson_result<raw_json_string> document::get() & noexcept { return get_raw_json_string(); }
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(); }
169 
170 template<> simdjson_inline error_code document::get(array& out) & noexcept { return get_array().get(out); }
171 template<> simdjson_inline error_code document::get(object& out) & noexcept { return get_object().get(out); }
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); }
174 template<> simdjson_inline error_code document::get(double& out) & noexcept { return get_double().get(out); }
175 template<> simdjson_inline error_code document::get(uint64_t& out) & noexcept { return get_uint64().get(out); }
176 template<> simdjson_inline error_code document::get(int64_t& out) & noexcept { return get_int64().get(out); }
177 template<> simdjson_inline error_code document::get(bool& out) & noexcept { return get_bool().get(out); }
178 template<> simdjson_inline error_code document::get(value& out) & noexcept { return get_value().get(out); }
179 
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(); }
187 
188 #if SIMDJSON_EXCEPTIONS
189 template <class T>
190 simdjson_deprecated simdjson_inline document::operator T() && noexcept(false) { return get<T>(); }
191 template <class 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(); }
202 
203 #endif
204 simdjson_inline simdjson_result<size_t> document::count_elements() & noexcept {
205  auto a = get_array();
206  simdjson_result<size_t> answer = a.count_elements();
207  /* If there was an array, we are now left pointing at its first element. */
208  if(answer.error() == SUCCESS) { rewind(); }
209  return answer;
210 }
211 simdjson_inline simdjson_result<size_t> document::count_fields() & noexcept {
212  auto a = get_object();
213  simdjson_result<size_t> answer = a.count_fields();
214  /* If there was an object, we are now left pointing at its first element. */
215  if(answer.error() == SUCCESS) { rewind(); }
216  return answer;
217 }
218 simdjson_inline simdjson_result<value> document::at(size_t index) & noexcept {
219  auto a = get_array();
220  return a.at(index);
221 }
222 simdjson_inline simdjson_result<array_iterator> document::begin() & noexcept {
223  return get_array().begin();
224 }
225 simdjson_inline simdjson_result<array_iterator> document::end() & noexcept {
226  return {};
227 }
228 
229 simdjson_inline simdjson_result<value> document::find_field(std::string_view key) & noexcept {
230  return start_or_resume_object().find_field(key);
231 }
232 simdjson_inline simdjson_result<value> document::find_field(const char *key) & noexcept {
233  return start_or_resume_object().find_field(key);
234 }
235 simdjson_inline simdjson_result<value> document::find_field_unordered(std::string_view key) & noexcept {
236  return start_or_resume_object().find_field_unordered(key);
237 }
238 simdjson_inline simdjson_result<value> document::find_field_unordered(const char *key) & noexcept {
239  return start_or_resume_object().find_field_unordered(key);
240 }
241 simdjson_inline simdjson_result<value> document::operator[](std::string_view key) & noexcept {
242  return start_or_resume_object()[key];
243 }
244 simdjson_inline simdjson_result<value> document::operator[](const char *key) & noexcept {
245  return start_or_resume_object()[key];
246 }
247 
248 simdjson_inline error_code document::consume() noexcept {
249  auto error = iter.skip_child(0);
250  if(error) { iter.abandon(); }
251  return error;
252 }
253 
255  auto _iter = get_root_value_iterator();
256  const uint8_t * starting_point{_iter.peek_start()};
257  auto error = consume();
258  if(error) { return error; }
259  // After 'consume()', we could be left pointing just beyond the document, but that
260  // is ok because we are not going to dereference the final pointer position, we just
261  // use it to compute the length in bytes.
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));
264 }
265 
266 simdjson_inline simdjson_result<json_type> document::type() noexcept {
267  return get_root_value_iterator().type();
268 }
269 
270 simdjson_inline simdjson_result<bool> document::is_scalar() noexcept {
271  json_type this_type;
272  auto error = type().get(this_type);
273  if(error) { return error; }
274  return ! ((this_type == json_type::array) || (this_type == json_type::object));
275 }
276 
277 simdjson_inline simdjson_result<bool> document::is_string() noexcept {
278  json_type this_type;
279  auto error = type().get(this_type);
280  if(error) { return error; }
281  return (this_type == json_type::string);
282 }
283 
284 simdjson_inline bool document::is_negative() noexcept {
285  return get_root_value_iterator().is_root_negative();
286 }
287 
288 simdjson_inline simdjson_result<bool> document::is_integer() noexcept {
289  return get_root_value_iterator().is_root_integer(true);
290 }
291 
293  return get_root_value_iterator().get_root_number_type(true);
294 }
295 
296 simdjson_inline simdjson_result<number> document::get_number() noexcept {
297  return get_root_value_iterator().get_root_number(true);
298 }
299 
300 
302  auto _iter = get_root_value_iterator();
303  return std::string_view(reinterpret_cast<const char*>(_iter.peek_start()), _iter.peek_root_length());
304 }
305 
306 simdjson_inline simdjson_result<value> document::at_pointer(std::string_view json_pointer) noexcept {
307  rewind(); // Rewind the document each time at_pointer is called
308  if (json_pointer.empty()) {
309  return this->get_value();
310  }
311  json_type t;
312  SIMDJSON_TRY(type().get(t));
313  switch (t)
314  {
315  case json_type::array:
316  return (*this).get_array().at_pointer(json_pointer);
317  case json_type::object:
318  return (*this).get_object().at_pointer(json_pointer);
319  default:
320  return INVALID_JSON_POINTER;
321  }
322 }
323 
324 simdjson_inline simdjson_result<value> document::at_path(std::string_view json_path) noexcept {
325  rewind(); // Rewind the document each time at_pointer is called
326  if (json_path.empty()) {
327  return this->get_value();
328  }
329  json_type t;
330  SIMDJSON_TRY(type().get(t));
331  switch (t) {
332  case json_type::array:
333  return (*this).get_array().at_path(json_path);
334  case json_type::object:
335  return (*this).get_object().at_path(json_path);
336  default:
337  return INVALID_JSON_POINTER;
338  }
339 }
340 
341 } // namespace ondemand
342 } // namespace SIMDJSON_IMPLEMENTATION
343 } // namespace simdjson
344 
345 namespace simdjson {
346 
347 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
348  SIMDJSON_IMPLEMENTATION::ondemand::document &&value
349 ) noexcept :
350  implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
351  std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(value)
352  )
353 {
354 }
355 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
356  error_code error
357 ) noexcept :
358  implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
359  error
360  )
361 {
362 }
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();
366 }
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();
370 }
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);
374 }
375 simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::rewind() noexcept {
376  if (error()) { return error(); }
377  first.rewind();
378  return SUCCESS;
379 }
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();
383 }
384 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::end() & noexcept {
385  return {};
386 }
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);
390 }
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);
394 }
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(); }
397  return first[key];
398 }
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(); }
401  return first[key];
402 }
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);
406 }
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);
410 }
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();
414 }
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();
418 }
419 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64() noexcept {
420  if (error()) { return error(); }
421  return first.get_uint64();
422 }
423 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64_in_string() noexcept {
424  if (error()) { return error(); }
425  return first.get_uint64_in_string();
426 }
427 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64() noexcept {
428  if (error()) { return error(); }
429  return first.get_int64();
430 }
431 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64_in_string() noexcept {
432  if (error()) { return error(); }
433  return first.get_int64_in_string();
434 }
435 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double() noexcept {
436  if (error()) { return error(); }
437  return first.get_double();
438 }
439 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double_in_string() noexcept {
440  if (error()) { return error(); }
441  return first.get_double_in_string();
442 }
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);
446 }
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);
451 }
452 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_wobbly_string() noexcept {
453  if (error()) { return error(); }
454  return first.get_wobbly_string();
455 }
456 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_raw_json_string() noexcept {
457  if (error()) { return error(); }
458  return first.get_raw_json_string();
459 }
460 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_bool() noexcept {
461  if (error()) { return error(); }
462  return first.get_bool();
463 }
464 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_value() noexcept {
465  if (error()) { return error(); }
466  return first.get_value();
467 }
468 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_null() noexcept {
469  if (error()) { return error(); }
470  return first.is_null();
471 }
472 
473 template<typename T>
474 simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get() & noexcept {
475  if (error()) { return error(); }
476  return first.get<T>();
477 }
478 template<typename T>
479 simdjson_deprecated simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get() && noexcept {
480  if (error()) { return error(); }
481  return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>();
482 }
483 template<typename T>
485  if (error()) { return error(); }
486  return first.get<T>(out);
487 }
488 template<typename T>
490  if (error()) { return error(); }
491  return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>(out);
492 }
493 
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);
498 }
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);
503  return SUCCESS;
504 }
505 
506 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::type() noexcept {
507  if (error()) { return error(); }
508  return first.type();
509 }
510 
511 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_scalar() noexcept {
512  if (error()) { return error(); }
513  return first.is_scalar();
514 }
515 
516 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_string() noexcept {
517  if (error()) { return error(); }
518  return first.is_string();
519 }
520 
521 simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_negative() noexcept {
522  if (error()) { return error(); }
523  return first.is_negative();
524 }
525 
526 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_integer() noexcept {
527  if (error()) { return error(); }
528  return first.is_integer();
529 }
530 
531 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number_type() noexcept {
532  if (error()) { return error(); }
533  return first.get_number_type();
534 }
535 
536 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number() noexcept {
537  if (error()) { return error(); }
538  return first.get_number();
539 }
540 
541 
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()); }
546  return first;
547 }
548 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) {
549  if (error()) { throw simdjson_error(error()); }
550  return first;
551 }
552 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) {
553  if (error()) { throw simdjson_error(error()); }
554  return first;
555 }
556 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator uint64_t() noexcept(false) {
557  if (error()) { throw simdjson_error(error()); }
558  return first;
559 }
560 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator int64_t() noexcept(false) {
561  if (error()) { throw simdjson_error(error()); }
562  return first;
563 }
564 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator double() noexcept(false) {
565  if (error()) { throw simdjson_error(error()); }
566  return first;
567 }
568 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator std::string_view() noexcept(false) {
569  if (error()) { throw simdjson_error(error()); }
570  return first;
571 }
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()); }
574  return first;
575 }
576 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator bool() noexcept(false) {
577  if (error()) { throw simdjson_error(error()); }
578  return first;
579 }
580 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
581  if (error()) { throw simdjson_error(error()); }
582  return first;
583 }
584 #endif
585 
586 
587 simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_location() noexcept {
588  if (error()) { return error(); }
589  return first.current_location();
590 }
591 
592 simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_end() const noexcept {
593  if (error()) { return error(); }
594  return first.at_end();
595 }
596 
597 
598 simdjson_inline int32_t simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_depth() const noexcept {
599  if (error()) { return error(); }
600  return first.current_depth();
601 }
602 
604  if (error()) { return error(); }
605  return first.raw_json_token();
606 }
607 
609  if (error()) { return error(); }
610  return first.at_pointer(json_pointer);
611 }
612 
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);
616 }
617 
618 } // namespace simdjson
619 
620 
621 namespace simdjson {
622 namespace SIMDJSON_IMPLEMENTATION {
623 namespace ondemand {
624 
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(); }
644 simdjson_inline simdjson_result<uint64_t> document_reference::get_uint64() noexcept { return doc->get_root_value_iterator().get_root_uint64(false); }
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
668 template <class T>
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); }
679 #endif
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; }
705 
706 } // namespace ondemand
707 } // namespace SIMDJSON_IMPLEMENTATION
708 } // namespace simdjson
709 
710 
711 
712 namespace simdjson {
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) {}
715 
716 
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();
720 }
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();
724 }
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);
728 }
729 simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::rewind() noexcept {
730  if (error()) { return error(); }
731  first.rewind();
732  return SUCCESS;
733 }
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();
737 }
738 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::end() & noexcept {
739  return {};
740 }
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);
744 }
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);
748 }
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(); }
751  return first[key];
752 }
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(); }
755  return first[key];
756 }
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);
760 }
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);
764 }
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();
768 }
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();
772 }
773 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64() noexcept {
774  if (error()) { return error(); }
775  return first.get_uint64();
776 }
777 simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64_in_string() noexcept {
778  if (error()) { return error(); }
779  return first.get_uint64_in_string();
780 }
781 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64() noexcept {
782  if (error()) { return error(); }
783  return first.get_int64();
784 }
785 simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64_in_string() noexcept {
786  if (error()) { return error(); }
787  return first.get_int64_in_string();
788 }
789 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double() noexcept {
790  if (error()) { return error(); }
791  return first.get_double();
792 }
793 simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double_in_string() noexcept {
794  if (error()) { return error(); }
795  return first.get_double_in_string();
796 }
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);
800 }
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);
805 }
806 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_wobbly_string() noexcept {
807  if (error()) { return error(); }
808  return first.get_wobbly_string();
809 }
810 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_raw_json_string() noexcept {
811  if (error()) { return error(); }
812  return first.get_raw_json_string();
813 }
814 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_bool() noexcept {
815  if (error()) { return error(); }
816  return first.get_bool();
817 }
818 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_value() noexcept {
819  if (error()) { return error(); }
820  return first.get_value();
821 }
822 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_null() noexcept {
823  if (error()) { return error(); }
824  return first.is_null();
825 }
826 template<typename T>
827 simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get() & noexcept {
828  if (error()) { return error(); }
829  return first.get<T>();
830 }
831 template<typename T>
832 simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get() && noexcept {
833  if (error()) { return error(); }
834  return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(first).get<T>();
835 }
836 template <class T>
838  if (error()) { return error(); }
839  return first.get<T>(out);
840 }
841 template <class T>
843  if (error()) { return error(); }
844  return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(first).get<T>(out);
845 }
846 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::type() noexcept {
847  if (error()) { return error(); }
848  return first.type();
849 }
850 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_scalar() noexcept {
851  if (error()) { return error(); }
852  return first.is_scalar();
853 }
854 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_string() noexcept {
855  if (error()) { return error(); }
856  return first.is_string();
857 }
858 template <>
859 simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get(SIMDJSON_IMPLEMENTATION::ondemand::document_reference &out) & noexcept {
860  if (error()) { return error(); }
861  out = first;
862  return SUCCESS;
863 }
864 template <>
865 simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get(SIMDJSON_IMPLEMENTATION::ondemand::document_reference &out) && noexcept {
866  if (error()) { return error(); }
867  out = first;
868  return SUCCESS;
869 }
870 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_negative() noexcept {
871  if (error()) { return error(); }
872  return first.is_negative();
873 }
874 simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_integer() noexcept {
875  if (error()) { return error(); }
876  return first.is_integer();
877 }
878 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number_type() noexcept {
879  if (error()) { return error(); }
880  return first.get_number_type();
881 }
882 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number() noexcept {
883  if (error()) { return error(); }
884  return first.get_number();
885 }
886 #if SIMDJSON_EXCEPTIONS
887 template <class T>
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>();
893 }
894 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) {
895  if (error()) { throw simdjson_error(error()); }
896  return first;
897 }
898 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) {
899  if (error()) { throw simdjson_error(error()); }
900  return first;
901 }
902 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator uint64_t() noexcept(false) {
903  if (error()) { throw simdjson_error(error()); }
904  return first;
905 }
906 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator int64_t() noexcept(false) {
907  if (error()) { throw simdjson_error(error()); }
908  return first;
909 }
910 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator double() noexcept(false) {
911  if (error()) { throw simdjson_error(error()); }
912  return first;
913 }
914 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator std::string_view() noexcept(false) {
915  if (error()) { throw simdjson_error(error()); }
916  return first;
917 }
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()); }
920  return first;
921 }
922 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator bool() noexcept(false) {
923  if (error()) { throw simdjson_error(error()); }
924  return first;
925 }
926 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
927  if (error()) { throw simdjson_error(error()); }
928  return first;
929 }
930 #endif
931 
932 simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::current_location() noexcept {
933  if (error()) { return error(); }
934  return first.current_location();
935 }
936 
938  if (error()) { return error(); }
939  return first.raw_json_token();
940 }
941 
943  if (error()) { return error(); }
944  return first.at_pointer(json_pointer);
945 }
946 
947 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at_path(std::string_view json_path) noexcept {
948  if (error()) {
949  return error();
950  }
951  return first.at_path(json_path);
952 }
953 
954 } // namespace simdjson
955 
956 #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.
Definition: document-inl.h:644
simdjson_inline simdjson_result< value > at(size_t index) &noexcept
Get the value at the given index in the array.
Definition: document-inl.h:218
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
Definition: document-inl.h:45
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
Definition: document-inl.h:222
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
Definition: document-inl.h:211
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
Definition: document-inl.h:140
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
Definition: document-inl.h:296
bool is_alive() noexcept
Some unrecoverable error conditions may render the document instance unusable.
Definition: document-inl.h:54
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
Definition: document-inl.h:153
simdjson_inline simdjson_result< object > get_object() &noexcept
Cast this JSON value to an object.
Definition: document-inl.h:109
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the document is a string.
Definition: document-inl.h:277
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
Definition: document-inl.h:122
simdjson_inline bool is_negative() noexcept
Checks whether the document is a negative number.
Definition: document-inl.h:284
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.
Definition: document-inl.h:301
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to an unsigned integer.
Definition: document-inl.h:125
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
Definition: document-inl.h:156
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
Definition: document-inl.h:128
simdjson_inline simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
Definition: document-inl.h:306
simdjson_inline simdjson_result< json_type > type() noexcept
Get the type of this JSON value.
Definition: document-inl.h:266
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
Definition: document-inl.h:225
simdjson_inline simdjson_result< T > get() &noexcept
Get this value as the given type.
Definition: document.h:185
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
Definition: document-inl.h:137
simdjson_inline simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
Definition: document-inl.h:324
json_iterator iter
Current position in the document.
Definition: document.h:722
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
Definition: document-inl.h:134
std::string to_debug_string() noexcept
Returns debugging information.
Definition: document-inl.h:37
void rewind() noexcept
Reset the iterator inside the document instance so we are pointing back at the beginning of the docum...
Definition: document-inl.h:33
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...
Definition: document-inl.h:254
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.
Definition: document-inl.h:235
simdjson_inline simdjson_result< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
Definition: document-inl.h:131
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
Definition: document-inl.h:204
simdjson_inline simdjson_result< value > get_value() noexcept
Cast this JSON value to a value when the document is an object or an array.
Definition: document-inl.h:70
simdjson_inline simdjson_result< value > find_field(std::string_view key) &noexcept
Look up a field by name on an object (order-sensitive).
Definition: document-inl.h:229
simdjson_inline simdjson_result< number_type > get_number_type() noexcept
Determine the number type (integer or floating-point number) as quickly as possible.
Definition: document-inl.h:292
simdjson_inline error_code consume() noexcept
Consumes the document.
Definition: document-inl.h:248
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the document is a scalar (string, number, null, Boolean).
Definition: document-inl.h:270
simdjson_inline simdjson_result< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a string.
Definition: document-inl.h:147
bool at_end() const noexcept
Returns true if this document has been fully parsed.
Definition: document-inl.h:49
simdjson_inline simdjson_result< array > get_array() &noexcept
Cast this JSON value to an array.
Definition: document-inl.h:105
simdjson_inline simdjson_result< bool > is_integer() noexcept
Checks whether the document is an integer number.
Definition: document-inl.h:288
simdjson_result< const char * > current_location() const noexcept
Returns the current location in the document if in bounds.
Definition: document-inl.h:41
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
Definition: document-inl.h:150
A forward-only JSON object field iterator.
Definition: object.h:17
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
Definition: value.h:21
json_type
The type of a JSON value.
Definition: json_type.h:17
@ 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
@ 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:215
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:131
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
Definition: error-inl.h:126