1 #ifndef SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_STREAM_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_DOCUMENT_STREAM_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/implementation_simdjson_result_base.h"
7 #include "simdjson/generic/ondemand/document.h"
8 #include "simdjson/generic/ondemand/parser.h"
11 #ifdef SIMDJSON_THREADS_ENABLED
14 #include <condition_variable>
18 namespace SIMDJSON_IMPLEMENTATION {
21 #ifdef SIMDJSON_THREADS_ENABLED
23 struct stage1_worker {
24 stage1_worker() noexcept = default;
25 stage1_worker(const stage1_worker&) = delete;
26 stage1_worker(stage1_worker&&) = delete;
27 stage1_worker operator=(const stage1_worker&) = delete;
38 void run(document_stream * ds, parser * stage1,
size_t next_batch_start);
53 ondemand::parser * stage1_thread_parser{};
54 size_t _next_batch_start{};
55 document_stream * owner{};
66 std::mutex locking_mutex{};
67 std::condition_variable cond_var{};
69 friend class document_stream;
127 using difference_type = std::ptrdiff_t;
129 using iterator_category = std::input_iterator_tag;
134 simdjson_inline
iterator() noexcept;
142 inline iterator& operator++() noexcept;
147 simdjson_inline
bool operator!=(
const iterator &other)
const noexcept;
163 simdjson_inline
size_t current_index()
const noexcept;
184 simdjson_inline std::string_view source()
const noexcept;
200 friend class json_iterator;
231 bool allow_comma_separated
238 inline
void start() noexcept;
263 inline
void next() noexcept;
266 inline
void next_document() noexcept;
269 inline
size_t next_batch_start() const noexcept;
272 inline
error_code run_stage1(ondemand::
parser &p,
size_t batch_start) noexcept;
279 bool allow_comma_separated;
288 size_t batch_start{0};
291 #ifdef SIMDJSON_THREADS_ENABLED
295 inline void load_from_stage1_thread() noexcept;
298 inline
void start_stage1_thread() noexcept;
301 inline
void finish_stage1_thread() noexcept;
306 std::unique_ptr<stage1_worker> worker{
new(std::nothrow) stage1_worker()};
311 ondemand::parser stage1_thread_parser{};
313 friend struct stage1_worker;
317 friend class document;
318 friend class json_iterator;
320 friend struct internal::simdjson_result_base<ondemand::document_stream>;
A forward-only stream of documents.
simdjson_inline iterator end() noexcept
The end of the stream, for iterator comparison purposes.
simdjson_inline document_stream(document_stream &&other) noexcept=default
Move one document_stream to another.
size_t size_in_bytes() const noexcept
Returns the input size in bytes.
simdjson_inline document_stream & operator=(document_stream &&other) noexcept=default
Move one document_stream to another.
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() noexcept
Construct an uninitialized document_stream.
A JSON fragment iterator.
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
@ UNINITIALIZED
unknown error, or uninitialized document
The result of a simdjson operation that could fail.
The result of a simdjson operation that could fail.