3 #ifndef SIMDJSON_DOM_PARSEDJSON_ITERATOR_H
4 #define SIMDJSON_DOM_PARSEDJSON_ITERATOR_H
13 #include "simdjson/dom/document.h"
14 #include "simdjson/dom/parsedjson.h"
15 #include "simdjson/internal/jsonformatutils.h"
17 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
21 class [[deprecated("Use the new DOM navigation API instead (see doc/basics.md)")]] dom::parser::Iterator {
23 inline Iterator(
const dom::parser &parser) noexcept(
false);
24 inline Iterator(
const Iterator &o) noexcept;
25 inline ~Iterator() noexcept;
27 inline Iterator& operator=(const Iterator&) = delete;
29 inline
bool is_ok() const;
32 inline
size_t get_tape_location() const;
35 inline
size_t get_tape_length() const;
39 inline
size_t get_depth() const;
43 inline uint8_t get_scope_type() const;
46 inline
bool move_forward();
50 inline uint8_t get_type()
const {
55 inline int64_t get_integer()
const {
56 if (location + 1 >= tape_length) {
59 return static_cast<int64_t
>(doc.tape[location + 1]);
63 inline uint64_t get_unsigned_integer()
const {
64 if (location + 1 >= tape_length) {
67 return doc.tape[location + 1];
74 inline const char *get_string()
const {
75 return reinterpret_cast<const char *
>(
76 doc.string_buf.get() + (current_val & internal::JSON_VALUE_MASK) +
sizeof(uint32_t));
80 inline uint32_t get_string_length()
const {
83 reinterpret_cast<const char *
>(doc.string_buf.get() +
84 (current_val & internal::JSON_VALUE_MASK)),
91 inline double get_double()
const {
92 if (location + 1 >= tape_length) {
93 return std::numeric_limits<double>::quiet_NaN();
97 std::memcpy(&answer, &doc.tape[location + 1],
sizeof(answer));
101 inline bool is_object_or_array()
const {
return is_object() || is_array(); }
103 inline bool is_object()
const {
return get_type() ==
'{'; }
105 inline bool is_array()
const {
return get_type() ==
'['; }
107 inline bool is_string()
const {
return get_type() ==
'"'; }
111 inline bool is_integer()
const {
return get_type() ==
'l'; }
121 inline bool is_unsigned_integer()
const {
return get_type() ==
'u'; }
123 inline bool is_double()
const {
return get_type() ==
'd'; }
125 inline bool is_number()
const {
126 return is_integer() || is_unsigned_integer() || is_double();
129 inline bool is_true()
const {
return get_type() ==
't'; }
131 inline bool is_false()
const {
return get_type() ==
'f'; }
133 inline bool is_null()
const {
return get_type() ==
'n'; }
135 static bool is_object_or_array(uint8_t type) {
136 return ((type ==
'[') || (type ==
'{'));
148 inline bool move_to_key(
const char *key);
151 inline bool move_to_key_insensitive(
const char *key);
160 inline bool move_to_key(
const char *key, uint32_t length);
165 inline void move_to_value();
170 inline bool move_to_index(uint32_t index);
182 inline bool move_to(
const char *pointer, uint32_t length);
193 inline bool move_to(
const std::string &pointer) {
194 return move_to(pointer.c_str(), uint32_t(pointer.length()));
205 inline bool relative_move_to(
const char *pointer, uint32_t length);
241 inline void to_start_scope();
243 inline void rewind() {
251 inline bool print(std::ostream &os,
bool escape_strings =
true)
const;
258 size_t tape_length{};
259 uint8_t current_type{};
260 uint64_t current_val{};
262 size_t start_of_scope;
266 scopeindex_t *depth_index{};
We want to support argument-dependent lookup (ADL).