36template <
typename TContainer>
40 using element_type =
typename TContainer::value_type;
44 virtual std::expected<TContainer, ast_node_type>
51 return std::unexpected(opened.error());
58 detail::reserve_if_possible(out, opened->element_count());
60 bool recovered =
false;
70 for (std::size_t idx = 0U; from.
good(); ++idx)
77 type == ast_node_type::document_end || type == ast_node_type::error)
79 return context.problem(
context.problem_path(from),
"Unterminated array");
95 context.note_value_consumed(from);
96 return std::unexpected(ast_node_type::error);
106 auto element = [&] () -> std::expected<element_type, ast_node_type>
110 return context.deserialize<element_type>(from);
119 return std::unexpected(element.error());
122 context.skip_failed_value(from);
126 out.insert(end(out), *std::move(element));
144 if (type == ast_node_type::array_end)
149 else if (type == ast_node_type::document_end || type == ast_node_type::error)
160 context.note_value_consumed(from);
166 return context.problem(
context.problem_path(from),
"Unterminated array");
172 for (
const element_type& x : from)
Copyright (c) 2015-2026 by Travis Gockel.
Utilities for directly dealing with a JSON AST.
An adapter for the type T.
The beginning of an kind::array ([).
An adapter for container types.
virtual void serialize(const serialization_context &context, const TContainer &from, writer &to) const override
Write from into to.
virtual std::expected< TContainer, ast_node_type > create(deserialization_context &context, reader &from) const override
Create an instance of T by reading from.
Provides extra information to routines used for deserialization and serialization.
An RAII guard naming one step of the deserialization path while it is alive.
Provides extra information to routines used for deserialization, collects the problems they encounter...
A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON...
bool next_value() noexcept
Go to one past the value this reader is on.
ast_node_type current_type() const
Get the type of the current AST node, which is always current().type().
bool next_token() noexcept
Go to the next token.
bool good() const
Check if this reader is still good to read from.
Provides extra information to routines used for serialization: the formats to find other serializers ...
A writer instance writes a JSON ast_node sequence to some form of sink: an encoder,...
writer & array_begin()
Write the token which opens or closes an object or an array.
writer & array_end()
Write the token which opens or closes an object or an array.
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
Definition of the reserve_if_possible utility.
Conversion between C++ types and JSON values.