2 #include "c4/yml/detail/parser_dbg.hpp"
7 C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4296)
8 C4_SUPPRESS_WARNING_MSVC(4702)
9 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
10 C4_SUPPRESS_WARNING_GCC("-Wtype-limits")
11 C4_SUPPRESS_WARNING_GCC("-Wuseless-cast")
23 return NodeRef(
this, root_id());
37 _RYML_CB_ASSERT(m_callbacks,
id !=
NONE &&
id >= 0 &&
id < m_cap);
42 _RYML_CB_ASSERT(m_callbacks,
id !=
NONE &&
id >= 0 &&
id < m_cap);
47 _RYML_CB_ASSERT(m_callbacks,
id !=
NONE &&
id >= 0 &&
id < m_cap);
53 return rootref()[
key];
57 return rootref()[
key];
136 m_callbacks = that.m_callbacks;
158 C4_SUPPRESS_WARNING_GCC_PUSH
159 #if defined(__GNUC__) && __GNUC__>= 8
160 C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wclass-memaccess")
176 void Tree::_copy(Tree
const& that)
183 m_buf = _RYML_CB_ALLOC_HINT(
m_callbacks, NodeData, (
size_t)that.m_cap, that.m_buf);
184 memcpy(
m_buf, that.m_buf, (
size_t)that.m_cap *
sizeof(NodeData));
194 _RYML_CB_ASSERT(
m_callbacks, that.m_arena.len > 0);
196 arena.str = _RYML_CB_ALLOC_HINT(
m_callbacks,
char, that.m_arena.len, that.m_arena.str);
197 arena.len = that.m_arena.len;
205 void Tree::_move(Tree & that) noexcept
207 _RYML_CB_ASSERT(m_callbacks, m_buf ==
nullptr);
208 _RYML_CB_ASSERT(m_callbacks, m_arena.str ==
nullptr);
209 _RYML_CB_ASSERT(m_callbacks, m_arena.len == 0);
212 m_size = that.m_size;
213 m_free_head = that.m_free_head;
214 m_free_tail = that.m_free_tail;
215 m_arena = that.m_arena;
216 m_arena_pos = that.m_arena_pos;
218 m_tag_directives[i] = that.m_tag_directives[i];
222 void Tree::_relocate(substr next_arena)
224 _RYML_CB_ASSERT(
m_callbacks, next_arena.not_empty());
231 n->m_key.scalar = _relocated(n->m_key.scalar, next_arena);
233 n->m_key.tag = _relocated(n->m_key.tag, next_arena);
235 n->m_key.anchor = _relocated(n->m_key.anchor, next_arena);
237 n->m_val.scalar = _relocated(n->m_val.scalar, next_arena);
239 n->m_val.tag = _relocated(n->m_val.tag, next_arena);
241 n->m_val.anchor = _relocated(n->m_val.anchor, next_arena);
246 td.prefix = _relocated(td.prefix, next_arena);
248 td.handle = _relocated(td.handle, next_arena);
267 _clear_range(first, del);
294 _clear_range(0,
m_cap);
312 void Tree::_claim_root()
326 memset(
m_buf + first, 0, (
size_t)num *
sizeof(NodeData));
327 for(
id_type i = first, e = first + num; i < e; ++i)
330 NodeData *n =
m_buf + i;
332 n->m_next_sibling = i + 1;
337 C4_SUPPRESS_WARNING_GCC_POP
354 void Tree::_free_list_add(
id_type i)
357 NodeData &C4_RESTRICT w =
m_buf[i];
361 w.m_prev_sibling =
NONE;
369 void Tree::_free_list_rem(
id_type i)
408 C4_SUPPRESS_WARNING_GCC_PUSH
409 C4_SUPPRESS_WARNING_CLANG_PUSH
410 C4_SUPPRESS_WARNING_CLANG(
"-Wnull-dereference")
411 #if defined(__GNUC__)
413 C4_SUPPRESS_WARNING_GCC(
"-Wnull-dereference")
416 C4_SUPPRESS_WARNING_GCC(
"-Wanalyzer-fd-leak")
424 _RYML_CB_ASSERT(
m_callbacks, iprev_sibling ==
NONE || (iprev_sibling >= 0 && iprev_sibling <
m_cap));
428 child->m_parent = iparent;
442 NodeData *C4_RESTRICT
parent =
get(iparent);
443 NodeData *C4_RESTRICT psib =
get(iprev_sibling);
444 NodeData *C4_RESTRICT nsib =
get(inext_sibling);
449 child->m_prev_sibling =
id(psib);
450 psib->m_next_sibling =
id(
child);
451 _RYML_CB_ASSERT(
m_callbacks, psib->m_prev_sibling != psib->m_next_sibling || psib->m_prev_sibling ==
NONE);
457 child->m_next_sibling =
id(nsib);
458 nsib->m_prev_sibling =
id(
child);
459 _RYML_CB_ASSERT(
m_callbacks, nsib->m_prev_sibling != nsib->m_next_sibling || nsib->m_prev_sibling ==
NONE);
478 C4_SUPPRESS_WARNING_GCC_POP
479 C4_SUPPRESS_WARNING_CLANG_POP
483 void Tree::_rem_hierarchy(
id_type i)
487 NodeData &C4_RESTRICT w =
m_buf[i];
490 if(w.m_parent !=
NONE)
492 NodeData &C4_RESTRICT p =
m_buf[w.m_parent];
493 if(p.m_first_child == i)
497 if(p.m_last_child == i)
499 p.m_last_child = w.m_prev_sibling;
504 if(w.m_prev_sibling !=
NONE)
506 NodeData *C4_RESTRICT prev =
get(w.m_prev_sibling);
507 prev->m_next_sibling = w.m_next_sibling;
509 if(w.m_next_sibling !=
NONE)
511 NodeData *C4_RESTRICT next =
get(w.m_next_sibling);
512 next->m_prev_sibling = w.m_prev_sibling;
533 count = _do_reorder(&i, count);
557 _swap_hierarchy(n_, m_);
563 _copy_hierarchy(n_, m_);
571 _copy_hierarchy(m_, n_);
588 if(i == ib || i == ia)
595 if(i == ib || i == ia)
600 auto & C4_RESTRICT a = *
_p(ia);
601 auto & C4_RESTRICT b = *
_p(ib);
602 auto & C4_RESTRICT pa = *
_p(a.m_parent);
603 auto & C4_RESTRICT pb = *
_p(b.m_parent);
607 if((pa.m_first_child == ib && pa.m_last_child == ia)
609 (pa.m_first_child == ia && pa.m_last_child == ib))
611 std::swap(pa.m_first_child, pa.m_last_child);
615 bool changed =
false;
616 if(pa.m_first_child == ia)
618 pa.m_first_child = ib;
621 if(pa.m_last_child == ia)
623 pa.m_last_child = ib;
626 if(pb.m_first_child == ib && !changed)
628 pb.m_first_child = ia;
630 if(pb.m_last_child == ib && !changed)
632 pb.m_last_child = ia;
638 if(pa.m_first_child == ia)
639 pa.m_first_child = ib;
640 if(pa.m_last_child == ia)
641 pa.m_last_child = ib;
642 if(pb.m_first_child == ib)
643 pb.m_first_child = ia;
644 if(pb.m_last_child == ib)
645 pb.m_last_child = ia;
647 std::swap(a.m_first_child , b.m_first_child);
648 std::swap(a.m_last_child , b.m_last_child);
650 if(a.m_prev_sibling != ib && b.m_prev_sibling != ia &&
651 a.m_next_sibling != ib && b.m_next_sibling != ia)
653 if(a.m_prev_sibling !=
NONE && a.m_prev_sibling != ib)
655 if(a.m_next_sibling !=
NONE && a.m_next_sibling != ib)
657 if(b.m_prev_sibling !=
NONE && b.m_prev_sibling != ia)
659 if(b.m_next_sibling !=
NONE && b.m_next_sibling != ia)
661 std::swap(a.m_prev_sibling, b.m_prev_sibling);
662 std::swap(a.m_next_sibling, b.m_next_sibling);
666 if(a.m_next_sibling == ib)
668 _RYML_CB_ASSERT(
m_callbacks, b.m_prev_sibling == ia);
669 if(a.m_prev_sibling !=
NONE)
671 _RYML_CB_ASSERT(
m_callbacks, a.m_prev_sibling != ib);
674 if(b.m_next_sibling !=
NONE)
676 _RYML_CB_ASSERT(
m_callbacks, b.m_next_sibling != ia);
680 b.m_prev_sibling = a.m_prev_sibling;
681 b.m_next_sibling = ia;
682 a.m_prev_sibling = ib;
683 a.m_next_sibling = ns;
685 else if(a.m_prev_sibling == ib)
687 _RYML_CB_ASSERT(
m_callbacks, b.m_next_sibling == ia);
688 if(b.m_prev_sibling !=
NONE)
690 _RYML_CB_ASSERT(
m_callbacks, b.m_prev_sibling != ia);
693 if(a.m_next_sibling !=
NONE)
695 _RYML_CB_ASSERT(
m_callbacks, a.m_next_sibling != ib);
699 a.m_prev_sibling = b.m_prev_sibling;
700 a.m_next_sibling = ib;
701 b.m_prev_sibling = ia;
702 b.m_next_sibling = ns;
709 _RYML_CB_ASSERT(
m_callbacks, a.m_next_sibling != ia);
710 _RYML_CB_ASSERT(
m_callbacks, a.m_prev_sibling != ia);
711 _RYML_CB_ASSERT(
m_callbacks, b.m_next_sibling != ib);
712 _RYML_CB_ASSERT(
m_callbacks, b.m_prev_sibling != ib);
714 if(a.m_parent != ib && b.m_parent != ia)
716 std::swap(a.m_parent, b.m_parent);
720 if(a.m_parent == ib && b.m_parent != ia)
722 a.m_parent = b.m_parent;
725 else if(a.m_parent != ib && b.m_parent == ia)
727 b.m_parent = a.m_parent;
740 auto const& C4_RESTRICT src = *
_p(src_);
741 auto & C4_RESTRICT dst = *
_p(dst_);
742 auto & C4_RESTRICT prt = *
_p(src.m_parent);
747 if(src.m_prev_sibling !=
NONE)
751 if(src.m_next_sibling !=
NONE)
755 if(prt.m_first_child == src_)
757 prt.m_first_child = dst_;
759 if(prt.m_last_child == src_)
761 prt.m_last_child = dst_;
763 dst.m_parent = src.m_parent;
764 dst.m_first_child = src.m_first_child;
765 dst.m_last_child = src.m_last_child;
766 dst.m_prev_sibling = src.m_prev_sibling;
767 dst.m_next_sibling = src.m_next_sibling;
773 NodeData &C4_RESTRICT n = *
_p(n_);
774 NodeData &C4_RESTRICT m = *
_p(m_);
775 std::swap(n.m_type, m.m_type);
776 std::swap(n.m_key, m.m_key);
777 std::swap(n.m_val, m.m_val);
789 _rem_hierarchy(node);
790 _set_hierarchy(node,
parent(node), after);
804 _rem_hierarchy(node);
805 _set_hierarchy(node, new_parent, after);
832 _copy_props_wo_key(next_doc, root);
841 _copy_props_wo_key(next_doc, root);
842 _add_flags(next_doc,
DOC);
847 move(ch, next_doc, prev);
867 if(ich ==
get(node)->m_last_child)
906 _copy_props(copy, src, node);
907 _set_hierarchy(copy,
parent, after);
946 _copy_props_wo_key(where, src, node);
983 _c4dbgpf(
"duplicate_no_rep: {} -> {}/{}", i,
parent, prev);
987 _c4dbgpf(
"duplicate_no_rep: {} is seq",
parent);
992 _c4dbgpf(
"duplicate_no_rep: {} is map",
parent);
997 csubstr srckey = src->
key(i);
1000 if(
key(j) == srckey)
1002 _c4dbgpf(
"duplicate_no_rep: found matching key '{}' src={}/{} dst={}/{}", srckey, node, i,
parent, j);
1004 dstnode_dup_pos = jcount;
1009 _c4dbgpf(
"duplicate_no_rep: dstnode_dup={} dstnode_dup_pos={} after_pos={}", dstnode_dup, dstnode_dup_pos, after_pos);
1010 if(dstnode_dup ==
NONE)
1012 _c4dbgpf(
"duplicate_no_rep: no repetition, just duplicate i={} parent={} prev={}", i,
parent, prev);
1017 if(after_pos !=
NONE && dstnode_dup_pos <= after_pos)
1021 _c4dbgpf(
"duplicate_no_dstnode_dup: replace {}/{} with {}/{}",
parent, dstnode_dup, node, i);
1022 if(prev == dstnode_dup)
1027 else if(prev ==
NONE)
1029 _c4dbgpf(
"duplicate_no_dstnode_dup: {}=prev <- {}", prev, dstnode_dup);
1033 else if(dstnode_dup != prev)
1037 _c4dbgpf(
"duplicate_no_dstnode_dup: move({}, {})", dstnode_dup, prev);
1038 move(dstnode_dup, prev);
1054 if(src_node ==
NONE)
1056 if(dst_node ==
NONE)
1070 _copy_props(dst_node, src, src_node, mask_src);
1075 _copy_props_wo_key(dst_node, src, src_node, mask_src);
1078 else if(src->
is_seq(src_node))
1084 _clear_type(dst_node);
1094 _copy_props_wo_key(dch, src, sch);
1105 _clear_type(dst_node);
1118 _copy_props(dch, src, sch);
1140 rr->resolve(
this, clear_anchors);
1179 #if defined(__clang__)
1180 # pragma clang diagnostic push
1181 # pragma GCC diagnostic ignored "-Wnull-dereference"
1182 #elif defined(__GNUC__)
1183 # pragma GCC diagnostic push
1185 # pragma GCC diagnostic ignored "-Wnull-dereference"
1188 # pragma GCC diagnostic ignored "-Wanalyzer-null-dereference"
1196 if(
get(node)->m_first_child ==
NONE)
1215 #if defined(__clang__)
1216 # pragma clang diagnostic pop
1217 #elif defined(__GNUC__)
1218 # pragma GCC diagnostic pop
1224 maxdepth = currdepth > maxdepth ? currdepth : maxdepth;
1225 for(
id_type child = t.first_child(
id); child !=
NONE; child = t.next_sibling(child))
1227 const id_type d = depth_desc_(t, child, currdepth+1, maxdepth);
1228 maxdepth = d > maxdepth ? d : maxdepth;
1237 return depth_desc_(*
this, node);
1272 _set_flags(node,
VAL|more_flags);
1281 _set_flags(node,
KEYVAL|more_flags);
1290 _set_flags(node,
MAP|more_flags);
1299 _set_flags(node,
KEY|
MAP|more_flags);
1308 _set_flags(node,
SEQ|more_flags);
1317 _set_flags(node,
KEY|
SEQ|more_flags);
1325 _set_flags(node,
DOC|more_flags);
1333 _set_flags(node,
STREAM|more_flags);
1362 _RYML_CB_CHECK(
m_callbacks, td.
handle ==
'!' || td.
handle ==
"!!" || td.
handle.trim(
'!').first_not_of(
"01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-") ==
npos);
1388 if(td.handle.empty())
1390 if(tag.begins_with(td.handle) && td.next_node_id <= node_id)
1393 if(tag.begins_with(
'!'))
1397 _RYML_CB_ERR(
m_callbacks,
"tag directive not found");
1404 csubstr _transform_tag(
Tree *t, csubstr tag,
id_type node)
1406 _c4dbgpf(
"[{}] resolving tag ~~~{}~~~", node, tag);
1407 size_t required_size = t->
resolve_tag(substr{}, tag, node);
1410 if(tag.begins_with(
"!<"))
1412 _c4dbgpf(
"[{}] resolved tag: ~~~{}~~~", node, tag);
1415 const char *prev_arena = t->
arena().str;(void)prev_arena;
1418 size_t actual_size = t->
resolve_tag(buf, tag, node);
1419 _RYML_CB_ASSERT(t->
m_callbacks, actual_size <= required_size);
1420 _c4dbgpf(
"[{}] resolved tag: ~~~{}~~~", node, buf.first(actual_size));
1421 return buf.first(actual_size);
1423 void _resolve_tags(Tree *t,
id_type node)
1425 NodeData *C4_RESTRICT d = t->_p(node);
1427 d->m_key.tag = _transform_tag(t, d->m_key.tag, node);
1429 d->m_val.tag = _transform_tag(t, d->m_val.tag, node);
1430 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1431 _resolve_tags(t, child);
1433 size_t _count_resolved_tags_size(Tree
const* t,
id_type node)
1436 NodeData
const* C4_RESTRICT d = t->_p(node);
1438 sz += t->resolve_tag(substr{}, d->m_key.tag, node);
1440 sz += t->resolve_tag(substr{}, d->m_val.tag, node);
1441 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1442 sz += _count_resolved_tags_size(t, child);
1445 void _normalize_tags(Tree *t,
id_type node)
1447 NodeData *C4_RESTRICT d = t->_p(node);
1452 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1453 _normalize_tags(t, child);
1455 void _normalize_tags_long(Tree *t,
id_type node)
1457 NodeData *C4_RESTRICT d = t->_p(node);
1462 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1463 _normalize_tags_long(t, child);
1471 size_t needed_size = _count_resolved_tags_size(
this,
root_id());
1474 _resolve_tags(
this,
root_id());
1481 _normalize_tags(
this,
root_id());
1488 _normalize_tags_long(
this,
root_id());
1497 if(p.ends_with(
'.'))
1498 p = p.first(p.len-1);
1504 return path.sub(path_pos);
1529 id_type target = _lookup_path_or_create(path, start);
1533 to_val(target, default_value);
1539 id_type target = _lookup_path_or_create(path, start);
1544 id_type Tree::_lookup_path_or_create(csubstr path,
id_type start)
1548 lookup_result r(path, start);
1555 _lookup_path_modify(&r);
1559 void Tree::_lookup_path(lookup_result *r)
const
1561 C4_ASSERT( ! r->unresolved().empty());
1562 _lookup_path_token
parent{
"",
type(r->closest)};
1566 node = _next_node(r, &
parent);
1569 if(r->unresolved().empty())
1574 }
while(node !=
NONE);
1577 void Tree::_lookup_path_modify(lookup_result *r)
1579 C4_ASSERT( ! r->unresolved().empty());
1580 _lookup_path_token
parent{
"",
type(r->closest)};
1584 node = _next_node_modify(r, &
parent);
1587 if(r->unresolved().empty())
1592 }
while(node !=
NONE);
1595 id_type Tree::_next_node(lookup_result * r, _lookup_path_token *
parent)
const
1597 _lookup_path_token token = _next_token(r, *
parent);
1602 csubstr prev = token.value;
1603 if(token.type ==
MAP || token.type ==
SEQ)
1605 _RYML_CB_ASSERT(
m_callbacks, !token.value.begins_with(
'['));
1610 else if(token.type ==
KEYVAL)
1612 _RYML_CB_ASSERT(
m_callbacks, r->unresolved().empty());
1616 else if(token.type ==
KEY)
1618 _RYML_CB_ASSERT(
m_callbacks, token.value.begins_with(
'[') && token.value.ends_with(
']'));
1619 token.value = token.value.offs(1, 1).trim(
' ');
1622 node =
child(r->closest, idx);
1635 csubstr p = r->path.sub(r->path_pos > 0 ? r->path_pos - 1 : r->path_pos);
1636 r->path_pos -= prev.len;
1637 if(p.begins_with(
'.'))
1644 id_type Tree::_next_node_modify(lookup_result * r, _lookup_path_token *
parent)
1646 _lookup_path_token token = _next_token(r, *
parent);
1651 if(token.type ==
MAP || token.type ==
SEQ)
1653 _RYML_CB_ASSERT(
m_callbacks, !token.value.begins_with(
'['));
1671 node =
child(r->closest, pos);
1678 NodeData *n =
_p(node);
1679 n->m_key.scalar = token.value;
1683 else if(token.type ==
KEYVAL)
1685 _RYML_CB_ASSERT(
m_callbacks, r->unresolved().empty());
1695 _add_flags(r->closest,
MAP);
1698 NodeData *n =
_p(node);
1699 n->m_key.scalar = token.value;
1700 n->m_val.scalar =
"";
1703 else if(token.type ==
KEY)
1705 _RYML_CB_ASSERT(
m_callbacks, token.value.begins_with(
'[') && token.value.ends_with(
']'));
1706 token.value = token.value.offs(1, 1).trim(
' ');
1714 csubstr k =
key(r->closest);
1715 _clear_type(r->closest);
1720 _clear_type(r->closest);
1725 node =
child(r->closest, idx);
1736 else if(
is_seq(r->closest))
1758 Tree::_lookup_path_token Tree::_next_token(lookup_result *r, _lookup_path_token
const&
parent)
const
1760 csubstr unres = r->unresolved();
1765 if(unres.begins_with(
'['))
1767 size_t pos = unres.find(
']');
1770 csubstr idx = unres.first(pos + 1);
1771 _advance(r, pos + 1);
1776 size_t pos = unres.first_of(
".[");
1779 _advance(r, unres.len);
1782 return {unres,
VAL};
1787 _RYML_CB_ASSERT(
m_callbacks, unres[pos] ==
'.' || unres[pos] ==
'[');
1788 if(unres[pos] ==
'.')
1791 _advance(r, pos + 1);
1792 return {unres.first(pos),
MAP};
1797 return {unres.first(pos),
SEQ};
1805 C4_SUPPRESS_WARNING_GCC_CLANG_POP
1806 C4_SUPPRESS_WARNING_MSVC_POP
Holds a pointer to an existing tree, and a node id.
A reference to a node in an existing yaml tree, offering a more convenient API than the index-based A...
void move(id_type node, id_type after)
change the node's position in the parent
void reserve_arena(size_t arena_cap)
ensure the tree's internal string arena is at least the given capacity
id_type duplicate(id_type node, id_type new_parent, id_type after)
recursively duplicate a node from this tree into a new parent, placing it after one of its children
void clear()
clear the tree and zero every node
lookup_result lookup_path(csubstr path, id_type start=NONE) const
for example foo.bar[0].baz
id_type lookup_path_or_modify(csubstr default_value, csubstr path, id_type start=NONE)
defaulted lookup: lookup path; if the lookup fails, recursively modify the tree so that the correspon...
id_type first_child(id_type node) const
bool is_stream(id_type node) const
NodeType type(id_type node) const
void set_root_as_stream()
ensure the first node is a stream.
id_type prev_sibling(id_type node) const
NodeData * get(id_type node)
get a pointer to a node's NodeData. i can be NONE, in which case a nullptr is returned
bool is_map(id_type node) const
void clear_tag_directives()
Tree & operator=(Tree const &that)
void to_keyval(id_type node, csubstr key, csubstr val, type_bits more_flags=0)
bool is_root(id_type node) const
substr alloc_arena(size_t sz)
grow the tree's string arena by the given size and return a substr of the added portion
bool is_keyval(id_type node) const
TagDirective m_tag_directives[RYML_MAX_TAG_DIRECTIVES]
void reserve(id_type node_capacity)
void to_doc(id_type node, type_bits more_flags=0)
bool has_key(id_type node) const
id_type depth_asc(id_type node) const
O(log(num_tree_nodes)) get the ascending depth of the node: number of levels between root and node.
bool in_arena(csubstr s) const
return true if the given substring is part of the tree's string arena
id_type parent(id_type node) const
size_t resolve_tag(substr output, csubstr tag, id_type node_id) const
resolve the given tag, appearing at node_id.
bool add_tag_directive(csubstr directive)
bool is_val(id_type node) const
id_type child_pos(id_type node, id_type ch) const
id_type append_child(id_type parent)
create and insert a node as the last child of parent
void to_stream(id_type node, type_bits more_flags=0)
bool has_sibling(id_type node, id_type sib) const
true if node has a sibling with id sib
id_type next_sibling(id_type node) const
void to_seq(id_type node, csubstr key, type_bits more_flags=0)
id_type depth_desc(id_type node) const
O(num_tree_nodes) get the descending depth of the node: number of levels between node and deepest chi...
id_type num_tag_directives() const
bool parent_is_seq(id_type node) const
csubstr const & key(id_type node) const
id_type duplicate_children_no_rep(id_type node, id_type parent, id_type after)
duplicate the node's children (but not the node) in a new parent, but omit repetitions where a duplic...
id_type last_child(id_type node) const
id_type id(NodeData const *n) const
get the index of a node belonging to this tree. n can be nullptr, in which case NONE is returned
void reorder()
reorder the tree in memory so that all the nodes are stored in a linear sequence when visited in dept...
void remove_children(id_type node)
remove all the node's children, but keep the node itself
bool is_ancestor(id_type node, id_type ancestor) const
true when ancestor is parent or parent of a parent of node
bool has_val(id_type node) const
void to_map(id_type node, csubstr key, type_bits more_flags=0)
size_t arena_capacity() const
get the current capacity of the tree's internal arena
bool change_type(id_type node, NodeType type)
change the type of the node to one of MAP, SEQ or VAL.
void normalize_tags_long()
csubstr const & val(id_type node) const
void resolve(ReferenceResolver *rr, bool clear_anchors=true)
Resolve references (aliases <- anchors), by forwarding to ReferenceResolver::resolve(); refer to Refe...
bool is_seq(id_type node) const
bool parent_is_map(id_type node) const
void remove(id_type node)
remove an entire branch at once: ie remove the children and the node itself
id_type find_child(id_type node, csubstr const &key) const
void duplicate_contents(id_type node, id_type where)
id_type root_id()
Get the id of the root node.
id_type duplicate_children(id_type node, id_type parent, id_type after)
recursively duplicate the node's children (but not the node)
id_type num_children(id_type node) const
O(num_children)
csubstr arena() const
get the current arena
void merge_with(Tree const *src, id_type src_node=NONE, id_type dst_root=NONE)
bool is_container(id_type node) const
size_t arena_size() const
get the current size of the tree's internal arena
id_type child(id_type node, id_type pos) const
bool has_child(id_type node, id_type ch) const
true if node has a child with id ch
NodeData * _p(id_type node)
An if-less form of get() that demands a valid node index. This function is implementation only; use a...
void to_val(id_type node, csubstr val, type_bits more_flags=0)
bool has_children(id_type node) const
true if node has any children key
bool atox(csubstr s, uint8_t *v) noexcept
bool from_chars(csubstr buf, uint8_t *v) noexcept
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
@ NOTYPE
no node type or style is set
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
@ STREAM
a stream: a seq of docs
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
@ KEYTAG
the key has a tag
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
@ VALTAG
the val has a tag
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
bool is_custom_tag(csubstr tag)
csubstr normalize_tag_long(csubstr tag)
csubstr normalize_tag(csubstr tag)
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
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...
@ npos
a null string position
a c-style callbacks class.
contains the data for each YAML node.
wraps a NodeType_e element with some syntactic sugar and predicates
bool has_key() const noexcept
bool is_seq() const noexcept
void rem(NodeType_e t) noexcept
bool is_map() const noexcept
void add(NodeType_e t) noexcept
bool is_val() const noexcept
Reusable object to resolve references/aliases in a Tree.
bool create_from_str(csubstr directive_)
leaves next_node_id unfilled
size_t transform(csubstr tag, substr output, Callbacks const &callbacks) const
csubstr unresolved() const
get the part ot the input path that was unresolved
csubstr resolved() const
get the part ot the input path that was resolved