simdjson 4.2.3
Ridiculously Fast JSON
Loading...
Searching...
No Matches
token_iterator.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_TOKEN_ITERATOR_H
2
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_TOKEN_ITERATOR_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/implementation_simdjson_result_base.h"
7#include "simdjson/generic/ondemand/logger.h"
8#endif // SIMDJSON_CONDITIONAL_INCLUDE
9
10namespace simdjson {
11namespace SIMDJSON_IMPLEMENTATION {
12namespace ondemand {
13
20class token_iterator {
21public:
27 simdjson_inline token_iterator() noexcept = default;
28 simdjson_inline token_iterator(token_iterator &&other) noexcept = default;
29 simdjson_inline token_iterator &operator=(token_iterator &&other) noexcept = default;
30 simdjson_inline token_iterator(const token_iterator &other) noexcept = default;
31 simdjson_inline token_iterator &operator=(const token_iterator &other) noexcept = default;
32
36 simdjson_inline const uint8_t *return_current_and_advance() noexcept;
40 simdjson_inline uint32_t current_offset() const noexcept;
52 simdjson_inline const uint8_t *peek(int32_t delta=0) const noexcept;
61 simdjson_inline uint32_t peek_length(int32_t delta=0) const noexcept;
62
71 simdjson_inline const uint8_t *peek(token_position position) const noexcept;
79 simdjson_inline uint32_t peek_length(token_position position) const noexcept;
87 simdjson_inline uint32_t peek_root_length(token_position position) const noexcept;
91 simdjson_inline token_position position() const noexcept;
95 simdjson_inline void set_position(token_position target_position) noexcept;
96
97 // NOTE: we don't support a full C++ iterator interface, because we expect people to make
98 // different calls to advance the iterator based on *their own* state.
99
100 simdjson_inline bool operator==(const token_iterator &other) const noexcept;
101 simdjson_inline bool operator!=(const token_iterator &other) const noexcept;
102 simdjson_inline bool operator>(const token_iterator &other) const noexcept;
103 simdjson_inline bool operator>=(const token_iterator &other) const noexcept;
104 simdjson_inline bool operator<(const token_iterator &other) const noexcept;
105 simdjson_inline bool operator<=(const token_iterator &other) const noexcept;
106
107protected:
108 simdjson_inline token_iterator(const uint8_t *buf, token_position position) noexcept;
109
118 simdjson_inline uint32_t peek_index(int32_t delta=0) const noexcept;
127 simdjson_inline uint32_t peek_index(token_position position) const noexcept;
128
129 const uint8_t *buf{};
130 token_position _position{};
131
132 friend class json_iterator;
133 friend class value_iterator;
134 friend class object;
135 template <typename... Args>
136 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, logger::log_level level, Args&&... args) noexcept;
137 template <typename... Args>
138 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, logger::log_level level, Args&&... args) noexcept;
139};
140
141} // namespace ondemand
142} // namespace SIMDJSON_IMPLEMENTATION
143} // namespace simdjson
144
145namespace simdjson {
146
147template<>
148struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator> {
149public:
150 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::token_iterator &&value) noexcept;
151 simdjson_inline simdjson_result(error_code error) noexcept;
152 simdjson_inline simdjson_result() noexcept = default;
153 simdjson_inline ~simdjson_result() noexcept = default;
154};
155
156} // namespace simdjson
157
158#endif // SIMDJSON_GENERIC_ONDEMAND_TOKEN_ITERATOR_H
@ 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 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
The result of a simdjson operation that could fail.
Definition error.h:280
simdjson_inline error_code error() const noexcept
The error.
Definition error-inl.h:168