simdjson  3.11.0
Ridiculously Fast JSON
token_iterator-inl.h
1 #ifndef SIMDJSON_GENERIC_ONDEMAND_TOKEN_ITERATOR_INL_H
2 
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_TOKEN_ITERATOR_INL_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/ondemand/token_iterator.h"
7 #include "simdjson/generic/implementation_simdjson_result_base-inl.h"
8 #endif // SIMDJSON_CONDITIONAL_INCLUDE
9 
10 namespace simdjson {
11 namespace SIMDJSON_IMPLEMENTATION {
12 namespace ondemand {
13 
14 simdjson_inline token_iterator::token_iterator(
15  const uint8_t *_buf,
16  token_position position
17 ) noexcept : buf{_buf}, _position{position}
18 {
19 }
20 
21 simdjson_inline uint32_t token_iterator::current_offset() const noexcept {
22  return *(_position);
23 }
24 
25 
26 simdjson_inline const uint8_t *token_iterator::return_current_and_advance() noexcept {
27  return &buf[*(_position++)];
28 }
29 
30 simdjson_inline const uint8_t *token_iterator::peek(token_position position) const noexcept {
31  return &buf[*position];
32 }
33 simdjson_inline uint32_t token_iterator::peek_index(token_position position) const noexcept {
34  return *position;
35 }
36 simdjson_inline uint32_t token_iterator::peek_length(token_position position) const noexcept {
37  return *(position+1) - *position;
38 }
39 
40 simdjson_inline uint32_t token_iterator::peek_root_length(token_position position) const noexcept {
41  return *(position+2) - *(position) > *(position+1) - *(position) ?
42  *(position+1) - *(position)
43  : *(position+2) - *(position);
44 }
45 simdjson_inline const uint8_t *token_iterator::peek(int32_t delta) const noexcept {
46  return &buf[*(_position+delta)];
47 }
48 simdjson_inline uint32_t token_iterator::peek_index(int32_t delta) const noexcept {
49  return *(_position+delta);
50 }
51 simdjson_inline uint32_t token_iterator::peek_length(int32_t delta) const noexcept {
52  return *(_position+delta+1) - *(_position+delta);
53 }
54 
55 simdjson_inline token_position token_iterator::position() const noexcept {
56  return _position;
57 }
58 simdjson_inline void token_iterator::set_position(token_position target_position) noexcept {
59  _position = target_position;
60 }
61 
62 simdjson_inline bool token_iterator::operator==(const token_iterator &other) const noexcept {
63  return _position == other._position;
64 }
65 simdjson_inline bool token_iterator::operator!=(const token_iterator &other) const noexcept {
66  return _position != other._position;
67 }
68 simdjson_inline bool token_iterator::operator>(const token_iterator &other) const noexcept {
69  return _position > other._position;
70 }
71 simdjson_inline bool token_iterator::operator>=(const token_iterator &other) const noexcept {
72  return _position >= other._position;
73 }
74 simdjson_inline bool token_iterator::operator<(const token_iterator &other) const noexcept {
75  return _position < other._position;
76 }
77 simdjson_inline bool token_iterator::operator<=(const token_iterator &other) const noexcept {
78  return _position <= other._position;
79 }
80 
81 } // namespace ondemand
82 } // namespace SIMDJSON_IMPLEMENTATION
83 } // namespace simdjson
84 
85 namespace simdjson {
86 
87 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator>::simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::token_iterator &&value) noexcept
88  : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator>(value)) {}
89 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator>::simdjson_result(error_code error) noexcept
90  : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::token_iterator>(error) {}
91 
92 } // namespace simdjson
93 
94 #endif // SIMDJSON_GENERIC_ONDEMAND_TOKEN_ITERATOR_INL_H
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