simdjson  3.3.0
Ridiculously Fast JSON
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 
10 namespace simdjson {
11 namespace SIMDJSON_IMPLEMENTATION {
12 namespace ondemand {
13 
20 class token_iterator {
21 public:
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;
80 
84  simdjson_inline token_position position() const noexcept;
88  simdjson_inline void set_position(token_position target_position) noexcept;
89 
90  // NOTE: we don't support a full C++ iterator interface, because we expect people to make
91  // different calls to advance the iterator based on *their own* state.
92 
93  simdjson_inline bool operator==(const token_iterator &other) const noexcept;
94  simdjson_inline bool operator!=(const token_iterator &other) const noexcept;
95  simdjson_inline bool operator>(const token_iterator &other) const noexcept;
96  simdjson_inline bool operator>=(const token_iterator &other) const noexcept;
97  simdjson_inline bool operator<(const token_iterator &other) const noexcept;
98  simdjson_inline bool operator<=(const token_iterator &other) const noexcept;
99 
100 protected:
101  simdjson_inline token_iterator(const uint8_t *buf, token_position position) noexcept;
102 
111  simdjson_inline uint32_t peek_index(int32_t delta=0) const noexcept;
120  simdjson_inline uint32_t peek_index(token_position position) const noexcept;
121 
122  const uint8_t *buf{};
123  token_position _position{};
124 
125  friend class json_iterator;
126  friend class value_iterator;
127  friend class object;
128  template <typename... Args>
129  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;
130  template <typename... Args>
131  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;
132 };
133 
134 } // namespace ondemand
135 } // namespace SIMDJSON_IMPLEMENTATION
136 } // namespace simdjson
137 
138 namespace simdjson {
139 
140 template<>
141 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator> {
142 public:
143  simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::token_iterator &&value) noexcept;
144  simdjson_inline simdjson_result(error_code error) noexcept;
145  simdjson_inline simdjson_result() noexcept = default;
146  simdjson_inline ~simdjson_result() noexcept = default;
147 };
148 
149 } // namespace simdjson
150 
151 #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:207
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:131
simdjson_inline T & value() &noexcept(false)
Get the result value.