1 #ifndef SIMDJSON_INTERNAL_DOM_PARSER_IMPLEMENTATION_H
2 #define SIMDJSON_INTERNAL_DOM_PARSER_IMPLEMENTATION_H
4 #include "simdjson/base.h"
5 #include "simdjson/error.h"
22 enum class stage1_mode { regular, streaming_partial, streaming_final};
30 return (mode != stage1_mode::regular);
44 class dom_parser_implementation {
60 simdjson_warn_unused
virtual error_code parse(
const uint8_t *buf,
size_t len, dom::document &doc) noexcept = 0;
76 simdjson_warn_unused
virtual error_code stage1(
const uint8_t *buf,
size_t len,
stage1_mode streaming) noexcept = 0;
90 simdjson_warn_unused
virtual error_code stage2(dom::document &doc) noexcept = 0;
103 simdjson_warn_unused
virtual error_code stage2_next(dom::document &doc) noexcept = 0;
120 simdjson_warn_unused
virtual uint8_t *parse_string(
const uint8_t *src, uint8_t *dst,
bool allow_replacement)
const noexcept = 0;
136 simdjson_warn_unused
virtual uint8_t *parse_wobbly_string(
const uint8_t *src, uint8_t *dst)
const noexcept = 0;
150 virtual error_code set_capacity(
size_t capacity) noexcept = 0;
161 virtual error_code set_max_depth(
size_t max_depth) noexcept = 0;
166 virtual ~dom_parser_implementation() =
default;
169 uint32_t n_structural_indexes{0};
171 std::unique_ptr<uint32_t[]> structural_indexes{};
173 uint32_t next_structural_index{0};
180 simdjson_pure simdjson_inline
size_t capacity() const noexcept;
187 simdjson_pure simdjson_inline
size_t max_depth() const noexcept;
197 simdjson_warn_unused inline
error_code allocate(
size_t capacity,
size_t max_depth) noexcept;
213 size_t _max_depth{0};
216 simdjson_inline dom_parser_implementation() noexcept;
217 simdjson_inline dom_parser_implementation(dom_parser_implementation &&other) noexcept;
218 simdjson_inline dom_parser_implementation &operator=(dom_parser_implementation &&other) noexcept;
220 simdjson_inline dom_parser_implementation(const dom_parser_implementation &) noexcept = delete;
221 simdjson_inline dom_parser_implementation &operator=(const dom_parser_implementation &other) noexcept = delete;
224 simdjson_inline dom_parser_implementation::dom_parser_implementation() noexcept = default;
225 simdjson_inline dom_parser_implementation::dom_parser_implementation(dom_parser_implementation &&other) noexcept = default;
226 simdjson_inline dom_parser_implementation &dom_parser_implementation::operator=(dom_parser_implementation &&other) noexcept = default;
228 simdjson_pure simdjson_inline
size_t dom_parser_implementation::capacity() const noexcept {
232 simdjson_pure simdjson_inline
size_t dom_parser_implementation::max_depth() const noexcept {
237 inline error_code dom_parser_implementation::allocate(
size_t capacity,
size_t max_depth) noexcept {
238 if (this->max_depth() != max_depth) {
240 if (err) {
return err; }
242 if (_capacity != capacity) {
244 if (err) {
return err; }
The top level simdjson namespace, containing everything the library provides.
bool is_streaming(stage1_mode mode)
Returns true if mode == streaming_partial or mode == streaming_final.
error_code
All possible errors returned by simdjson.
stage1_mode
This enum is used with the dom_parser_implementation::stage1 function.