1namespace simdjson {
2namespace SIMDJSON_IMPLEMENTATION {
3namespace ondemand {
4
5simdjson_inline value::value(const value_iterator &_iter) noexcept
6 : iter{_iter}
7{
8}
9simdjson_inline value value::start(const value_iterator &iter) noexcept {
10 return iter;
11}
12simdjson_inline value value::resume(const value_iterator &iter) noexcept {
13 return iter;
14}
15
16simdjson_inline simdjson_result<array> value::get_array() noexcept {
17 return array::start(iter);
18}
19simdjson_inline simdjson_result<object> value::get_object() noexcept {
20 return object::start(iter);
21}
22simdjson_inline simdjson_result<object> value::start_or_resume_object() noexcept {
23 if (iter.at_start()) {
24 return get_object();
25 } else {
26 return object::resume(iter);
27 }
28}
29
30simdjson_inline simdjson_result<raw_json_string> value::get_raw_json_string() noexcept {
31 return iter.get_raw_json_string();
32}
33simdjson_inline simdjson_result<std::string_view> value::get_string(bool allow_replacement) noexcept {
34 return iter.get_string(allow_replacement);
35}
36simdjson_inline simdjson_result<std::string_view> value::get_wobbly_string() noexcept {
37 return iter.get_wobbly_string();
38}
39simdjson_inline simdjson_result<double> value::get_double() noexcept {
40 return iter.get_double();
41}
42simdjson_inline simdjson_result<double> value::get_double_in_string() noexcept {
43 return iter.get_double_in_string();
44}
45simdjson_inline simdjson_result<uint64_t> value::get_uint64() noexcept {
46 return iter.get_uint64();
47}
48simdjson_inline simdjson_result<uint64_t> value::get_uint64_in_string() noexcept {
49 return iter.get_uint64_in_string();
50}
51simdjson_inline simdjson_result<int64_t> value::get_int64() noexcept {
52 return iter.get_int64();
53}
54simdjson_inline simdjson_result<int64_t> value::get_int64_in_string() noexcept {
55 return iter.get_int64_in_string();
56}
57simdjson_inline simdjson_result<bool> value::get_bool() noexcept {
58 return iter.get_bool();
59}
60simdjson_inline simdjson_result<bool> value::is_null() noexcept {
61 return iter.is_null();
62}
63template<> simdjson_inline simdjson_result<array> value::get() noexcept { return get_array(); }
64template<> simdjson_inline simdjson_result<object> value::get() noexcept { return get_object(); }
65template<> simdjson_inline simdjson_result<raw_json_string> value::get() noexcept { return get_raw_json_string(); }
66template<> simdjson_inline simdjson_result<std::string_view> value::get() noexcept { return get_string(allow_replacement: false); }
67template<> simdjson_inline simdjson_result<number> value::get() noexcept { return get_number(); }
68template<> simdjson_inline simdjson_result<double> value::get() noexcept { return get_double(); }
69template<> simdjson_inline simdjson_result<uint64_t> value::get() noexcept { return get_uint64(); }
70template<> simdjson_inline simdjson_result<int64_t> value::get() noexcept { return get_int64(); }
71template<> simdjson_inline simdjson_result<bool> value::get() noexcept { return get_bool(); }
72
73template<typename T> simdjson_inline error_code value::get(T &out) noexcept {
74 return get<T>().get(out);
75}
76
77#if SIMDJSON_EXCEPTIONS
78simdjson_inline value::operator array() noexcept(false) {
79 return get_array();
80}
81simdjson_inline value::operator object() noexcept(false) {
82 return get_object();
83}
84simdjson_inline value::operator uint64_t() noexcept(false) {
85 return get_uint64();
86}
87simdjson_inline value::operator int64_t() noexcept(false) {
88 return get_int64();
89}
90simdjson_inline value::operator double() noexcept(false) {
91 return get_double();
92}
93simdjson_inline value::operator std::string_view() noexcept(false) {
94 return get_string(allow_replacement: false);
95}
96simdjson_inline value::operator raw_json_string() noexcept(false) {
97 return get_raw_json_string();
98}
99simdjson_inline value::operator bool() noexcept(false) {
100 return get_bool();
101}
102#endif
103
104simdjson_inline simdjson_result<array_iterator> value::begin() & noexcept {
105 return get_array().begin();
106}
107simdjson_inline simdjson_result<array_iterator> value::end() & noexcept {
108 return {};
109}
110simdjson_inline simdjson_result<size_t> value::count_elements() & noexcept {
111 simdjson_result<size_t> answer;
112 auto a = get_array();
113 answer = a.count_elements();
114 // count_elements leaves you pointing inside the array, at the first element.
115 // We need to move back so that the user can create a new array (which requires that
116 // we point at '[').
117 iter.move_at_start();
118 return answer;
119}
120simdjson_inline simdjson_result<size_t> value::count_fields() & noexcept {
121 simdjson_result<size_t> answer;
122 auto a = get_object();
123 answer = a.count_fields();
124 iter.move_at_start();
125 return answer;
126}
127simdjson_inline simdjson_result<value> value::at(size_t index) noexcept {
128 auto a = get_array();
129 return a.at(index);
130}
131
132simdjson_inline simdjson_result<value> value::find_field(std::string_view key) noexcept {
133 return start_or_resume_object().find_field(key);
134}
135simdjson_inline simdjson_result<value> value::find_field(const char *key) noexcept {
136 return start_or_resume_object().find_field(key);
137}
138
139simdjson_inline simdjson_result<value> value::find_field_unordered(std::string_view key) noexcept {
140 return start_or_resume_object().find_field_unordered(key);
141}
142simdjson_inline simdjson_result<value> value::find_field_unordered(const char *key) noexcept {
143 return start_or_resume_object().find_field_unordered(key);
144}
145
146simdjson_inline simdjson_result<value> value::operator[](std::string_view key) noexcept {
147 return start_or_resume_object()[key];
148}
149simdjson_inline simdjson_result<value> value::operator[](const char *key) noexcept {
150 return start_or_resume_object()[key];
151}
152
153simdjson_inline simdjson_result<json_type> value::type() noexcept {
154 return iter.type();
155}
156
157simdjson_inline simdjson_result<bool> value::is_scalar() noexcept {
158 json_type this_type;
159 auto error = type().get(value&: this_type);
160 if(error) { return error; }
161 return ! ((this_type == json_type::array) || (this_type == json_type::object));
162}
163
164simdjson_inline bool value::is_negative() noexcept {
165 return iter.is_negative();
166}
167
168simdjson_inline simdjson_result<bool> value::is_integer() noexcept {
169 return iter.is_integer();
170}
171simdjson_warn_unused simdjson_inline simdjson_result<number_type> value::get_number_type() noexcept {
172 return iter.get_number_type();
173}
174simdjson_warn_unused simdjson_inline simdjson_result<number> value::get_number() noexcept {
175 return iter.get_number();
176}
177
178simdjson_inline std::string_view value::raw_json_token() noexcept {
179 return std::string_view(reinterpret_cast<const char*>(iter.peek_start()), iter.peek_start_length());
180}
181
182simdjson_inline simdjson_result<const char *> value::current_location() noexcept {
183 return iter.json_iter().current_location();
184}
185
186simdjson_inline int32_t value::current_depth() const noexcept{
187 return iter.json_iter().depth();
188}
189
190simdjson_inline simdjson_result<value> value::at_pointer(std::string_view json_pointer) noexcept {
191 json_type t;
192 SIMDJSON_TRY(type().get(t));
193 switch (t)
194 {
195 case json_type::array:
196 return (*this).get_array().at_pointer(json_pointer);
197 case json_type::object:
198 return (*this).get_object().at_pointer(json_pointer);
199 default:
200 return INVALID_JSON_POINTER;
201 }
202}
203
204} // namespace ondemand
205} // namespace SIMDJSON_IMPLEMENTATION
206} // namespace simdjson
207
208namespace simdjson {
209
210simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
211 SIMDJSON_IMPLEMENTATION::ondemand::value &&value
212) noexcept :
213 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(
214 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(t&: value)
215 )
216{
217}
218simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
219 error_code error
220) noexcept :
221 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(error)
222{
223}
224simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_elements() & noexcept {
225 if (error()) { return error(); }
226 return first.count_elements();
227}
228simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_fields() & noexcept {
229 if (error()) { return error(); }
230 return first.count_fields();
231}
232simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at(size_t index) noexcept {
233 if (error()) { return error(); }
234 return first.at(index);
235}
236simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::begin() & noexcept {
237 if (error()) { return error(); }
238 return first.begin();
239}
240simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::end() & noexcept {
241 if (error()) { return error(); }
242 return {};
243}
244
245simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::find_field(std::string_view key) noexcept {
246 if (error()) { return error(); }
247 return first.find_field(key);
248}
249simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::find_field(const char *key) noexcept {
250 if (error()) { return error(); }
251 return first.find_field(key);
252}
253
254simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::find_field_unordered(std::string_view key) noexcept {
255 if (error()) { return error(); }
256 return first.find_field_unordered(key);
257}
258simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::find_field_unordered(const char *key) noexcept {
259 if (error()) { return error(); }
260 return first.find_field_unordered(key);
261}
262
263simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](std::string_view key) noexcept {
264 if (error()) { return error(); }
265 return first[key];
266}
267simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](const char *key) noexcept {
268 if (error()) { return error(); }
269 return first[key];
270}
271
272simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_array() noexcept {
273 if (error()) { return error(); }
274 return first.get_array();
275}
276simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_object() noexcept {
277 if (error()) { return error(); }
278 return first.get_object();
279}
280simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64() noexcept {
281 if (error()) { return error(); }
282 return first.get_uint64();
283}
284simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64_in_string() noexcept {
285 if (error()) { return error(); }
286 return first.get_uint64_in_string();
287}
288simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64() noexcept {
289 if (error()) { return error(); }
290 return first.get_int64();
291}
292simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64_in_string() noexcept {
293 if (error()) { return error(); }
294 return first.get_int64_in_string();
295}
296simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double() noexcept {
297 if (error()) { return error(); }
298 return first.get_double();
299}
300simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double_in_string() noexcept {
301 if (error()) { return error(); }
302 return first.get_double_in_string();
303}
304simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(bool allow_replacement) noexcept {
305 if (error()) { return error(); }
306 return first.get_string(allow_replacement);
307}
308simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_wobbly_string() noexcept {
309 if (error()) { return error(); }
310 return first.get_wobbly_string();
311}
312simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_raw_json_string() noexcept {
313 if (error()) { return error(); }
314 return first.get_raw_json_string();
315}
316simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_bool() noexcept {
317 if (error()) { return error(); }
318 return first.get_bool();
319}
320simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() noexcept {
321 if (error()) { return error(); }
322 return first.is_null();
323}
324
325template<typename T> simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() noexcept {
326 if (error()) { return error(); }
327 return first.get<T>();
328}
329template<typename T> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) noexcept {
330 if (error()) { return error(); }
331 return first.get<T>(out);
332}
333
334template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>() noexcept {
335 if (error()) { return error(); }
336 return std::move(first);
337}
338template<> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>(SIMDJSON_IMPLEMENTATION::ondemand::value &out) noexcept {
339 if (error()) { return error(); }
340 out = first;
341 return SUCCESS;
342}
343
344simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::type() noexcept {
345 if (error()) { return error(); }
346 return first.type();
347}
348simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_scalar() noexcept {
349 if (error()) { return error(); }
350 return first.is_scalar();
351}
352simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_negative() noexcept {
353 if (error()) { return error(); }
354 return first.is_negative();
355}
356simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_integer() noexcept {
357 if (error()) { return error(); }
358 return first.is_integer();
359}
360simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number_type() noexcept {
361 if (error()) { return error(); }
362 return first.get_number_type();
363}
364simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number() noexcept {
365 if (error()) { return error(); }
366 return first.get_number();
367}
368#if SIMDJSON_EXCEPTIONS
369simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false) {
370 if (error()) { throw simdjson_error(error()); }
371 return first;
372}
373simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() noexcept(false) {
374 if (error()) { throw simdjson_error(error()); }
375 return first;
376}
377simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator uint64_t() noexcept(false) {
378 if (error()) { throw simdjson_error(error()); }
379 return first;
380}
381simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator int64_t() noexcept(false) {
382 if (error()) { throw simdjson_error(error()); }
383 return first;
384}
385simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator double() noexcept(false) {
386 if (error()) { throw simdjson_error(error()); }
387 return first;
388}
389simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator std::string_view() noexcept(false) {
390 if (error()) { throw simdjson_error(error()); }
391 return first;
392}
393simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
394 if (error()) { throw simdjson_error(error()); }
395 return first;
396}
397simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator bool() noexcept(false) {
398 if (error()) { throw simdjson_error(error()); }
399 return first;
400}
401#endif
402
403simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::raw_json_token() noexcept {
404 if (error()) { return error(); }
405 return first.raw_json_token();
406}
407
408simdjson_inline simdjson_result<const char *> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::current_location() noexcept {
409 if (error()) { return error(); }
410 return first.current_location();
411}
412
413simdjson_inline simdjson_result<int32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::current_depth() const noexcept {
414 if (error()) { return error(); }
415 return first.current_depth();
416}
417
418simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at_pointer(std::string_view json_pointer) noexcept {
419 if (error()) { return error(); }
420 return first.at_pointer(json_pointer);
421}
422
423} // namespace simdjson
424