1 #ifndef SIMDJSON_DOCUMENT_STREAM_H
2 #define SIMDJSON_DOCUMENT_STREAM_H
4 #include "simdjson/common_defs.h"
5 #include "simdjson/dom/parser.h"
6 #include "simdjson/error.h"
7 #ifdef SIMDJSON_THREADS_ENABLED
10 #include <condition_variable>
17 #ifdef SIMDJSON_THREADS_ENABLED
19 struct stage1_worker {
20 stage1_worker() noexcept = default;
21 stage1_worker(const stage1_worker&) = delete;
22 stage1_worker(stage1_worker&&) = delete;
23 stage1_worker operator=(const stage1_worker&) = delete;
34 void run(document_stream * ds, dom::parser * stage1,
size_t next_batch_start);
49 dom::parser * stage1_thread_parser{};
50 size_t _next_batch_start{};
51 document_stream * owner{};
62 std::mutex locking_mutex{};
63 std::condition_variable cond_var{};
121 using difference_type = std::ptrdiff_t;
123 using iterator_category = std::input_iterator_tag;
128 simdjson_inline
iterator() noexcept;
132 simdjson_inline
reference operator*() noexcept;
136 inline iterator& operator++() noexcept;
141 simdjson_inline
bool operator!=(
const iterator &other)
const noexcept;
157 simdjson_inline
size_t current_index()
const noexcept;
177 simdjson_inline std::string_view source()
const noexcept;
222 inline
void start() noexcept;
248 inline
void next() noexcept;
254 inline
void load_batch() noexcept;
257 inline
size_t next_batch_start() const noexcept;
268 size_t batch_start{0};
270 #ifdef SIMDJSON_THREADS_ENABLED
274 inline void load_from_stage1_thread() noexcept;
277 inline
void start_stage1_thread() noexcept;
280 inline
void finish_stage1_thread() noexcept;
285 friend struct stage1_worker;
286 std::unique_ptr<stage1_worker> worker{
new(std::nothrow) stage1_worker()};
291 dom::parser stage1_thread_parser{};
294 friend class dom::parser;
296 friend struct internal::simdjson_result_base<dom::document_stream>;
303 struct
simdjson_result<dom::document_stream> :
public internal::simdjson_result_base<dom::document_stream> {
309 #if SIMDJSON_EXCEPTIONS
313 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
314 [[deprecated(
"parse_many() and load_many() may return errors. Use document_stream stream; error = parser.parse_many().get(doc); instead.")]]
316 [[deprecated(
"parse_many() and load_many() may return errors. Use document_stream stream; error = parser.parse_many().get(doc); instead.")]]
An iterator through a forward-only stream of documents.
A forward-only stream of documents.
simdjson_inline document_stream & operator=(document_stream &&other) noexcept=default
Move one document_stream to another.
size_t size_in_bytes() const noexcept
Returns the input size in bytes.
size_t truncated_bytes() const noexcept
After iterating through the stream, this method returns the number of bytes that were not parsed at t...
simdjson_inline iterator begin() noexcept
Start iterating the documents in the stream.
simdjson_inline document_stream(document_stream &&other) noexcept=default
Move one document_stream to another.
simdjson_inline iterator end() noexcept
The end of the stream, for iterator comparison purposes.
simdjson_inline document_stream() noexcept
Construct an uninitialized document_stream.
A persistent document parser.
We want to support argument-dependent lookup (ADL).
error_code
All possible errors returned by simdjson.
@ UNINITIALIZED
unknown error, or uninitialized document
The result of a simdjson operation that could fail.