6192{
6194 "---" "\n"
6195 "a: 0" "\n"
6196 "b: 1" "\n"
6197 "---" "\n"
6198 "c: 2" "\n"
6199 "d: 3" "\n"
6200 "---" "\n"
6201 "- 4" "\n"
6202 "- 5" "\n"
6203 "- 6" "\n"
6204 "- 7" "\n"
6205 "";
6208
6209
6210 {
6211
6218 CHECK(doc.is_doc());
6222
6235
6236
6237 CHECK(stream[0].is_doc());
6238 CHECK(stream[0].is_map());
6239 CHECK(stream[0][
"a"].val() ==
"0");
6240 CHECK(stream[0][
"b"].val() ==
"1");
6241
6247
6248
6249 CHECK(stream[1].is_doc());
6250 CHECK(stream[1].is_map());
6251 CHECK(stream[1][
"c"].val() ==
"2");
6252 CHECK(stream[1][
"d"].val() ==
"3");
6253
6259
6260
6261 CHECK(stream[2].is_doc());
6262 CHECK(stream[2].is_seq());
6263 CHECK(stream[2][0].val() ==
"4");
6264 CHECK(stream[2][1].val() ==
"5");
6265 CHECK(stream[2][2].val() ==
"6");
6266 CHECK(stream[2][3].val() ==
"7");
6267
6275 }
6276
6277
6279 "[" "\n"
6280 " {" "\n"
6281 " \"a\": 0," "\n"
6282 " \"b\": 1" "\n"
6283 " }," "\n"
6284 " {" "\n"
6285 " \"c\": 2," "\n"
6286 " \"d\": 3" "\n"
6287 " }," "\n"
6288 " [" "\n"
6289 " 4," "\n"
6290 " 5," "\n"
6291 " 6," "\n"
6292 " 7" "\n"
6293 " ]" "\n"
6294 "]\n"
6295 "");
6296
6297
6298 {
6304 return ryml::emitrs_json<std::string>(err_tree, err_opts);
6305 }));
6306
6307
6308 const std::string expected_json[] = {
6309 "{" "\n"
6310 " \"a\": 0," "\n"
6311 " \"b\": 1" "\n"
6312 "}" "\n"
6313 ,
6314 "{" "\n"
6315 " \"c\": 2," "\n"
6316 " \"d\": 3" "\n"
6317 "}" "\n"
6318 ,
6319 "[" "\n"
6320 " 4," "\n"
6321 " 5," "\n"
6322 " 6," "\n"
6323 " 7" "\n"
6324 "]" "\n"
6325 };
6331 }
6332}
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).