simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
ranges.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_RANGES_H
2
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_RANGES_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/ondemand/array.h"
7#include "simdjson/generic/ondemand/array_iterator.h"
8#include "simdjson/generic/ondemand/object.h"
9#include "simdjson/generic/ondemand/object_iterator.h"
10#include "simdjson/generic/ondemand/field.h"
11#include "simdjson/generic/ondemand/value.h"
12#endif // SIMDJSON_CONDITIONAL_INCLUDE
13
14#if SIMDJSON_SUPPORTS_RANGES
15
16namespace simdjson {
17namespace SIMDJSON_IMPLEMENTATION {
18namespace ondemand {
19
31class array_range_iterator {
32public:
33 using iterator_concept = std::input_iterator_tag;
34 using value_type = simdjson_result<value>;
35 using reference = simdjson_result<value>;
36 using difference_type = std::ptrdiff_t;
37
38 simdjson_inline array_range_iterator() noexcept = default;
39 simdjson_inline explicit array_range_iterator(array_iterator iter) noexcept;
40
45 simdjson_inline simdjson_result<value> operator*() const noexcept;
46 simdjson_inline array_range_iterator& operator++() noexcept;
47SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
48 simdjson_inline void operator++(int) noexcept;
49SIMDJSON_POP_DISABLE_WARNINGS
54 simdjson_inline friend bool operator==(const array_range_iterator& a,
55 const array_range_iterator& b) noexcept {
56 return a.iter_ == b.iter_;
57 }
58
59private:
60 mutable array_iterator iter_{};
61};
62
80class array_range {
81public:
82 simdjson_inline array_range() noexcept = default;
83 simdjson_inline explicit array_range(array& arr) noexcept;
84
85 simdjson_inline array_range_iterator begin() noexcept;
86 simdjson_inline array_range_iterator end() noexcept;
87
89 simdjson_inline error_code error() const noexcept { return error_; }
90
91private:
92 array_iterator begin_{};
93 array_iterator end_{};
94 error_code error_{SUCCESS};
95};
96
103class object_range_iterator {
104public:
105 using iterator_concept = std::input_iterator_tag;
106 using value_type = simdjson_result<field>;
107 using reference = simdjson_result<field>;
108 using difference_type = std::ptrdiff_t;
109
110 simdjson_inline object_range_iterator() noexcept = default;
111 simdjson_inline explicit object_range_iterator(object_iterator iter) noexcept;
112
113 simdjson_inline simdjson_result<field> operator*() const noexcept;
114 simdjson_inline object_range_iterator& operator++() noexcept;
115SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
116 simdjson_inline void operator++(int) noexcept;
117SIMDJSON_POP_DISABLE_WARNINGS
118 simdjson_inline friend bool operator==(const object_range_iterator& a,
119 const object_range_iterator& b) noexcept {
120 return a.iter_ == b.iter_;
121 }
122
123private:
124 mutable object_iterator iter_{};
125};
126
136class object_range {
137public:
138 simdjson_inline object_range() noexcept = default;
139 simdjson_inline explicit object_range(object& obj) noexcept;
140
141 simdjson_inline object_range_iterator begin() noexcept;
142 simdjson_inline object_range_iterator end() noexcept;
143
145 simdjson_inline error_code error() const noexcept { return error_; }
146
147private:
148 object_iterator begin_{};
149 object_iterator end_{};
150 error_code error_{SUCCESS};
151};
152
154simdjson_inline array_range get_range(array& arr) noexcept;
155
157simdjson_inline object_range get_key_value_range(object& obj) noexcept;
158
159#if SIMDJSON_EXCEPTIONS
161simdjson_inline array_range get_range(simdjson_result<array> result);
162
164simdjson_inline object_range get_key_value_range(simdjson_result<object> result);
165#endif // SIMDJSON_EXCEPTIONS
166
167} // namespace ondemand
168} // namespace SIMDJSON_IMPLEMENTATION
169} // namespace simdjson
170
171namespace std {
172namespace ranges {
173template<>
174inline constexpr bool enable_view<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::array_range> = true;
175template<>
176inline constexpr bool enable_view<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::object_range> = true;
177} // namespace ranges
178} // namespace std
179
180#endif // SIMDJSON_SUPPORTS_RANGES
181
182#endif // SIMDJSON_GENERIC_ONDEMAND_RANGES_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
@ SUCCESS
No error.
Definition error.h:20