simdjson  3.11.0
Ridiculously Fast JSON
value_iterator.h
1 #ifndef SIMDJSON_GENERIC_ONDEMAND_VALUE_ITERATOR_H
2 
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_VALUE_ITERATOR_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/implementation_simdjson_result_base.h"
7 #endif // SIMDJSON_CONDITIONAL_INCLUDE
8 
9 namespace simdjson {
10 namespace SIMDJSON_IMPLEMENTATION {
11 namespace ondemand {
12 
21 class value_iterator {
22 protected:
24  json_iterator *_json_iter{};
26  depth_t _depth{};
30  token_position _start_position{};
31 
32 public:
33  simdjson_inline value_iterator() noexcept = default;
34 
38  simdjson_inline void start_document() noexcept;
39 
45  simdjson_warn_unused simdjson_inline error_code skip_child() noexcept;
46 
50  simdjson_inline bool at_end() const noexcept;
51 
55  simdjson_inline bool at_start() const noexcept;
56 
60  simdjson_inline bool is_open() const noexcept;
61 
65  simdjson_inline bool at_first_field() const noexcept;
66 
70  simdjson_inline void abandon() noexcept;
71 
75  simdjson_inline value_iterator child_value() const noexcept;
76 
80  simdjson_inline int32_t depth() const noexcept;
81 
87  simdjson_inline simdjson_result<json_type> type() const noexcept;
88 
104  simdjson_warn_unused simdjson_inline simdjson_result<bool> start_object() noexcept;
112  simdjson_warn_unused simdjson_inline simdjson_result<bool> start_root_object() noexcept;
120  simdjson_warn_unused simdjson_inline error_code check_root_object() noexcept;
130  simdjson_warn_unused simdjson_inline simdjson_result<bool> started_object() noexcept;
140  simdjson_warn_unused simdjson_inline simdjson_result<bool> started_root_object() noexcept;
141 
152  simdjson_warn_unused simdjson_inline simdjson_result<bool> has_next_field() noexcept;
153 
157  simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> field_key() noexcept;
158 
162  simdjson_warn_unused simdjson_inline error_code field_value() noexcept;
163 
180  simdjson_warn_unused simdjson_inline error_code find_field(const std::string_view key) noexcept;
181 
199  simdjson_warn_unused simdjson_inline simdjson_result<bool> find_field_raw(const std::string_view key) noexcept;
200 
219  simdjson_warn_unused simdjson_inline simdjson_result<bool> find_field_unordered_raw(const std::string_view key) noexcept;
220 
236  simdjson_warn_unused simdjson_inline simdjson_result<bool> start_array() noexcept;
244  simdjson_warn_unused simdjson_inline simdjson_result<bool> start_root_array() noexcept;
252  simdjson_warn_unused simdjson_inline error_code check_root_array() noexcept;
262  simdjson_warn_unused simdjson_inline simdjson_result<bool> started_array() noexcept;
272  simdjson_warn_unused simdjson_inline simdjson_result<bool> started_root_array() noexcept;
273 
283  simdjson_warn_unused simdjson_inline simdjson_result<bool> has_next_element() noexcept;
284 
288  simdjson_warn_unused simdjson_inline value_iterator child() const noexcept;
289 
298  simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement) noexcept;
299  template <typename string_type>
300  simdjson_warn_unused simdjson_inline error_code get_string(string_type& receiver, bool allow_replacement) noexcept;
301  simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
302  simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
303  simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
304  simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_uint64_in_string() noexcept;
305  simdjson_warn_unused simdjson_inline simdjson_result<int64_t> get_int64() noexcept;
306  simdjson_warn_unused simdjson_inline simdjson_result<int64_t> get_int64_in_string() noexcept;
307  simdjson_warn_unused simdjson_inline simdjson_result<double> get_double() noexcept;
308  simdjson_warn_unused simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
309  simdjson_warn_unused simdjson_inline simdjson_result<bool> get_bool() noexcept;
310  simdjson_warn_unused simdjson_inline simdjson_result<bool> is_null() noexcept;
311  simdjson_warn_unused simdjson_inline bool is_negative() noexcept;
312  simdjson_warn_unused simdjson_inline simdjson_result<bool> is_integer() noexcept;
313  simdjson_warn_unused simdjson_inline simdjson_result<number_type> get_number_type() noexcept;
314  simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
315 
316  simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_root_string(bool check_trailing, bool allow_replacement) noexcept;
317  template <typename string_type>
318  simdjson_warn_unused simdjson_inline error_code get_root_string(string_type& receiver, bool check_trailing, bool allow_replacement) noexcept;
319  simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_root_wobbly_string(bool check_trailing) noexcept;
320  simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> get_root_raw_json_string(bool check_trailing) noexcept;
321  simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_root_uint64(bool check_trailing) noexcept;
322  simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_root_uint64_in_string(bool check_trailing) noexcept;
323  simdjson_warn_unused simdjson_inline simdjson_result<int64_t> get_root_int64(bool check_trailing) noexcept;
324  simdjson_warn_unused simdjson_inline simdjson_result<int64_t> get_root_int64_in_string(bool check_trailing) noexcept;
325  simdjson_warn_unused simdjson_inline simdjson_result<double> get_root_double(bool check_trailing) noexcept;
326  simdjson_warn_unused simdjson_inline simdjson_result<double> get_root_double_in_string(bool check_trailing) noexcept;
327  simdjson_warn_unused simdjson_inline simdjson_result<bool> get_root_bool(bool check_trailing) noexcept;
328  simdjson_warn_unused simdjson_inline bool is_root_negative() noexcept;
329  simdjson_warn_unused simdjson_inline simdjson_result<bool> is_root_integer(bool check_trailing) noexcept;
330  simdjson_warn_unused simdjson_inline simdjson_result<number_type> get_root_number_type(bool check_trailing) noexcept;
331  simdjson_warn_unused simdjson_inline simdjson_result<number> get_root_number(bool check_trailing) noexcept;
332  simdjson_warn_unused simdjson_inline simdjson_result<bool> is_root_null(bool check_trailing) noexcept;
333 
334  simdjson_inline error_code error() const noexcept;
335  simdjson_inline uint8_t *&string_buf_loc() noexcept;
336  simdjson_inline const json_iterator &json_iter() const noexcept;
337  simdjson_inline json_iterator &json_iter() noexcept;
338 
339  simdjson_inline void assert_is_valid() const noexcept;
340  simdjson_inline bool is_valid() const noexcept;
341 
343 protected:
348  simdjson_inline simdjson_result<bool> reset_array() noexcept;
353  simdjson_inline simdjson_result<bool> reset_object() noexcept;
361  simdjson_inline void move_at_start() noexcept;
362 
369  simdjson_inline void move_at_container_start() noexcept;
370  /* Useful for debugging and logging purposes. */
371  inline std::string to_string() const noexcept;
372  simdjson_inline value_iterator(json_iterator *json_iter, depth_t depth, token_position start_index) noexcept;
373 
374  simdjson_inline simdjson_result<bool> parse_null(const uint8_t *json) const noexcept;
375  simdjson_inline simdjson_result<bool> parse_bool(const uint8_t *json) const noexcept;
376  simdjson_inline const uint8_t *peek_start() const noexcept;
377  simdjson_inline uint32_t peek_start_length() const noexcept;
378  simdjson_inline uint32_t peek_root_length() const noexcept;
379 
409  simdjson_inline void advance_scalar(const char *type) noexcept;
410  simdjson_inline void advance_root_scalar(const char *type) noexcept;
411  simdjson_inline void advance_non_root_scalar(const char *type) noexcept;
412 
413  simdjson_inline const uint8_t *peek_scalar(const char *type) noexcept;
414  simdjson_inline const uint8_t *peek_root_scalar(const char *type) noexcept;
415  simdjson_inline const uint8_t *peek_non_root_scalar(const char *type) noexcept;
416 
417 
418  simdjson_inline error_code start_container(uint8_t start_char, const char *incorrect_type_message, const char *type) noexcept;
419  simdjson_inline error_code end_container() noexcept;
420 
427  simdjson_inline simdjson_result<const uint8_t *> advance_to_value() noexcept;
428 
429  simdjson_inline error_code incorrect_type_error(const char *message) const noexcept;
430  simdjson_inline error_code error_unless_more_tokens(uint32_t tokens=1) const noexcept;
431 
432  simdjson_inline bool is_at_start() const noexcept;
439  simdjson_inline bool is_at_iterator_start() const noexcept;
440 
448  simdjson_inline bool is_at_key() const noexcept;
449 
450  inline void assert_at_start() const noexcept;
451  inline void assert_at_container_start() const noexcept;
452  inline void assert_at_root() const noexcept;
453  inline void assert_at_child() const noexcept;
454  inline void assert_at_next() const noexcept;
455  inline void assert_at_non_root_start() const noexcept;
456 
458  simdjson_inline token_position start_position() const noexcept;
459 
461  simdjson_inline token_position position() const noexcept;
463  simdjson_inline token_position last_position() const noexcept;
465  simdjson_inline token_position end_position() const noexcept;
467  simdjson_inline error_code report_error(error_code error, const char *message) noexcept;
468 
469  friend class document;
470  friend class object;
471  friend class array;
472  friend class value;
473  friend class field;
474 }; // value_iterator
475 
476 } // namespace ondemand
477 } // namespace SIMDJSON_IMPLEMENTATION
478 } // namespace simdjson
479 
480 namespace simdjson {
481 
482 template<>
483 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value_iterator> {
484 public:
485  simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::value_iterator &&value) noexcept;
486  simdjson_inline simdjson_result(error_code error) noexcept;
487  simdjson_inline simdjson_result() noexcept = default;
488 };
489 
490 } // namespace simdjson
491 
492 #endif // SIMDJSON_GENERIC_ONDEMAND_VALUE_ITERATOR_H
A JSON field (key/value pair) in an object.
Definition: field.h:22
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
int32_t depth_t
Represents the depth of a JSON value (number of nested arrays/objects).
Definition: base.h:18
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
std::string to_string(T x)
Converts JSON to a string.
A type representing a JSON number.
Definition: json_type.h:32
The result of a simdjson operation that could fail.
Definition: error.h:215