1namespace simdjson {
2namespace SIMDJSON_IMPLEMENTATION {
3namespace ondemand {
4
5simdjson_inline document::document(ondemand::json_iterator &&_iter) noexcept
6 : iter{std::forward<json_iterator>(t&: _iter)}
7{
8 logger::log_start_value(iter, type: "document");
9}
10
11simdjson_inline document document::start(json_iterator &&iter) noexcept {
12 return document(std::forward<json_iterator>(t&: iter));
13}
14
15inline void document::rewind() noexcept {
16 iter.rewind();
17}
18
19inline std::string document::to_debug_string() noexcept {
20 return iter.to_string();
21}
22
23inline simdjson_result<const char *> document::current_location() noexcept {
24 return iter.current_location();
25}
26
27inline int32_t document::current_depth() const noexcept {
28 return iter.depth();
29}
30
31inline bool document::is_alive() noexcept {
32 return iter.is_alive();
33}
34simdjson_inline value_iterator document::resume_value_iterator() noexcept {
35 return value_iterator(&iter, 1, iter.root_position());
36}
37simdjson_inline value_iterator document::get_root_value_iterator() noexcept {
38 return resume_value_iterator();
39}
40simdjson_inline simdjson_result<object> document::start_or_resume_object() noexcept {
41 if (iter.at_root()) {
42 return get_object();
43 } else {
44 return object::resume(iter: resume_value_iterator());
45 }
46}
47simdjson_inline simdjson_result<value> document::get_value() noexcept {
48 // Make sure we start any arrays or objects before returning, so that start_root_<object/array>()
49 // gets called.
50 iter.assert_at_document_depth();
51 switch (*iter.peek()) {
52 case '[':
53 case '{':
54 return value(get_root_value_iterator());
55 default:
56 // Unfortunately, scalar documents are a special case in simdjson and they cannot
57 // be safely converted to value instances.
58 return SCALAR_DOCUMENT_AS_VALUE;
59 // return value(get_root_value_iterator());
60 }
61}
62simdjson_inline simdjson_result<array> document::get_array() & noexcept {
63 auto value = get_root_value_iterator();
64 return array::start_root(iter&: value);
65}
66simdjson_inline simdjson_result<object> document::get_object() & noexcept {
67 auto value = get_root_value_iterator();
68 return object::start_root(iter&: value);
69}
70
71/**
72 * We decided that calling 'get_double()' on the JSON document '1.233 blabla' should
73 * give an error, so we check for trailing content. We want to disallow trailing
74 * content.
75 * Thus, in several implementations below, we pass a 'true' parameter value to
76 * a get_root_value_iterator() method: this indicates that we disallow trailing content.
77 */
78
79simdjson_inline simdjson_result<uint64_t> document::get_uint64() noexcept {
80 return get_root_value_iterator().get_root_uint64(check_trailing: true);
81}
82simdjson_inline simdjson_result<uint64_t> document::get_uint64_in_string() noexcept {
83 return get_root_value_iterator().get_root_uint64_in_string(check_trailing: true);
84}
85simdjson_inline simdjson_result<int64_t> document::get_int64() noexcept {
86 return get_root_value_iterator().get_root_int64(check_trailing: true);
87}
88simdjson_inline simdjson_result<int64_t> document::get_int64_in_string() noexcept {
89 return get_root_value_iterator().get_root_int64_in_string(check_trailing: true);
90}
91simdjson_inline simdjson_result<double> document::get_double() noexcept {
92 return get_root_value_iterator().get_root_double(check_trailing: true);
93}
94simdjson_inline simdjson_result<double> document::get_double_in_string() noexcept {
95 return get_root_value_iterator().get_root_double_in_string(check_trailing: true);
96}
97simdjson_inline simdjson_result<std::string_view> document::get_string(bool allow_replacement) noexcept {
98 return get_root_value_iterator().get_root_string(check_trailing: true, allow_replacement);
99}
100simdjson_inline simdjson_result<std::string_view> document::get_wobbly_string() noexcept {
101 return get_root_value_iterator().get_root_wobbly_string(check_trailing: true);
102}
103simdjson_inline simdjson_result<raw_json_string> document::get_raw_json_string() noexcept {
104 return get_root_value_iterator().get_root_raw_json_string(check_trailing: true);
105}
106simdjson_inline simdjson_result<bool> document::get_bool() noexcept {
107 return get_root_value_iterator().get_root_bool(check_trailing: true);
108}
109simdjson_inline simdjson_result<bool> document::is_null() noexcept {
110 return get_root_value_iterator().is_root_null(check_trailing: true);
111}
112
113template<> simdjson_inline simdjson_result<array> document::get() & noexcept { return get_array(); }
114template<> simdjson_inline simdjson_result<object> document::get() & noexcept { return get_object(); }
115template<> simdjson_inline simdjson_result<raw_json_string> document::get() & noexcept { return get_raw_json_string(); }
116template<> simdjson_inline simdjson_result<std::string_view> document::get() & noexcept { return get_string(allow_replacement: false); }
117template<> simdjson_inline simdjson_result<double> document::get() & noexcept { return get_double(); }
118template<> simdjson_inline simdjson_result<uint64_t> document::get() & noexcept { return get_uint64(); }
119template<> simdjson_inline simdjson_result<int64_t> document::get() & noexcept { return get_int64(); }
120template<> simdjson_inline simdjson_result<bool> document::get() & noexcept { return get_bool(); }
121template<> simdjson_inline simdjson_result<value> document::get() & noexcept { return get_value(); }
122
123template<> simdjson_inline simdjson_result<raw_json_string> document::get() && noexcept { return get_raw_json_string(); }
124template<> simdjson_inline simdjson_result<std::string_view> document::get() && noexcept { return get_string(allow_replacement: false); }
125template<> simdjson_inline simdjson_result<double> document::get() && noexcept { return std::forward<document>(t&: *this).get_double(); }
126template<> simdjson_inline simdjson_result<uint64_t> document::get() && noexcept { return std::forward<document>(t&: *this).get_uint64(); }
127template<> simdjson_inline simdjson_result<int64_t> document::get() && noexcept { return std::forward<document>(t&: *this).get_int64(); }
128template<> simdjson_inline simdjson_result<bool> document::get() && noexcept { return std::forward<document>(t&: *this).get_bool(); }
129template<> simdjson_inline simdjson_result<value> document::get() && noexcept { return get_value(); }
130
131template<typename T> simdjson_inline error_code document::get(T &out) & noexcept {
132 return get<T>().get(out);
133}
134template<typename T> simdjson_inline error_code document::get(T &out) && noexcept {
135 return std::forward<document>(t&: *this).get<T>().get(out);
136}
137
138#if SIMDJSON_EXCEPTIONS
139simdjson_inline document::operator array() & noexcept(false) { return get_array(); }
140simdjson_inline document::operator object() & noexcept(false) { return get_object(); }
141simdjson_inline document::operator uint64_t() noexcept(false) { return get_uint64(); }
142simdjson_inline document::operator int64_t() noexcept(false) { return get_int64(); }
143simdjson_inline document::operator double() noexcept(false) { return get_double(); }
144simdjson_inline document::operator std::string_view() noexcept(false) { return get_string(allow_replacement: false); }
145simdjson_inline document::operator raw_json_string() noexcept(false) { return get_raw_json_string(); }
146simdjson_inline document::operator bool() noexcept(false) { return get_bool(); }
147simdjson_inline document::operator value() noexcept(false) { return get_value(); }
148
149#endif
150simdjson_inline simdjson_result<size_t> document::count_elements() & noexcept {
151 auto a = get_array();
152 simdjson_result<size_t> answer = a.count_elements();
153 /* If there was an array, we are now left pointing at its first element. */
154 if(answer.error() == SUCCESS) { rewind(); }
155 return answer;
156}
157simdjson_inline simdjson_result<size_t> document::count_fields() & noexcept {
158 auto a = get_object();
159 simdjson_result<size_t> answer = a.count_fields();
160 /* If there was an object, we are now left pointing at its first element. */
161 if(answer.error() == SUCCESS) { rewind(); }
162 return answer;
163}
164simdjson_inline simdjson_result<value> document::at(size_t index) & noexcept {
165 auto a = get_array();
166 return a.at(index);
167}
168simdjson_inline simdjson_result<array_iterator> document::begin() & noexcept {
169 return get_array().begin();
170}
171simdjson_inline simdjson_result<array_iterator> document::end() & noexcept {
172 return {};
173}
174
175simdjson_inline simdjson_result<value> document::find_field(std::string_view key) & noexcept {
176 return start_or_resume_object().find_field(key);
177}
178simdjson_inline simdjson_result<value> document::find_field(const char *key) & noexcept {
179 return start_or_resume_object().find_field(key);
180}
181simdjson_inline simdjson_result<value> document::find_field_unordered(std::string_view key) & noexcept {
182 return start_or_resume_object().find_field_unordered(key);
183}
184simdjson_inline simdjson_result<value> document::find_field_unordered(const char *key) & noexcept {
185 return start_or_resume_object().find_field_unordered(key);
186}
187simdjson_inline simdjson_result<value> document::operator[](std::string_view key) & noexcept {
188 return start_or_resume_object()[key];
189}
190simdjson_inline simdjson_result<value> document::operator[](const char *key) & noexcept {
191 return start_or_resume_object()[key];
192}
193
194simdjson_inline error_code document::consume() noexcept {
195 auto error = iter.skip_child(parent_depth: 0);
196 if(error) { iter.abandon(); }
197 return error;
198}
199
200simdjson_inline simdjson_result<std::string_view> document::raw_json() noexcept {
201 auto _iter = get_root_value_iterator();
202 const uint8_t * starting_point{_iter.peek_start()};
203 auto error = consume();
204 if(error) { return error; }
205 // After 'consume()', we could be left pointing just beyond the document, but that
206 // is ok because we are not going to dereference the final pointer position, we just
207 // use it to compute the length in bytes.
208 const uint8_t * final_point{iter.unsafe_pointer()};
209 return std::string_view(reinterpret_cast<const char*>(starting_point), size_t(final_point - starting_point));
210}
211
212simdjson_inline simdjson_result<json_type> document::type() noexcept {
213 return get_root_value_iterator().type();
214}
215
216simdjson_inline simdjson_result<bool> document::is_scalar() noexcept {
217 json_type this_type;
218 auto error = type().get(value&: this_type);
219 if(error) { return error; }
220 return ! ((this_type == json_type::array) || (this_type == json_type::object));
221}
222
223simdjson_inline bool document::is_negative() noexcept {
224 return get_root_value_iterator().is_root_negative();
225}
226
227simdjson_inline simdjson_result<bool> document::is_integer() noexcept {
228 return get_root_value_iterator().is_root_integer(check_trailing: true);
229}
230
231simdjson_inline simdjson_result<number_type> document::get_number_type() noexcept {
232 return get_root_value_iterator().get_root_number_type(check_trailing: true);
233}
234
235simdjson_inline simdjson_result<number> document::get_number() noexcept {
236 return get_root_value_iterator().get_root_number(check_trailing: true);
237}
238
239
240simdjson_inline simdjson_result<std::string_view> document::raw_json_token() noexcept {
241 auto _iter = get_root_value_iterator();
242 return std::string_view(reinterpret_cast<const char*>(_iter.peek_start()), _iter.peek_start_length());
243}
244
245simdjson_inline simdjson_result<value> document::at_pointer(std::string_view json_pointer) noexcept {
246 rewind(); // Rewind the document each time at_pointer is called
247 if (json_pointer.empty()) {
248 return this->get_value();
249 }
250 json_type t;
251 SIMDJSON_TRY(type().get(t));
252 switch (t)
253 {
254 case json_type::array:
255 return (*this).get_array().at_pointer(json_pointer);
256 case json_type::object:
257 return (*this).get_object().at_pointer(json_pointer);
258 default:
259 return INVALID_JSON_POINTER;
260 }
261}
262
263} // namespace ondemand
264} // namespace SIMDJSON_IMPLEMENTATION
265} // namespace simdjson
266
267namespace simdjson {
268
269simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
270 SIMDJSON_IMPLEMENTATION::ondemand::document &&value
271) noexcept :
272 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
273 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(t&: value)
274 )
275{
276}
277simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::simdjson_result(
278 error_code error
279) noexcept :
280 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>(
281 error
282 )
283{
284}
285simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::count_elements() & noexcept {
286 if (error()) { return error(); }
287 return first.count_elements();
288}
289simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::count_fields() & noexcept {
290 if (error()) { return error(); }
291 return first.count_fields();
292}
293simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at(size_t index) & noexcept {
294 if (error()) { return error(); }
295 return first.at(index);
296}
297simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::rewind() noexcept {
298 if (error()) { return error(); }
299 first.rewind();
300 return SUCCESS;
301}
302simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::begin() & noexcept {
303 if (error()) { return error(); }
304 return first.begin();
305}
306simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::end() & noexcept {
307 return {};
308}
309simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field_unordered(std::string_view key) & noexcept {
310 if (error()) { return error(); }
311 return first.find_field_unordered(key);
312}
313simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field_unordered(const char *key) & noexcept {
314 if (error()) { return error(); }
315 return first.find_field_unordered(key);
316}
317simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator[](std::string_view key) & noexcept {
318 if (error()) { return error(); }
319 return first[key];
320}
321simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator[](const char *key) & noexcept {
322 if (error()) { return error(); }
323 return first[key];
324}
325simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field(std::string_view key) & noexcept {
326 if (error()) { return error(); }
327 return first.find_field(key);
328}
329simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::find_field(const char *key) & noexcept {
330 if (error()) { return error(); }
331 return first.find_field(key);
332}
333simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_array() & noexcept {
334 if (error()) { return error(); }
335 return first.get_array();
336}
337simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_object() & noexcept {
338 if (error()) { return error(); }
339 return first.get_object();
340}
341simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64() noexcept {
342 if (error()) { return error(); }
343 return first.get_uint64();
344}
345simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_uint64_in_string() noexcept {
346 if (error()) { return error(); }
347 return first.get_uint64_in_string();
348}
349simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64() noexcept {
350 if (error()) { return error(); }
351 return first.get_int64();
352}
353simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_int64_in_string() noexcept {
354 if (error()) { return error(); }
355 return first.get_int64_in_string();
356}
357simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double() noexcept {
358 if (error()) { return error(); }
359 return first.get_double();
360}
361simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_double_in_string() noexcept {
362 if (error()) { return error(); }
363 return first.get_double_in_string();
364}
365simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_string(bool allow_replacement) noexcept {
366 if (error()) { return error(); }
367 return first.get_string(allow_replacement);
368}
369simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_wobbly_string() noexcept {
370 if (error()) { return error(); }
371 return first.get_wobbly_string();
372}
373simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_raw_json_string() noexcept {
374 if (error()) { return error(); }
375 return first.get_raw_json_string();
376}
377simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_bool() noexcept {
378 if (error()) { return error(); }
379 return first.get_bool();
380}
381simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_value() noexcept {
382 if (error()) { return error(); }
383 return first.get_value();
384}
385simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_null() noexcept {
386 if (error()) { return error(); }
387 return first.is_null();
388}
389
390template<typename T>
391simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get() & noexcept {
392 if (error()) { return error(); }
393 return first.get<T>();
394}
395template<typename T>
396simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get() && noexcept {
397 if (error()) { return error(); }
398 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(t&: first).get<T>();
399}
400template<typename T>
401simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get(T &out) & noexcept {
402 if (error()) { return error(); }
403 return first.get<T>(out);
404}
405template<typename T>
406simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get(T &out) && noexcept {
407 if (error()) { return error(); }
408 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(t&: first).get<T>(out);
409}
410
411template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() & noexcept = delete;
412template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() && noexcept {
413 if (error()) { return error(); }
414 return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(t&: first);
415}
416template<> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) & noexcept = delete;
417template<> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) && noexcept {
418 if (error()) { return error(); }
419 out = std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(t&: first);
420 return SUCCESS;
421}
422
423simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::type() noexcept {
424 if (error()) { return error(); }
425 return first.type();
426}
427
428simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_scalar() noexcept {
429 if (error()) { return error(); }
430 return first.is_scalar();
431}
432
433
434simdjson_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_negative() noexcept {
435 if (error()) { return error(); }
436 return first.is_negative();
437}
438
439simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::is_integer() noexcept {
440 if (error()) { return error(); }
441 return first.is_integer();
442}
443
444simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number_type() noexcept {
445 if (error()) { return error(); }
446 return first.get_number_type();
447}
448
449simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_number() noexcept {
450 if (error()) { return error(); }
451 return first.get_number();
452}
453
454
455#if SIMDJSON_EXCEPTIONS
456simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) {
457 if (error()) { throw simdjson_error(error()); }
458 return first;
459}
460simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) {
461 if (error()) { throw simdjson_error(error()); }
462 return first;
463}
464simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator uint64_t() noexcept(false) {
465 if (error()) { throw simdjson_error(error()); }
466 return first;
467}
468simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator int64_t() noexcept(false) {
469 if (error()) { throw simdjson_error(error()); }
470 return first;
471}
472simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator double() noexcept(false) {
473 if (error()) { throw simdjson_error(error()); }
474 return first;
475}
476simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator std::string_view() noexcept(false) {
477 if (error()) { throw simdjson_error(error()); }
478 return first;
479}
480simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
481 if (error()) { throw simdjson_error(error()); }
482 return first;
483}
484simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator bool() noexcept(false) {
485 if (error()) { throw simdjson_error(error()); }
486 return first;
487}
488simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
489 if (error()) { throw simdjson_error(error()); }
490 return first;
491}
492#endif
493
494
495simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_location() noexcept {
496 if (error()) { return error(); }
497 return first.current_location();
498}
499
500simdjson_inline int32_t simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::current_depth() const noexcept {
501 if (error()) { return error(); }
502 return first.current_depth();
503}
504
505simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::raw_json_token() noexcept {
506 if (error()) { return error(); }
507 return first.raw_json_token();
508}
509
510simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_pointer(std::string_view json_pointer) noexcept {
511 if (error()) { return error(); }
512 return first.at_pointer(json_pointer);
513}
514
515
516} // namespace simdjson
517
518
519namespace simdjson {
520namespace SIMDJSON_IMPLEMENTATION {
521namespace ondemand {
522
523simdjson_inline document_reference::document_reference() noexcept : doc{nullptr} {}
524simdjson_inline document_reference::document_reference(document &d) noexcept : doc(&d) {}
525simdjson_inline void document_reference::rewind() noexcept { doc->rewind(); }
526simdjson_inline simdjson_result<array> document_reference::get_array() & noexcept { return doc->get_array(); }
527simdjson_inline simdjson_result<object> document_reference::get_object() & noexcept { return doc->get_object(); }
528/**
529 * The document_reference instances are used primarily/solely for streams of JSON
530 * documents.
531 * We decided that calling 'get_double()' on the JSON document '1.233 blabla' should
532 * give an error, so we check for trailing content.
533 *
534 * However, for streams of JSON documents, we want to be able to start from
535 * "321" "321" "321"
536 * and parse it successfully as a stream of JSON documents, calling get_uint64_in_string()
537 * successfully each time.
538 *
539 * To achieve this result, we pass a 'false' to a get_root_value_iterator() method:
540 * this indicates that we allow trailing content.
541 */
542simdjson_inline simdjson_result<uint64_t> document_reference::get_uint64() noexcept { return doc->get_root_value_iterator().get_root_uint64(check_trailing: false); }
543simdjson_inline simdjson_result<uint64_t> document_reference::get_uint64_in_string() noexcept { return doc->get_root_value_iterator().get_root_uint64_in_string(check_trailing: false); }
544simdjson_inline simdjson_result<int64_t> document_reference::get_int64() noexcept { return doc->get_root_value_iterator().get_root_int64(check_trailing: false); }
545simdjson_inline simdjson_result<int64_t> document_reference::get_int64_in_string() noexcept { return doc->get_root_value_iterator().get_root_int64_in_string(check_trailing: false); }
546simdjson_inline simdjson_result<double> document_reference::get_double() noexcept { return doc->get_root_value_iterator().get_root_double(check_trailing: false); }
547simdjson_inline simdjson_result<double> document_reference::get_double_in_string() noexcept { return doc->get_root_value_iterator().get_root_double(check_trailing: false); }
548simdjson_inline simdjson_result<std::string_view> document_reference::get_string(bool allow_replacement) noexcept { return doc->get_root_value_iterator().get_root_string(check_trailing: false, allow_replacement); }
549simdjson_inline simdjson_result<std::string_view> document_reference::get_wobbly_string() noexcept { return doc->get_root_value_iterator().get_root_wobbly_string(check_trailing: false); }
550simdjson_inline simdjson_result<raw_json_string> document_reference::get_raw_json_string() noexcept { return doc->get_root_value_iterator().get_root_raw_json_string(check_trailing: false); }
551simdjson_inline simdjson_result<bool> document_reference::get_bool() noexcept { return doc->get_root_value_iterator().get_root_bool(check_trailing: false); }
552simdjson_inline simdjson_result<value> document_reference::get_value() noexcept { return doc->get_value(); }
553simdjson_inline simdjson_result<bool> document_reference::is_null() noexcept { return doc->get_root_value_iterator().is_root_null(check_trailing: false); }
554
555#if SIMDJSON_EXCEPTIONS
556simdjson_inline document_reference::operator array() & noexcept(false) { return array(*doc); }
557simdjson_inline document_reference::operator object() & noexcept(false) { return object(*doc); }
558simdjson_inline document_reference::operator uint64_t() noexcept(false) { return get_uint64(); }
559simdjson_inline document_reference::operator int64_t() noexcept(false) { return get_int64(); }
560simdjson_inline document_reference::operator double() noexcept(false) { return get_double(); }
561simdjson_inline document_reference::operator std::string_view() noexcept(false) { return std::string_view(*doc); }
562simdjson_inline document_reference::operator raw_json_string() noexcept(false) { return raw_json_string(*doc); }
563simdjson_inline document_reference::operator bool() noexcept(false) { return get_bool(); }
564simdjson_inline document_reference::operator value() noexcept(false) { return value(*doc); }
565#endif
566simdjson_inline simdjson_result<size_t> document_reference::count_elements() & noexcept { return doc->count_elements(); }
567simdjson_inline simdjson_result<size_t> document_reference::count_fields() & noexcept { return doc->count_fields(); }
568simdjson_inline simdjson_result<value> document_reference::at(size_t index) & noexcept { return doc->at(index); }
569simdjson_inline simdjson_result<array_iterator> document_reference::begin() & noexcept { return doc->begin(); }
570simdjson_inline simdjson_result<array_iterator> document_reference::end() & noexcept { return doc->end(); }
571simdjson_inline simdjson_result<value> document_reference::find_field(std::string_view key) & noexcept { return doc->find_field(key); }
572simdjson_inline simdjson_result<value> document_reference::find_field(const char *key) & noexcept { return doc->find_field(key); }
573simdjson_inline simdjson_result<value> document_reference::operator[](std::string_view key) & noexcept { return (*doc)[key]; }
574simdjson_inline simdjson_result<value> document_reference::operator[](const char *key) & noexcept { return (*doc)[key]; }
575simdjson_inline simdjson_result<value> document_reference::find_field_unordered(std::string_view key) & noexcept { return doc->find_field_unordered(key); }
576simdjson_inline simdjson_result<value> document_reference::find_field_unordered(const char *key) & noexcept { return doc->find_field_unordered(key); }
577simdjson_inline simdjson_result<json_type> document_reference::type() noexcept { return doc->type(); }
578simdjson_inline simdjson_result<bool> document_reference::is_scalar() noexcept { return doc->is_scalar(); }
579simdjson_inline simdjson_result<const char *> document_reference::current_location() noexcept { return doc->current_location(); }
580simdjson_inline int32_t document_reference::current_depth() const noexcept { return doc->current_depth(); }
581simdjson_inline bool document_reference::is_negative() noexcept { return doc->is_negative(); }
582simdjson_inline simdjson_result<bool> document_reference::is_integer() noexcept { return doc->get_root_value_iterator().is_root_integer(check_trailing: false); }
583simdjson_inline simdjson_result<number_type> document_reference::get_number_type() noexcept { return doc->get_root_value_iterator().get_root_number_type(check_trailing: false); }
584simdjson_inline simdjson_result<number> document_reference::get_number() noexcept { return doc->get_root_value_iterator().get_root_number(check_trailing: false); }
585simdjson_inline simdjson_result<std::string_view> document_reference::raw_json_token() noexcept { return doc->raw_json_token(); }
586simdjson_inline simdjson_result<value> document_reference::at_pointer(std::string_view json_pointer) noexcept { return doc->at_pointer(json_pointer); }
587simdjson_inline simdjson_result<std::string_view> document_reference::raw_json() noexcept { return doc->raw_json();}
588simdjson_inline document_reference::operator document&() const noexcept { return *doc; }
589
590} // namespace ondemand
591} // namespace SIMDJSON_IMPLEMENTATION
592} // namespace simdjson
593
594
595
596namespace simdjson {
597simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::document_reference value, error_code error)
598 noexcept : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>(t&: value), error) {}
599
600
601simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::count_elements() & noexcept {
602 if (error()) { return error(); }
603 return first.count_elements();
604}
605simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::count_fields() & noexcept {
606 if (error()) { return error(); }
607 return first.count_fields();
608}
609simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at(size_t index) & noexcept {
610 if (error()) { return error(); }
611 return first.at(index);
612}
613simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::rewind() noexcept {
614 if (error()) { return error(); }
615 first.rewind();
616 return SUCCESS;
617}
618simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::begin() & noexcept {
619 if (error()) { return error(); }
620 return first.begin();
621}
622simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::end() & noexcept {
623 return {};
624}
625simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field_unordered(std::string_view key) & noexcept {
626 if (error()) { return error(); }
627 return first.find_field_unordered(key);
628}
629simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field_unordered(const char *key) & noexcept {
630 if (error()) { return error(); }
631 return first.find_field_unordered(key);
632}
633simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator[](std::string_view key) & noexcept {
634 if (error()) { return error(); }
635 return first[key];
636}
637simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator[](const char *key) & noexcept {
638 if (error()) { return error(); }
639 return first[key];
640}
641simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field(std::string_view key) & noexcept {
642 if (error()) { return error(); }
643 return first.find_field(key);
644}
645simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::find_field(const char *key) & noexcept {
646 if (error()) { return error(); }
647 return first.find_field(key);
648}
649simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_array() & noexcept {
650 if (error()) { return error(); }
651 return first.get_array();
652}
653simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_object() & noexcept {
654 if (error()) { return error(); }
655 return first.get_object();
656}
657simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64() noexcept {
658 if (error()) { return error(); }
659 return first.get_uint64();
660}
661simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_uint64_in_string() noexcept {
662 if (error()) { return error(); }
663 return first.get_uint64_in_string();
664}
665simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64() noexcept {
666 if (error()) { return error(); }
667 return first.get_int64();
668}
669simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_int64_in_string() noexcept {
670 if (error()) { return error(); }
671 return first.get_int64_in_string();
672}
673simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double() noexcept {
674 if (error()) { return error(); }
675 return first.get_double();
676}
677simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_double_in_string() noexcept {
678 if (error()) { return error(); }
679 return first.get_double_in_string();
680}
681simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_string(bool allow_replacement) noexcept {
682 if (error()) { return error(); }
683 return first.get_string(allow_replacement);
684}
685simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_wobbly_string() noexcept {
686 if (error()) { return error(); }
687 return first.get_wobbly_string();
688}
689simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_raw_json_string() noexcept {
690 if (error()) { return error(); }
691 return first.get_raw_json_string();
692}
693simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_bool() noexcept {
694 if (error()) { return error(); }
695 return first.get_bool();
696}
697simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_value() noexcept {
698 if (error()) { return error(); }
699 return first.get_value();
700}
701simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_null() noexcept {
702 if (error()) { return error(); }
703 return first.is_null();
704}
705simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::type() noexcept {
706 if (error()) { return error(); }
707 return first.type();
708}
709simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_scalar() noexcept {
710 if (error()) { return error(); }
711 return first.is_scalar();
712}
713simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_negative() noexcept {
714 if (error()) { return error(); }
715 return first.is_negative();
716}
717simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::is_integer() noexcept {
718 if (error()) { return error(); }
719 return first.is_integer();
720}
721simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number_type() noexcept {
722 if (error()) { return error(); }
723 return first.get_number_type();
724}
725simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_number() noexcept {
726 if (error()) { return error(); }
727 return first.get_number();
728}
729#if SIMDJSON_EXCEPTIONS
730simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) {
731 if (error()) { throw simdjson_error(error()); }
732 return first;
733}
734simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) {
735 if (error()) { throw simdjson_error(error()); }
736 return first;
737}
738simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator uint64_t() noexcept(false) {
739 if (error()) { throw simdjson_error(error()); }
740 return first;
741}
742simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator int64_t() noexcept(false) {
743 if (error()) { throw simdjson_error(error()); }
744 return first;
745}
746simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator double() noexcept(false) {
747 if (error()) { throw simdjson_error(error()); }
748 return first;
749}
750simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator std::string_view() noexcept(false) {
751 if (error()) { throw simdjson_error(error()); }
752 return first;
753}
754simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
755 if (error()) { throw simdjson_error(error()); }
756 return first;
757}
758simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator bool() noexcept(false) {
759 if (error()) { throw simdjson_error(error()); }
760 return first;
761}
762simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::operator SIMDJSON_IMPLEMENTATION::ondemand::value() noexcept(false) {
763 if (error()) { throw simdjson_error(error()); }
764 return first;
765}
766#endif
767
768simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::current_location() noexcept {
769 if (error()) { return error(); }
770 return first.current_location();
771}
772
773simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::raw_json_token() noexcept {
774 if (error()) { return error(); }
775 return first.raw_json_token();
776}
777
778simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at_pointer(std::string_view json_pointer) noexcept {
779 if (error()) { return error(); }
780 return first.at_pointer(json_pointer);
781}
782
783
784} // namespace simdjson
785