Rename dom::stream to dom::document_stream

This commit is contained in:
John Keiser 2020-03-28 12:31:05 -07:00
parent 03746b966b
commit 62da98aef6
5 changed files with 45 additions and 45 deletions

View File

@ -17,8 +17,8 @@ class element;
class array;
class object;
class key_value_pair;
class stream;
class document;
class document_stream;
/** The default batch size for parser.parse_many() and parser.load_many() */
static constexpr size_t DEFAULT_BATCH_SIZE = 1000000;
@ -792,7 +792,7 @@ public:
* - CAPACITY if the parser does not have enough capacity and batch_size > max_capacity.
* - other json errors if parsing fails.
*/
inline stream load_many(const std::string &path, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
inline document_stream load_many(const std::string &path, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
/**
* Parse a JSON document and return a temporary reference to it.
@ -991,7 +991,7 @@ public:
* - CAPACITY if the parser does not have enough capacity and batch_size > max_capacity.
* - other json errors if parsing fails.
*/
inline stream parse_many(const uint8_t *buf, size_t len, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
inline document_stream parse_many(const uint8_t *buf, size_t len, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
/**
* Parse a buffer containing many JSON documents.
@ -1053,7 +1053,7 @@ public:
* - CAPACITY if the parser does not have enough capacity and batch_size > max_capacity.
* - other json errors if parsing fails
*/
inline stream parse_many(const char *buf, size_t len, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
inline document_stream parse_many(const char *buf, size_t len, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
/**
* Parse a buffer containing many JSON documents.
@ -1114,7 +1114,7 @@ public:
* - CAPACITY if the parser does not have enough capacity and batch_size > max_capacity.
* - other json errors if parsing fails
*/
inline stream parse_many(const std::string &s, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
inline document_stream parse_many(const std::string &s, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
/**
* Parse a buffer containing many JSON documents.
@ -1170,7 +1170,7 @@ public:
* - CAPACITY if the parser does not have enough capacity and batch_size > max_capacity.
* - other json errors if parsing fails
*/
inline stream parse_many(const padded_string &s, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
inline document_stream parse_many(const padded_string &s, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
// We do not want to allow implicit conversion from C string to std::string.
really_inline simdjson_result<element> parse_many(const char *buf, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept = delete;
@ -1380,7 +1380,7 @@ private:
inline simdjson_result<size_t> read_file(const std::string &path) noexcept;
friend class parser::Iterator;
friend class stream;
friend class document_stream;
}; // class parser
} // namespace simdjson::dom

View File

@ -12,9 +12,9 @@ namespace simdjson::dom {
* Produced by parser::parse_many.
*
*/
class stream {
class document_stream {
public:
really_inline ~stream() noexcept;
really_inline ~document_stream() noexcept;
/**
* An iterator through a forward-only stream of documents.
@ -36,12 +36,12 @@ public:
really_inline bool operator!=(const iterator &other) const noexcept;
private:
iterator(stream& stream, bool finished) noexcept;
/** The stream parser we're iterating through. */
stream& _stream;
iterator(document_stream& stream, bool finished) noexcept;
/** The document_stream we're iterating through. */
document_stream& stream;
/** Whether we're finished or not. */
bool finished;
friend class stream;
friend class document_stream;
};
/**
@ -55,14 +55,14 @@ public:
private:
stream &operator=(const stream &) = delete; // Disallow copying
document_stream &operator=(const document_stream &) = delete; // Disallow copying
stream(stream &other) = delete; // Disallow copying
document_stream(document_stream &other) = delete; // Disallow copying
really_inline stream(dom::parser &parser, const uint8_t *buf, size_t len, size_t batch_size, error_code error = SUCCESS) noexcept;
really_inline document_stream(dom::parser &parser, const uint8_t *buf, size_t len, size_t batch_size, error_code error = SUCCESS) noexcept;
/**
* Parse the next document found in the buffer previously given to stream.
* Parse the next document found in the buffer previously given to document_stream.
*
* The content should be a valid JSON document encoded as UTF-8. If there is a
* UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
@ -70,7 +70,7 @@ private:
*
* You do NOT need to pre-allocate a parser. This function takes care of
* pre-allocating a capacity defined by the batch_size defined when creating the
* stream object.
* document_stream object.
*
* The function returns simdjson::SUCCESS_AND_HAS_MORE (an integer = 1) in case
* of success and indicates that the buffer still contains more data to be parsed,
@ -99,13 +99,13 @@ private:
inline size_t get_current_buffer_loc() const { return current_buffer_loc; }
/**
* Returns the total amount of complete documents parsed by the stream,
* Returns the total amount of complete documents parsed by the document_stream,
* in the current buffer, at the given time.
*/
inline size_t get_n_parsed_docs() const { return n_parsed_docs; }
/**
* Returns the total amount of data (in bytes) parsed by the stream,
* Returns the total amount of data (in bytes) parsed by the document_stream,
* in the current buffer, at the given time.
*/
inline size_t get_n_bytes_parsed() const { return n_bytes_parsed; }
@ -136,7 +136,7 @@ private:
dom::parser parser_thread;
#endif
friend class dom::parser;
}; // class stream
}; // class document_stream
} // end of namespace simdjson::dom

View File

@ -390,9 +390,9 @@ inline simdjson_result<element> parser::load(const std::string &path) noexcept {
return parse(loaded_bytes.get(), len, false);
}
inline stream parser::load_many(const std::string &path, size_t batch_size) noexcept {
inline document_stream parser::load_many(const std::string &path, size_t batch_size) noexcept {
auto [len, code] = read_file(path);
return stream(*this, (const uint8_t*)loaded_bytes.get(), len, batch_size, code);
return document_stream(*this, (const uint8_t*)loaded_bytes.get(), len, batch_size, code);
}
inline simdjson_result<element> parser::parse(const uint8_t *buf, size_t len, bool realloc_if_needed) noexcept {
@ -428,16 +428,16 @@ really_inline simdjson_result<element> parser::parse(const padded_string &s) noe
return parse(s.data(), s.length(), false);
}
inline stream parser::parse_many(const uint8_t *buf, size_t len, size_t batch_size) noexcept {
return stream(*this, buf, len, batch_size);
inline document_stream parser::parse_many(const uint8_t *buf, size_t len, size_t batch_size) noexcept {
return document_stream(*this, buf, len, batch_size);
}
inline stream parser::parse_many(const char *buf, size_t len, size_t batch_size) noexcept {
inline document_stream parser::parse_many(const char *buf, size_t len, size_t batch_size) noexcept {
return parse_many((const uint8_t *)buf, len, batch_size);
}
inline stream parser::parse_many(const std::string &s, size_t batch_size) noexcept {
inline document_stream parser::parse_many(const std::string &s, size_t batch_size) noexcept {
return parse_many(s.data(), s.length(), batch_size);
}
inline stream parser::parse_many(const padded_string &s, size_t batch_size) noexcept {
inline document_stream parser::parse_many(const padded_string &s, size_t batch_size) noexcept {
return parse_many(s.data(), s.length(), batch_size);
}

View File

@ -97,7 +97,7 @@ static inline size_t trimmed_length_safe_utf8(const char * c, size_t len) {
namespace simdjson::dom {
really_inline stream::stream(
really_inline document_stream::document_stream(
dom::parser &_parser,
const uint8_t *buf,
size_t len,
@ -107,7 +107,7 @@ really_inline stream::stream(
if (!error) { error = json_parse(); }
}
inline stream::~stream() noexcept {
inline document_stream::~document_stream() noexcept {
#ifdef SIMDJSON_THREADS_ENABLED
if (stage_1_thread.joinable()) {
stage_1_thread.join();
@ -115,34 +115,34 @@ inline stream::~stream() noexcept {
#endif
}
really_inline stream::iterator stream::begin() noexcept {
really_inline document_stream::iterator document_stream::begin() noexcept {
return iterator(*this, false);
}
really_inline stream::iterator stream::end() noexcept {
really_inline document_stream::iterator document_stream::end() noexcept {
return iterator(*this, true);
}
really_inline stream::iterator::iterator(stream& stream, bool _is_end) noexcept
: _stream{stream}, finished{_is_end} {
really_inline document_stream::iterator::iterator(document_stream& _stream, bool is_end) noexcept
: stream{_stream}, finished{is_end} {
}
really_inline simdjson_result<element> stream::iterator::operator*() noexcept {
error_code error = _stream.error == SUCCESS_AND_HAS_MORE ? SUCCESS : _stream.error;
really_inline simdjson_result<element> document_stream::iterator::operator*() noexcept {
error_code error = stream.error == SUCCESS_AND_HAS_MORE ? SUCCESS : stream.error;
if (error) { return error; }
return _stream.parser.doc.root();
return stream.parser.doc.root();
}
really_inline stream::iterator& stream::iterator::operator++() noexcept {
if (_stream.error == SUCCESS_AND_HAS_MORE) {
_stream.error = _stream.json_parse();
really_inline document_stream::iterator& document_stream::iterator::operator++() noexcept {
if (stream.error == SUCCESS_AND_HAS_MORE) {
stream.error = stream.json_parse();
} else {
finished = true;
}
return *this;
}
really_inline bool stream::iterator::operator!=(const stream::iterator &other) const noexcept {
really_inline bool document_stream::iterator::operator!=(const document_stream::iterator &other) const noexcept {
return finished != other.finished;
}
@ -150,7 +150,7 @@ really_inline bool stream::iterator::operator!=(const stream::iterator &other) c
// threaded version of json_parse
// todo: simplify this code further
inline error_code stream::json_parse() noexcept {
inline error_code document_stream::json_parse() noexcept {
error = parser.ensure_capacity(_batch_size);
if (error) { return error; }
error = parser_thread.ensure_capacity(_batch_size);
@ -232,7 +232,7 @@ inline error_code stream::json_parse() noexcept {
#else // SIMDJSON_THREADS_ENABLED
// single-threaded version of json_parse
inline error_code stream::json_parse() noexcept {
inline error_code document_stream::json_parse() noexcept {
error = parser.ensure_capacity(_batch_size);
if (error) { return error; }

View File

@ -302,14 +302,14 @@ namespace document_tests {
namespace document_stream_tests {
static simdjson::dom::stream parse_many_stream_return(simdjson::dom::parser &parser, simdjson::padded_string &str) {
static simdjson::dom::document_stream parse_many_stream_return(simdjson::dom::parser &parser, simdjson::padded_string &str) {
return parser.parse_many(str);
}
// this is a compilation test
UNUSED static void parse_many_stream_assign() {
simdjson::dom::parser parser;
simdjson::padded_string str("{}",2);
simdjson::dom::stream s1 = parse_many_stream_return(parser, str);
simdjson::dom::document_stream s1 = parse_many_stream_return(parser, str);
}
static bool parse_json_message_issue467(simdjson::padded_string &json, size_t expectedcount) {