6276{
6278 "---" "\n"
6279 "a: 0" "\n"
6280 "b: 1" "\n"
6281 "---" "\n"
6282 "c: 2" "\n"
6283 "d: 3" "\n"
6284 "---" "\n"
6285 "- 4" "\n"
6286 "- 5" "\n"
6287 "- 6" "\n"
6288 "- 7" "\n"
6289 "";
6292
6293
6294 {
6295
6302 CHECK(doc.is_doc());
6306
6319
6320
6321 CHECK(stream[0].is_doc());
6322 CHECK(stream[0].is_map());
6323 CHECK(stream[0][
"a"].val() ==
"0");
6324 CHECK(stream[0][
"b"].val() ==
"1");
6325
6331
6332
6333 CHECK(stream[1].is_doc());
6334 CHECK(stream[1].is_map());
6335 CHECK(stream[1][
"c"].val() ==
"2");
6336 CHECK(stream[1][
"d"].val() ==
"3");
6337
6343
6344
6345 CHECK(stream[2].is_doc());
6346 CHECK(stream[2].is_seq());
6347 CHECK(stream[2][0].val() ==
"4");
6348 CHECK(stream[2][1].val() ==
"5");
6349 CHECK(stream[2][2].val() ==
"6");
6350 CHECK(stream[2][3].val() ==
"7");
6351
6359 }
6360
6361
6363 "[" "\n"
6364 " {" "\n"
6365 " \"a\": 0," "\n"
6366 " \"b\": 1" "\n"
6367 " }," "\n"
6368 " {" "\n"
6369 " \"c\": 2," "\n"
6370 " \"d\": 3" "\n"
6371 " }," "\n"
6372 " [" "\n"
6373 " 4," "\n"
6374 " 5," "\n"
6375 " 6," "\n"
6376 " 7" "\n"
6377 " ]" "\n"
6378 "]\n"
6379 "");
6380
6381
6382 {
6388 return ryml::emitrs_json<std::string>(err_tree, err_opts);
6389 }));
6390
6391
6392 const std::string expected_json[] = {
6393 "{" "\n"
6394 " \"a\": 0," "\n"
6395 " \"b\": 1" "\n"
6396 "}" "\n"
6397 ,
6398 "{" "\n"
6399 " \"c\": 2," "\n"
6400 " \"d\": 3" "\n"
6401 "}" "\n"
6402 ,
6403 "[" "\n"
6404 " 4," "\n"
6405 " 5," "\n"
6406 " 6," "\n"
6407 " 7" "\n"
6408 "]" "\n"
6409 };
6415 }
6416}
Holds a pointer to an existing tree, and a node id.
ConstNodeRef child(id_type pos) const RYML_NOEXCEPT
Forward to Tree::child().
id_type id() const noexcept
const_children_view children() const RYML_NOEXCEPT
get an iterable view over children
id_type id() const noexcept
id_type first_child(id_type node) const
bool is_stream(id_type node) const
id_type root_id() const
Get the id of the root node. The tree must not be empty. The tree can be empty only when constructed ...
NodeRef rootref()
Get the root as a NodeRef . Note that a non-const Tree implicitly converts to NodeRef.
bool is_map(id_type node) const
csubstr const & val(id_type node) const
bool is_root(id_type node) const
id_type next_sibling(id_type node) const
NodeRef docref(id_type i)
get the i-th document of the stream
bool is_doc(id_type node) const
Callbacks const & callbacks() const
id_type doc(id_type i) const
gets the i document node index.
bool is_seq(id_type node) const
id_type find_child(id_type node, csubstr const &key) const
find child by name, or NONE if no child is found with this key like Tree::child(),...
id_type num_children(id_type node) const
O(num_children).
id_type child(id_type node, id_type pos) const
find child by position, or NONE if there are less than pos children posi
substr emitrs_json(Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
(1) emit+resize: emit JSON to the given std::string/std::vector<char>-like container,...
substr emitrs_yaml(Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
(1) emit+resize: emit YAML to the given std::string/std::vector<char>-like container,...
void parse_in_arena(Parser *parser, csubstr filename, csubstr yaml, Tree *tree, id_type node_id)
(1) parse YAML into an existing tree node. The filename will be used in any error messages arising du...
bool check_error_occurs(Fn &&fn)
checking that an error occurs while calling fn
#define CHECK(predicate)
a testing assertion, used only in this quickstart
ryml::Callbacks callbacks()
a helper to create the Callbacks object for the custom error handler
basic_substring< const char > csubstr
an immutable string view
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Shows how to create a scoped error handler.
A lightweight object containing options to be used when emitting.
EmitOptions & json_err_on_stream(bool enabled) noexcept
Whether to trigger an error (or emit as seq) when finding a stream in json mode.
bool is_root() const RYML_NOEXCEPT
Forward to Tree::is_root().
bool is_stream() const RYML_NOEXCEPT
Forward to Tree::is_stream().
bool is_doc() const RYML_NOEXCEPT
Forward to Tree::is_doc().
id_type num_children() const RYML_NOEXCEPT
O(num_children).