2 #include "c4/yml/detail/parser_dbg.hpp"
7 C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4296)
8 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
9 C4_SUPPRESS_WARNING_GCC("-Wtype-limits")
10 C4_SUPPRESS_WARNING_GCC("-Wuseless-cast")
22 return NodeRef(
this, root_id());
36 _RYML_CB_ASSERT(m_callbacks,
id !=
NONE &&
id >= 0 &&
id < m_cap);
41 _RYML_CB_ASSERT(m_callbacks,
id !=
NONE &&
id >= 0 &&
id < m_cap);
46 _RYML_CB_ASSERT(m_callbacks,
id !=
NONE &&
id >= 0 &&
id < m_cap);
52 return rootref()[
key];
56 return rootref()[
key];
130 m_callbacks = that.m_callbacks;
151 C4_SUPPRESS_WARNING_GCC_PUSH
152 #if defined(__GNUC__) && __GNUC__>= 8
153 C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wclass-memaccess")
169 void Tree::_copy(Tree
const& that)
176 m_buf = _RYML_CB_ALLOC_HINT(
m_callbacks, NodeData, (
size_t)that.m_cap, that.m_buf);
177 memcpy(
m_buf, that.m_buf, (
size_t)that.m_cap *
sizeof(NodeData));
187 _RYML_CB_ASSERT(
m_callbacks, that.m_arena.len > 0);
189 arena.str = _RYML_CB_ALLOC_HINT(
m_callbacks,
char, that.m_arena.len, that.m_arena.str);
190 arena.len = that.m_arena.len;
198 void Tree::_move(Tree & that) noexcept
200 _RYML_CB_ASSERT(m_callbacks, m_buf ==
nullptr);
201 _RYML_CB_ASSERT(m_callbacks, m_arena.str ==
nullptr);
202 _RYML_CB_ASSERT(m_callbacks, m_arena.len == 0);
205 m_size = that.m_size;
206 m_free_head = that.m_free_head;
207 m_free_tail = that.m_free_tail;
208 m_arena = that.m_arena;
209 m_arena_pos = that.m_arena_pos;
211 m_tag_directives[i] = that.m_tag_directives[i];
215 void Tree::_relocate(substr next_arena)
217 _RYML_CB_ASSERT(
m_callbacks, next_arena.not_empty());
224 n->m_key.scalar = _relocated(n->m_key.scalar, next_arena);
226 n->m_key.tag = _relocated(n->m_key.tag, next_arena);
228 n->m_key.anchor = _relocated(n->m_key.anchor, next_arena);
230 n->m_val.scalar = _relocated(n->m_val.scalar, next_arena);
232 n->m_val.tag = _relocated(n->m_val.tag, next_arena);
234 n->m_val.anchor = _relocated(n->m_val.anchor, next_arena);
239 td.prefix = _relocated(td.prefix, next_arena);
241 td.handle = _relocated(td.handle, next_arena);
260 _clear_range(first, del);
287 _clear_range(0,
m_cap);
305 void Tree::_claim_root()
319 memset(
m_buf + first, 0, (
size_t)num *
sizeof(NodeData));
320 for(
id_type i = first, e = first + num; i < e; ++i)
323 NodeData *n =
m_buf + i;
325 n->m_next_sibling = i + 1;
330 C4_SUPPRESS_WARNING_GCC_POP
347 void Tree::_free_list_add(
id_type i)
350 NodeData &C4_RESTRICT w =
m_buf[i];
354 w.m_prev_sibling =
NONE;
362 void Tree::_free_list_rem(
id_type i)
401 C4_SUPPRESS_WARNING_GCC_PUSH
402 C4_SUPPRESS_WARNING_CLANG_PUSH
403 C4_SUPPRESS_WARNING_CLANG(
"-Wnull-dereference")
404 #if defined(__GNUC__)
406 C4_SUPPRESS_WARNING_GCC(
"-Wnull-dereference")
409 C4_SUPPRESS_WARNING_GCC(
"-Wanalyzer-fd-leak")
417 _RYML_CB_ASSERT(
m_callbacks, iprev_sibling ==
NONE || (iprev_sibling >= 0 && iprev_sibling <
m_cap));
421 child->m_parent = iparent;
435 NodeData *C4_RESTRICT
parent =
get(iparent);
436 NodeData *C4_RESTRICT psib =
get(iprev_sibling);
437 NodeData *C4_RESTRICT nsib =
get(inext_sibling);
442 child->m_prev_sibling =
id(psib);
443 psib->m_next_sibling =
id(
child);
444 _RYML_CB_ASSERT(
m_callbacks, psib->m_prev_sibling != psib->m_next_sibling || psib->m_prev_sibling ==
NONE);
450 child->m_next_sibling =
id(nsib);
451 nsib->m_prev_sibling =
id(
child);
452 _RYML_CB_ASSERT(
m_callbacks, nsib->m_prev_sibling != nsib->m_next_sibling || nsib->m_prev_sibling ==
NONE);
471 C4_SUPPRESS_WARNING_GCC_POP
472 C4_SUPPRESS_WARNING_CLANG_POP
476 void Tree::_rem_hierarchy(
id_type i)
480 NodeData &C4_RESTRICT w =
m_buf[i];
483 if(w.m_parent !=
NONE)
485 NodeData &C4_RESTRICT p =
m_buf[w.m_parent];
486 if(p.m_first_child == i)
490 if(p.m_last_child == i)
492 p.m_last_child = w.m_prev_sibling;
497 if(w.m_prev_sibling !=
NONE)
499 NodeData *C4_RESTRICT prev =
get(w.m_prev_sibling);
500 prev->m_next_sibling = w.m_next_sibling;
502 if(w.m_next_sibling !=
NONE)
504 NodeData *C4_RESTRICT next =
get(w.m_next_sibling);
505 next->m_prev_sibling = w.m_prev_sibling;
525 count = _do_reorder(&i, count);
547 _swap_hierarchy(n_, m_);
553 _copy_hierarchy(n_, m_);
561 _copy_hierarchy(m_, n_);
578 if(i == ib || i == ia)
585 if(i == ib || i == ia)
590 auto & C4_RESTRICT a = *
_p(ia);
591 auto & C4_RESTRICT b = *
_p(ib);
592 auto & C4_RESTRICT pa = *
_p(a.m_parent);
593 auto & C4_RESTRICT pb = *
_p(b.m_parent);
597 if((pa.m_first_child == ib && pa.m_last_child == ia)
599 (pa.m_first_child == ia && pa.m_last_child == ib))
601 std::swap(pa.m_first_child, pa.m_last_child);
605 bool changed =
false;
606 if(pa.m_first_child == ia)
608 pa.m_first_child = ib;
611 if(pa.m_last_child == ia)
613 pa.m_last_child = ib;
616 if(pb.m_first_child == ib && !changed)
618 pb.m_first_child = ia;
620 if(pb.m_last_child == ib && !changed)
622 pb.m_last_child = ia;
628 if(pa.m_first_child == ia)
629 pa.m_first_child = ib;
630 if(pa.m_last_child == ia)
631 pa.m_last_child = ib;
632 if(pb.m_first_child == ib)
633 pb.m_first_child = ia;
634 if(pb.m_last_child == ib)
635 pb.m_last_child = ia;
637 std::swap(a.m_first_child , b.m_first_child);
638 std::swap(a.m_last_child , b.m_last_child);
640 if(a.m_prev_sibling != ib && b.m_prev_sibling != ia &&
641 a.m_next_sibling != ib && b.m_next_sibling != ia)
643 if(a.m_prev_sibling !=
NONE && a.m_prev_sibling != ib)
645 if(a.m_next_sibling !=
NONE && a.m_next_sibling != ib)
647 if(b.m_prev_sibling !=
NONE && b.m_prev_sibling != ia)
649 if(b.m_next_sibling !=
NONE && b.m_next_sibling != ia)
651 std::swap(a.m_prev_sibling, b.m_prev_sibling);
652 std::swap(a.m_next_sibling, b.m_next_sibling);
656 if(a.m_next_sibling == ib)
658 _RYML_CB_ASSERT(
m_callbacks, b.m_prev_sibling == ia);
659 if(a.m_prev_sibling !=
NONE)
661 _RYML_CB_ASSERT(
m_callbacks, a.m_prev_sibling != ib);
664 if(b.m_next_sibling !=
NONE)
666 _RYML_CB_ASSERT(
m_callbacks, b.m_next_sibling != ia);
670 b.m_prev_sibling = a.m_prev_sibling;
671 b.m_next_sibling = ia;
672 a.m_prev_sibling = ib;
673 a.m_next_sibling = ns;
675 else if(a.m_prev_sibling == ib)
677 _RYML_CB_ASSERT(
m_callbacks, b.m_next_sibling == ia);
678 if(b.m_prev_sibling !=
NONE)
680 _RYML_CB_ASSERT(
m_callbacks, b.m_prev_sibling != ia);
683 if(a.m_next_sibling !=
NONE)
685 _RYML_CB_ASSERT(
m_callbacks, a.m_next_sibling != ib);
689 a.m_prev_sibling = b.m_prev_sibling;
690 a.m_next_sibling = ib;
691 b.m_prev_sibling = ia;
692 b.m_next_sibling = ns;
699 _RYML_CB_ASSERT(
m_callbacks, a.m_next_sibling != ia);
700 _RYML_CB_ASSERT(
m_callbacks, a.m_prev_sibling != ia);
701 _RYML_CB_ASSERT(
m_callbacks, b.m_next_sibling != ib);
702 _RYML_CB_ASSERT(
m_callbacks, b.m_prev_sibling != ib);
704 if(a.m_parent != ib && b.m_parent != ia)
706 std::swap(a.m_parent, b.m_parent);
710 if(a.m_parent == ib && b.m_parent != ia)
712 a.m_parent = b.m_parent;
715 else if(a.m_parent != ib && b.m_parent == ia)
717 b.m_parent = a.m_parent;
730 auto const& C4_RESTRICT src = *
_p(src_);
731 auto & C4_RESTRICT dst = *
_p(dst_);
732 auto & C4_RESTRICT prt = *
_p(src.m_parent);
737 if(src.m_prev_sibling !=
NONE)
741 if(src.m_next_sibling !=
NONE)
745 if(prt.m_first_child == src_)
747 prt.m_first_child = dst_;
749 if(prt.m_last_child == src_)
751 prt.m_last_child = dst_;
753 dst.m_parent = src.m_parent;
754 dst.m_first_child = src.m_first_child;
755 dst.m_last_child = src.m_last_child;
756 dst.m_prev_sibling = src.m_prev_sibling;
757 dst.m_next_sibling = src.m_next_sibling;
763 NodeData &C4_RESTRICT n = *
_p(n_);
764 NodeData &C4_RESTRICT m = *
_p(m_);
765 std::swap(n.m_type, m.m_type);
766 std::swap(n.m_key, m.m_key);
767 std::swap(n.m_val, m.m_val);
778 _rem_hierarchy(node);
779 _set_hierarchy(node,
parent(node), after);
793 _rem_hierarchy(node);
794 _set_hierarchy(node, new_parent, after);
821 _copy_props_wo_key(next_doc, root);
830 _copy_props_wo_key(next_doc, root);
831 _add_flags(next_doc,
DOC);
836 move(ch, next_doc, prev);
856 if(ich ==
get(node)->m_last_child)
895 _copy_props(copy, src, node);
896 _set_hierarchy(copy,
parent, after);
935 _copy_props_wo_key(where, src, node);
996 if(after_pos !=
NONE && rep_pos < after_pos)
1003 else if(prev ==
NONE)
1008 else if(rep != prev)
1028 if(src_node ==
NONE)
1030 if(dst_node ==
NONE)
1044 _copy_props(dst_node, src, src_node, mask_src);
1049 _copy_props_wo_key(dst_node, src, src_node, mask_src);
1052 else if(src->
is_seq(src_node))
1058 _clear_type(dst_node);
1068 _copy_props_wo_key(dch, src, sch);
1079 _clear_type(dst_node);
1092 _copy_props(dch, src, sch);
1153 #if defined(__clang__)
1154 # pragma clang diagnostic push
1155 # pragma GCC diagnostic ignored "-Wnull-dereference"
1156 #elif defined(__GNUC__)
1157 # pragma GCC diagnostic push
1159 # pragma GCC diagnostic ignored "-Wnull-dereference"
1162 # pragma GCC diagnostic ignored "-Wanalyzer-null-dereference"
1170 if(
get(node)->m_first_child ==
NONE)
1189 #if defined(__clang__)
1190 # pragma clang diagnostic pop
1191 #elif defined(__GNUC__)
1192 # pragma GCC diagnostic pop
1198 maxdepth = currdepth > maxdepth ? currdepth : maxdepth;
1199 for(
id_type child = t.first_child(
id); child !=
NONE; child = t.next_sibling(child))
1201 const id_type d = depth_desc_(t, child, currdepth+1, maxdepth);
1202 maxdepth = d > maxdepth ? d : maxdepth;
1211 return depth_desc_(*
this, node);
1233 _set_flags(node,
VAL|more_flags);
1242 _set_flags(node,
KEYVAL|more_flags);
1251 _set_flags(node,
MAP|more_flags);
1260 _set_flags(node,
KEY|
MAP|more_flags);
1269 _set_flags(node,
SEQ|more_flags);
1278 _set_flags(node,
KEY|
SEQ|more_flags);
1286 _set_flags(node,
DOC|more_flags);
1294 _set_flags(node,
STREAM|more_flags);
1323 _RYML_CB_CHECK(
m_callbacks, td.
handle ==
'!' || td.
handle ==
"!!" || td.
handle.trim(
'!').first_not_of(
"01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-") ==
npos);
1349 if(td.handle.empty())
1351 if(tag.begins_with(td.handle) && td.next_node_id <= node_id)
1354 if(tag.begins_with(
'!'))
1358 _RYML_CB_ERR(
m_callbacks,
"tag directive not found");
1365 csubstr _transform_tag(
Tree *t, csubstr tag,
id_type node)
1367 _c4dbgpf(
"[{}] resolving tag ~~~{}~~~", node, tag);
1368 size_t required_size = t->
resolve_tag(substr{}, tag, node);
1371 if(tag.begins_with(
"!<"))
1373 _c4dbgpf(
"[{}] resolved tag: ~~~{}~~~", node, tag);
1376 const char *prev_arena = t->
arena().str;(void)prev_arena;
1379 size_t actual_size = t->
resolve_tag(buf, tag, node);
1380 _RYML_CB_ASSERT(t->
m_callbacks, actual_size <= required_size);
1381 _c4dbgpf(
"[{}] resolved tag: ~~~{}~~~", node, buf.first(actual_size));
1382 return buf.first(actual_size);
1384 void _resolve_tags(Tree *t,
id_type node)
1386 NodeData *C4_RESTRICT d = t->_p(node);
1388 d->m_key.tag = _transform_tag(t, d->m_key.tag, node);
1390 d->m_val.tag = _transform_tag(t, d->m_val.tag, node);
1391 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1392 _resolve_tags(t, child);
1394 size_t _count_resolved_tags_size(Tree
const* t,
id_type node)
1397 NodeData
const* C4_RESTRICT d = t->_p(node);
1399 sz += t->resolve_tag(substr{}, d->m_key.tag, node);
1401 sz += t->resolve_tag(substr{}, d->m_val.tag, node);
1402 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1403 sz += _count_resolved_tags_size(t, child);
1406 void _normalize_tags(Tree *t,
id_type node)
1408 NodeData *C4_RESTRICT d = t->_p(node);
1413 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1414 _normalize_tags(t, child);
1416 void _normalize_tags_long(Tree *t,
id_type node)
1418 NodeData *C4_RESTRICT d = t->_p(node);
1423 for(
id_type child = t->first_child(node); child !=
NONE; child = t->next_sibling(child))
1424 _normalize_tags_long(t, child);
1432 size_t needed_size = _count_resolved_tags_size(
this,
root_id());
1435 _resolve_tags(
this,
root_id());
1442 _normalize_tags(
this,
root_id());
1449 _normalize_tags_long(
this,
root_id());
1458 if(p.ends_with(
'.'))
1459 p = p.first(p.len-1);
1465 return path.sub(path_pos);
1490 id_type target = _lookup_path_or_create(path, start);
1494 to_val(target, default_value);
1500 id_type target = _lookup_path_or_create(path, start);
1505 id_type Tree::_lookup_path_or_create(csubstr path,
id_type start)
1509 lookup_result r(path, start);
1516 _lookup_path_modify(&r);
1520 void Tree::_lookup_path(lookup_result *r)
const
1522 C4_ASSERT( ! r->unresolved().empty());
1523 _lookup_path_token
parent{
"",
type(r->closest)};
1527 node = _next_node(r, &
parent);
1530 if(r->unresolved().empty())
1535 }
while(node !=
NONE);
1538 void Tree::_lookup_path_modify(lookup_result *r)
1540 C4_ASSERT( ! r->unresolved().empty());
1541 _lookup_path_token
parent{
"",
type(r->closest)};
1545 node = _next_node_modify(r, &
parent);
1548 if(r->unresolved().empty())
1553 }
while(node !=
NONE);
1556 id_type Tree::_next_node(lookup_result * r, _lookup_path_token *
parent)
const
1558 _lookup_path_token token = _next_token(r, *
parent);
1563 csubstr prev = token.value;
1564 if(token.type ==
MAP || token.type ==
SEQ)
1566 _RYML_CB_ASSERT(
m_callbacks, !token.value.begins_with(
'['));
1571 else if(token.type ==
KEYVAL)
1573 _RYML_CB_ASSERT(
m_callbacks, r->unresolved().empty());
1577 else if(token.type ==
KEY)
1579 _RYML_CB_ASSERT(
m_callbacks, token.value.begins_with(
'[') && token.value.ends_with(
']'));
1580 token.value = token.value.offs(1, 1).trim(
' ');
1583 node =
child(r->closest, idx);
1596 csubstr p = r->path.sub(r->path_pos > 0 ? r->path_pos - 1 : r->path_pos);
1597 r->path_pos -= prev.len;
1598 if(p.begins_with(
'.'))
1605 id_type Tree::_next_node_modify(lookup_result * r, _lookup_path_token *
parent)
1607 _lookup_path_token token = _next_token(r, *
parent);
1612 if(token.type ==
MAP || token.type ==
SEQ)
1614 _RYML_CB_ASSERT(
m_callbacks, !token.value.begins_with(
'['));
1632 node =
child(r->closest, pos);
1639 NodeData *n =
_p(node);
1640 n->m_key.scalar = token.value;
1644 else if(token.type ==
KEYVAL)
1646 _RYML_CB_ASSERT(
m_callbacks, r->unresolved().empty());
1656 _add_flags(r->closest,
MAP);
1659 NodeData *n =
_p(node);
1660 n->m_key.scalar = token.value;
1661 n->m_val.scalar =
"";
1664 else if(token.type ==
KEY)
1666 _RYML_CB_ASSERT(
m_callbacks, token.value.begins_with(
'[') && token.value.ends_with(
']'));
1667 token.value = token.value.offs(1, 1).trim(
' ');
1675 csubstr k =
key(r->closest);
1676 _clear_type(r->closest);
1681 _clear_type(r->closest);
1686 node =
child(r->closest, idx);
1697 else if(
is_seq(r->closest))
1719 Tree::_lookup_path_token Tree::_next_token(lookup_result *r, _lookup_path_token
const&
parent)
const
1721 csubstr unres = r->unresolved();
1726 if(unres.begins_with(
'['))
1728 size_t pos = unres.find(
']');
1731 csubstr idx = unres.first(pos + 1);
1732 _advance(r, pos + 1);
1737 size_t pos = unres.first_of(
".[");
1740 _advance(r, unres.len);
1743 return {unres,
VAL};
1748 _RYML_CB_ASSERT(
m_callbacks, unres[pos] ==
'.' || unres[pos] ==
'[');
1749 if(unres[pos] ==
'.')
1752 _advance(r, pos + 1);
1753 return {unres.first(pos),
MAP};
1758 return {unres.first(pos),
SEQ};
1766 C4_SUPPRESS_WARNING_GCC_CLANG_POP
1767 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 resolve()
Resolve references using a throw-away resolver.
void remove_children(id_type node)
remove all the node's children, but keep the node itself
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
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
#define RYML_NOEXCEPT
Conditionally expands to noexcept when RYML_USE_ASSERT is 0 and is empty otherwise.
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
@ KEY
is member of a map, must have non-empty key
@ 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 the tree.
bool create_from_str(csubstr directive_)
leaves next_node_id unfilled
csubstr handle
Eg !e! in TAG !e! tag:example.com,2000:app/
size_t transform(csubstr tag, substr output, Callbacks const &callbacks) const
csubstr prefix
Eg tag:example.com,2000:app/ in TAG !e! tag:example.com,2000:app/
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