simdjson  3.1.6
Ridiculously Fast JSON
token_iterator.h
1 namespace simdjson {
2 namespace SIMDJSON_IMPLEMENTATION {
3 namespace ondemand {
4 
11 class token_iterator {
12 public:
18  simdjson_inline token_iterator() noexcept = default;
19  simdjson_inline token_iterator(token_iterator &&other) noexcept = default;
20  simdjson_inline token_iterator &operator=(token_iterator &&other) noexcept = default;
21  simdjson_inline token_iterator(const token_iterator &other) noexcept = default;
22  simdjson_inline token_iterator &operator=(const token_iterator &other) noexcept = default;
23 
27  simdjson_inline const uint8_t *return_current_and_advance() noexcept;
31  simdjson_inline uint32_t current_offset() const noexcept;
43  simdjson_inline const uint8_t *peek(int32_t delta=0) const noexcept;
52  simdjson_inline uint32_t peek_length(int32_t delta=0) const noexcept;
53 
62  simdjson_inline const uint8_t *peek(token_position position) const noexcept;
70  simdjson_inline uint32_t peek_length(token_position position) const noexcept;
71 
75  simdjson_inline token_position position() const noexcept;
79  simdjson_inline void set_position(token_position target_position) noexcept;
80 
81  // NOTE: we don't support a full C++ iterator interface, because we expect people to make
82  // different calls to advance the iterator based on *their own* state.
83 
84  simdjson_inline bool operator==(const token_iterator &other) const noexcept;
85  simdjson_inline bool operator!=(const token_iterator &other) const noexcept;
86  simdjson_inline bool operator>(const token_iterator &other) const noexcept;
87  simdjson_inline bool operator>=(const token_iterator &other) const noexcept;
88  simdjson_inline bool operator<(const token_iterator &other) const noexcept;
89  simdjson_inline bool operator<=(const token_iterator &other) const noexcept;
90 
91 protected:
92  simdjson_inline token_iterator(const uint8_t *buf, token_position position) noexcept;
93 
102  simdjson_inline uint32_t peek_index(int32_t delta=0) const noexcept;
111  simdjson_inline uint32_t peek_index(token_position position) const noexcept;
112 
113  const uint8_t *buf{};
114  token_position _position{};
115 
116  friend class json_iterator;
117  friend class value_iterator;
118  friend class object;
119  friend simdjson_inline void logger::log_line(const json_iterator &iter, const char *title_prefix, const char *title, std::string_view detail, int delta, int depth_delta) noexcept;
120  friend simdjson_inline void logger::log_line(const json_iterator &iter, token_position index, depth_t depth, const char *title_prefix, const char *title, std::string_view detail) noexcept;
121 };
122 
123 } // namespace ondemand
124 } // namespace SIMDJSON_IMPLEMENTATION
125 } // namespace simdjson
126 
127 namespace simdjson {
128 
129 template<>
130 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator> {
131 public:
132  simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::token_iterator &&value) noexcept;
133  simdjson_inline simdjson_result(error_code error) noexcept;
134  simdjson_inline simdjson_result() noexcept = default;
135  simdjson_inline ~simdjson_result() noexcept = default;
136 };
137 
138 } // namespace simdjson
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
int32_t depth_t
Represents the depth of a JSON value (number of nested arrays/objects).
Definition: ondemand.h:11
We want to support argument-dependent lookup (ADL).
error_code
All possible errors returned by simdjson.
Definition: error.h:17
The result of a simdjson operation that could fail.
Definition: error.h:205
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:132
simdjson_inline T & value() &noexcept(false)
Get the result value.