1 #ifndef _C4_YML_NODE_HPP_
2 #define _C4_YML_NODE_HPP_
12 # pragma clang diagnostic push
13 # pragma clang diagnostic ignored "-Wtype-limits"
14 # pragma clang diagnostic ignored "-Wold-style-cast"
15 #elif defined(__GNUC__)
16 # pragma GCC diagnostic push
17 # pragma GCC diagnostic ignored "-Wtype-limits"
18 # pragma GCC diagnostic ignored "-Wold-style-cast"
19 # pragma GCC diagnostic ignored "-Wuseless-cast"
20 #elif defined(_MSC_VER)
21 # pragma warning(push)
22 # pragma warning(disable: 4251)
23 # pragma warning(disable: 4296)
39 template<
class K>
struct Key { K &
k; };
48 template<
class T>
void write(NodeRef *n, T
const& v);
50 template<
class T>
inline bool read(ConstNodeRef
const& C4_RESTRICT n, T *v);
51 template<
class T>
inline bool read(NodeRef
const& C4_RESTRICT n, T *v);
52 template<
class T>
inline bool readkey(ConstNodeRef
const& C4_RESTRICT n, T *v);
53 template<
class T>
inline bool readkey(NodeRef
const& C4_RESTRICT n, T *v);
74 template<
class NodeRefType>
77 using value_type = NodeRefType;
78 using tree_type =
typename NodeRefType::tree_type;
80 tree_type * C4_RESTRICT m_tree;
83 child_iterator(tree_type * t,
id_type id) : m_tree(t), m_child_id(id) {}
85 child_iterator& operator++ () { RYML_ASSERT(m_child_id !=
NONE); m_child_id = m_tree->next_sibling(m_child_id);
return *
this; }
86 child_iterator& operator-- () { RYML_ASSERT(m_child_id !=
NONE); m_child_id = m_tree->prev_sibling(m_child_id);
return *
this; }
88 NodeRefType operator* ()
const {
return NodeRefType(m_tree, m_child_id); }
89 NodeRefType operator-> ()
const {
return NodeRefType(m_tree, m_child_id); }
91 bool operator!= (child_iterator that)
const { RYML_ASSERT(m_tree == that.m_tree);
return m_child_id != that.m_child_id; }
92 bool operator== (child_iterator that)
const { RYML_ASSERT(m_tree == that.m_tree);
return m_child_id == that.m_child_id; }
95 template<
class NodeRefType>
98 using n_iterator = child_iterator<NodeRefType>;
102 children_view_(n_iterator
const& C4_RESTRICT b_,
103 n_iterator
const& C4_RESTRICT e_) : b(b_), e(e_) {}
105 n_iterator begin()
const {
return b; }
106 n_iterator end ()
const {
return e; }
109 template<
class NodeRefType,
class Visitor>
110 bool _visit(NodeRefType &node, Visitor fn,
id_type indentation_level,
bool skip_root=
false)
113 if( ! (node.is_root() && skip_root))
115 if(fn(node, indentation_level))
119 if(node.has_children())
121 for(
auto ch : node.children())
123 if(_visit(ch, fn, indentation_level + increment,
false))
132 template<
class NodeRefType,
class Visitor>
133 bool _visit_stacked(NodeRefType &node, Visitor fn,
id_type indentation_level,
bool skip_root=
false)
136 if( ! (node.is_root() && skip_root))
138 if(fn(node, indentation_level))
144 if(node.has_children())
146 fn.push(node, indentation_level);
147 for(
auto ch : node.children())
149 if(_visit_stacked(ch, fn, indentation_level + increment,
false))
151 fn.pop(node, indentation_level);
155 fn.pop(node, indentation_level);
160 template<
class Impl,
class ConstImpl>
161 struct RoNodeMethods;
172 template<
class Impl,
class ConstImpl>
175 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wcast-align")
178 #define tree_ ((ConstImpl const* C4_RESTRICT)this)->m_tree
179 #define id_ ((ConstImpl const* C4_RESTRICT)this)->m_id
180 #define tree__ ((Impl const* C4_RESTRICT)this)->m_tree
181 #define id__ ((Impl const* C4_RESTRICT)this)->m_id
185 RYML_ASSERT(tree_ != nullptr); \
186 _RYML_CB_ASSERT(tree_->m_callbacks, id_ != NONE); \
187 _RYML_CB_ASSERT(tree_->m_callbacks, (((Impl const* C4_RESTRICT)this)->readable()))
190 #define _C4_IF_MUTABLE(ty) typename std::enable_if<!std::is_same<U, ConstImpl>::value, ty>::type
201 template<
class U=Impl>
202 C4_ALWAYS_INLINE
auto get()
RYML_NOEXCEPT -> _C4_IF_MUTABLE(
NodeData*) {
return ((Impl
const*)
this)->readable() ? tree__->get(id__) :
nullptr; }
254 RYML_DEPRECATED(
"use has_key_anchor()") bool
is_key_anchor() const noexcept {
_C4RR();
return tree_->has_key_anchor(id_); }
255 RYML_DEPRECATED(
"use has_val_anchor()") bool
is_val_hanchor() const noexcept {
_C4RR();
return tree_->has_val_anchor(id_); }
256 RYML_DEPRECATED(
"use has_anchor()") bool
is_anchor() const noexcept {
_C4RR();
return tree_->has_anchor(id_); }
257 RYML_DEPRECATED(
"use has_anchor() || is_ref()") bool
is_anchor_or_ref() const noexcept {
_C4RR();
return tree_->is_anchor_or_ref(id_); }
327 template<
class U=Impl>
328 C4_ALWAYS_INLINE
auto doc(
id_type i)
RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { RYML_ASSERT(tree_);
return {tree__, tree__->doc(i)}; }
331 template<
class U=Impl>
335 template<
class U=Impl>
339 template<
class U=Impl>
343 template<
class U=Impl>
347 template<
class U=Impl>
351 template<
class U=Impl>
355 template<
class U=Impl>
359 template<
class U=Impl>
363 template<
class U=Impl>
367 template<
class U=Impl>
371 template<
class U=Impl>
379 C4_ALWAYS_INLINE
id_type sibling_pos(ConstImpl
const& n)
const RYML_NOEXCEPT {
_C4RR(); _RYML_CB_ASSERT(tree_->callbacks(), n.readable());
return tree_->child_pos(tree_->parent(id_), n.m_id); }
410 template<
class U=Impl>
415 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__,
key);
436 template<
class U=Impl>
440 id_type ch = tree__->child(id__, pos);
441 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
457 _RYML_CB_ASSERT(tree_->m_callbacks, ch !=
NONE);
473 id_type ch = tree_->child(id_, pos);
474 _RYML_CB_ASSERT(tree_->m_callbacks, ch !=
NONE);
517 template<
class U=Impl>
518 C4_ALWAYS_INLINE
auto at(csubstr
key) -> _C4_IF_MUTABLE(Impl)
520 RYML_CHECK(tree_ !=
nullptr);
521 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
522 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
523 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
525 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__,
key);
553 template<
class U=Impl>
554 C4_ALWAYS_INLINE
auto at(
id_type pos) -> _C4_IF_MUTABLE(Impl)
556 RYML_CHECK(tree_ !=
nullptr);
557 const id_type cap = tree_->capacity();
558 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
559 _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
560 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
561 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
562 id_type ch = tree__->child(id__, pos);
563 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
577 RYML_CHECK(tree_ !=
nullptr);
578 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
579 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
580 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
582 _RYML_CB_CHECK(tree_->m_callbacks, ch !=
NONE);
597 RYML_CHECK(tree_ !=
nullptr);
598 const id_type cap = tree_->capacity();
599 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
600 _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
601 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
602 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
603 const id_type ch = tree_->child(id_, pos);
604 _RYML_CB_CHECK(tree_->m_callbacks, ch !=
NONE);
621 if( !
read((ConstImpl
const&)*
this, &v))
622 _RYML_CB_ERR(tree_->m_callbacks,
"could not deserialize value");
623 return *((ConstImpl
const*)
this);
633 if( !
readkey((ConstImpl
const&)*
this, &v.
k))
634 _RYML_CB_ERR(tree_->m_callbacks,
"could not deserialize key");
635 return *((ConstImpl
const*)
this);
655 bool get_if(csubstr name, T *var, T
const& fallback)
const
678 return *((ConstImpl
const*)
this);
685 return *((ConstImpl
const*)
this);
711 #if defined(__clang__)
712 # pragma clang diagnostic push
713 # pragma clang diagnostic ignored "-Wnull-dereference"
714 #elif defined(__GNUC__)
715 # pragma GCC diagnostic push
717 # pragma GCC diagnostic ignored "-Wnull-dereference"
730 template<
class U=Impl>
738 template<
class U=Impl>
746 template<
class U=Impl>
754 template<
class U=Impl>
758 NodeData const *nd = tree__->get(id__);
768 NodeData const *nd = tree_->get(id_);
778 template<
class Visitor>
782 return detail::_visit(*(ConstImpl
const*)
this, fn, indentation_level, skip_root);
785 template<
class Visitor,
class U=Impl>
787 -> _C4_IF_MUTABLE(
bool)
790 return detail::_visit(*(Impl*)
this, fn, indentation_level, skip_root);
794 template<
class Visitor>
798 return detail::_visit_stacked(*(ConstImpl
const*)
this, fn, indentation_level, skip_root);
801 template<
class Visitor,
class U=Impl>
803 -> _C4_IF_MUTABLE(
bool)
806 return detail::_visit_stacked(*(Impl*)
this, fn, indentation_level, skip_root);
811 #if defined(__clang__)
812 # pragma clang diagnostic pop
813 #elif defined(__GNUC__)
814 # pragma GCC diagnostic pop
817 #undef _C4_IF_MUTABLE
824 C4_SUPPRESS_WARNING_GCC_CLANG_POP
875 ConstNodeRef& operator= (std::nullptr_t) noexcept { m_tree =
nullptr; m_id =
NONE;
return *
this; }
893 C4_ALWAYS_INLINE
bool invalid() const noexcept {
return (!m_tree) || (m_id ==
NONE); }
896 C4_ALWAYS_INLINE
bool readable() const noexcept {
return m_tree !=
nullptr && m_id !=
NONE; }
899 constexpr
static C4_ALWAYS_INLINE
bool is_seed() noexcept {
return false; }
901 RYML_DEPRECATED(
"use one of readable(), is_seed() or !invalid()") bool valid() const noexcept {
return m_tree !=
nullptr && m_id !=
NONE; }
910 C4_ALWAYS_INLINE
Tree const*
tree() const noexcept {
return m_tree; }
911 C4_ALWAYS_INLINE
id_type id() const noexcept {
return m_id; }
924 RYML_DEPRECATED(
"use invalid()") bool operator== (std::nullptr_t) const noexcept {
return m_tree ==
nullptr || m_id ==
NONE; }
925 RYML_DEPRECATED(
"use !invalid()") bool operator!= (std::nullptr_t) const noexcept {
return !(m_tree ==
nullptr || m_id ==
NONE); }
927 RYML_DEPRECATED(
"use (this->val() == s)") bool operator== (csubstr s) const
RYML_NOEXCEPT { RYML_ASSERT(m_tree); _RYML_CB_ASSERT(m_tree->m_callbacks, m_id !=
NONE);
return m_tree->val(m_id) == s; }
928 RYML_DEPRECATED(
"use (this->val() != s)") bool operator!= (csubstr s) const
RYML_NOEXCEPT { RYML_ASSERT(m_tree); _RYML_CB_ASSERT(m_tree->m_callbacks, m_id !=
NONE);
return m_tree->val(m_id) != s; }
987 Tree *C4_RESTRICT m_tree;
1007 RYML_ASSERT(m_tree != nullptr); \
1008 _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE && !is_seed())
1011 RYML_ASSERT(m_tree != nullptr); \
1012 _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE)
1019 NodeRef() noexcept : m_tree(
nullptr), m_id(
NONE), m_seed() { _clear_seed(); }
1020 NodeRef(
Tree &t) noexcept : m_tree(&t), m_id(t .root_id()), m_seed() { _clear_seed(); }
1021 NodeRef(
Tree *t) noexcept : m_tree(t ), m_id(t->root_id()), m_seed() { _clear_seed(); }
1023 NodeRef(
Tree *t,
id_type id,
id_type seed_pos) noexcept : m_tree(t), m_id(
id), m_seed() { m_seed.str =
nullptr; m_seed.len = (size_t)seed_pos; }
1025 NodeRef(std::nullptr_t) noexcept : m_tree(
nullptr), m_id(
NONE), m_seed() {}
1050 bool invalid() const noexcept {
return m_tree ==
nullptr || m_id ==
NONE; }
1052 bool is_seed() const noexcept {
return (m_tree !=
nullptr && m_id !=
NONE) && (m_seed.str !=
nullptr || m_seed.len != (size_t)
NONE); }
1054 bool readable() const noexcept {
return (m_tree !=
nullptr && m_id !=
NONE) && (m_seed.str ==
nullptr && m_seed.len == (size_t)
NONE); }
1056 RYML_DEPRECATED(
"use one of readable(), is_seed() or !invalid()") inline
bool valid()
const {
return m_tree !=
nullptr && m_id !=
NONE; }
1067 if(m_tree == that.m_tree && m_id == that.m_id)
1069 bool seed = is_seed();
1074 return (m_seed.len == that.m_seed.len)
1075 && (m_seed.str == that.m_seed.str
1076 || m_seed == that.m_seed);
1089 RYML_DEPRECATED(
"use !readable()") bool operator== (std::nullptr_t)
const {
return m_tree ==
nullptr || m_id ==
NONE || is_seed(); }
1090 RYML_DEPRECATED(
"use readable()") bool operator!= (std::nullptr_t)
const {
return !(m_tree ==
nullptr || m_id ==
NONE || is_seed()); }
1092 RYML_DEPRECATED(
"use `this->val() == s`") bool operator== (csubstr s)
const {
_C4RR(); _RYML_CB_ASSERT(m_tree->m_callbacks, has_val());
return m_tree->val(m_id) == s; }
1093 RYML_DEPRECATED(
"use `this->val() != s`") bool operator!= (csubstr s)
const {
_C4RR(); _RYML_CB_ASSERT(m_tree->m_callbacks, has_val());
return m_tree->val(m_id) != s; }
1101 C4_ALWAYS_INLINE
Tree *
tree() noexcept {
return m_tree; }
1102 C4_ALWAYS_INLINE
Tree const*
tree() const noexcept {
return m_tree; }
1104 C4_ALWAYS_INLINE
id_type id() const noexcept {
return m_id; }
1119 void set_val(csubstr val) { _apply_seed(); m_tree->_set_val(m_id, val); }
1120 void set_key_tag(csubstr key_tag) { _apply_seed(); m_tree->set_key_tag(m_id, key_tag); }
1121 void set_val_tag(csubstr val_tag) { _apply_seed(); m_tree->set_val_tag(m_id, val_tag); }
1122 void set_key_anchor(csubstr key_anchor) { _apply_seed(); m_tree->set_key_anchor(m_id, key_anchor); }
1123 void set_val_anchor(csubstr val_anchor) { _apply_seed(); m_tree->set_val_anchor(m_id, val_anchor); }
1124 void set_key_ref(csubstr key_ref) { _apply_seed(); m_tree->set_key_ref(m_id, key_ref); }
1125 void set_val_ref(csubstr val_ref) { _apply_seed(); m_tree->set_val_ref(m_id, val_ref); }
1137 m_tree->remove_children(m_id);
1138 m_tree->_clear(m_id);
1145 m_tree->_clear_key(m_id);
1152 m_tree->_clear_val(m_id);
1159 m_tree->remove_children(m_id);
1165 m_tree->_add_flags(m_id, t);
1171 m_tree->_add_flags(m_id, t);
1186 void operator= (std::nullptr_t)
1192 void operator= (csubstr v)
1199 void operator= (
const char (&v)[N])
1218 RYML_ASSERT(m_tree);
1219 return m_tree->to_arena(s);
1226 csubstr s = m_tree->to_arena(k);
1227 m_tree->_set_key(m_id, s);
1233 m_tree->_set_key(m_id, csubstr{});
1241 csubstr s = m_tree->to_arena(v);
1242 m_tree->_set_val(m_id, s);
1248 m_tree->_set_val(m_id, csubstr{});
1268 _RYML_CB_ASSERT(m_tree->m_callbacks, val() == s);
1285 set_key_serialized(v.
k);
1294 set_key_serialized(v.
k);
1300 set_key_serialized(w.
wrapper);
1306 set_val_serialized(w);
1319 m_id = m_tree->append_child(m_id);
1320 m_tree->_set_key(m_id, m_seed);
1321 m_seed.str =
nullptr;
1322 m_seed.len = (size_t)
NONE;
1324 else if(m_seed.len != (
size_t)
NONE)
1326 _RYML_CB_ASSERT(m_tree->m_callbacks, (
size_t)m_tree->num_children(m_id) == m_seed.len);
1327 m_id = m_tree->append_child(m_id);
1328 m_seed.str =
nullptr;
1329 m_seed.len = (size_t)
NONE;
1333 _RYML_CB_ASSERT(m_tree->m_callbacks, readable());
1337 void _apply(csubstr v)
1339 m_tree->_set_val(m_id, v);
1342 void _apply(NodeScalar
const& v)
1344 m_tree->_set_val(m_id, v);
1347 void _apply(NodeInit
const& i)
1349 m_tree->_set(m_id, i);
1360 _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1361 NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1368 _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1369 NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1377 NodeRef r(m_tree, m_tree->insert_child(m_id,
NONE));
1384 NodeRef r(m_tree, m_tree->insert_child(m_id,
NONE));
1392 NodeRef r(m_tree, m_tree->append_child(m_id));
1399 NodeRef r(m_tree, m_tree->append_child(m_id));
1407 _RYML_CB_ASSERT(m_tree->m_callbacks, after.
m_tree == m_tree);
1408 NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.
m_id));
1415 _RYML_CB_ASSERT(m_tree->m_callbacks, after.
m_tree == m_tree);
1416 NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.
m_id));
1424 NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1431 NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1439 NodeRef r(m_tree, m_tree->append_sibling(m_id));
1446 NodeRef r(m_tree, m_tree->append_sibling(m_id));
1456 _RYML_CB_ASSERT(m_tree->m_callbacks, has_child(child));
1457 _RYML_CB_ASSERT(m_tree->m_callbacks, child.
parent().id() ==
id());
1458 m_tree->remove(child.
id());
1466 _RYML_CB_ASSERT(m_tree->m_callbacks, pos >= 0 && pos < num_children());
1467 id_type child = m_tree->child(m_id, pos);
1468 _RYML_CB_ASSERT(m_tree->m_callbacks, child !=
NONE);
1469 m_tree->remove(child);
1476 id_type child = m_tree->find_child(m_id,
key);
1477 _RYML_CB_ASSERT(m_tree->m_callbacks, child !=
NONE);
1478 m_tree->remove(child);
1490 m_tree->move(m_id, after.
m_id);
1500 if(parent.m_tree == m_tree)
1502 m_tree->move(m_id, parent.m_id, after.
m_id);
1506 parent.m_tree->
move(m_tree, m_id, parent.m_id, after.
m_id);
1507 m_tree = parent.m_tree;
1518 _RYML_CB_ASSERT(m_tree->m_callbacks, m_tree == after.
m_tree || after.
m_id ==
NONE);
1519 id_type dup = m_tree->duplicate(m_id, m_tree->parent(m_id), after.
m_id);
1532 _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.
m_tree || after.
m_id ==
NONE);
1533 if(parent.m_tree == m_tree)
1535 id_type dup = m_tree->duplicate(m_id, parent.m_id, after.
m_id);
1542 NodeRef r(parent.m_tree, dup);
1550 _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.
m_tree);
1551 if(parent.m_tree == m_tree)
1553 m_tree->duplicate_children(m_id, parent.m_id, after.
m_id);
1573 : m_tree(that.m_tree)
1574 , m_id(!that.is_seed() ? that.id() : (
id_type)
NONE)
1579 : m_tree(that.m_tree)
1580 , m_id(!that.is_seed() ? that.id() : (
id_type)
NONE)
1587 m_tree = (that.m_tree);
1588 m_id = (!that.is_seed() ? that.id() : (
id_type)
NONE);
1594 m_tree = (that.m_tree);
1595 m_id = (!that.is_seed() ? that.id() : (
id_type)
NONE);
1616 return read(n.m_tree, n.m_id, v);
1622 return read(n.tree(), n.id(), v);
1628 return readkey(n.m_tree, n.m_id, v);
1634 return readkey(n.tree(), n.id(), v);
1648 # pragma clang diagnostic pop
1649 #elif defined(__GNUC__)
1650 # pragma GCC diagnostic pop
1651 #elif defined(_MSC_VER)
1652 # pragma warning(pop)
encoding/decoding for base64.
Holds a pointer to an existing tree, and a node id.
Tree const * tree() const noexcept
ConstNodeRef(ConstNodeRef const &) noexcept=default
id_type id() const noexcept
ConstNodeRef(ConstNodeRef &&) noexcept=default
ConstNodeRef(Tree const *t) noexcept
ConstNodeRef(std::nullptr_t) noexcept
ConstNodeRef(Tree const *t, id_type id) noexcept
constexpr static bool is_seed() noexcept
because a ConstNodeRef cannot be used to write to the tree, it can never be a seed.
ConstNodeRef(Tree const &t) noexcept
ConstNodeRef & operator=(std::nullptr_t) noexcept
bool readable() const noexcept
because a ConstNodeRef cannot be used to write to the tree, readable() has the same meaning as !...
A reference to a node in an existing yaml tree, offering a more convenient API than the index-based A...
void set_val_anchor(csubstr val_anchor)
void move(ConstNodeRef const &after)
change the node's position within its parent, placing it after after.
void set_key_style(NodeType_e style)
NodeRef prepend_child(NodeInit const &i)
NodeRef insert_sibling(ConstNodeRef const &after)
NodeRef(Tree *t, id_type id, csubstr seed_key) noexcept
void set_val_tag(csubstr val_tag)
NodeRef append_sibling(NodeInit const &i)
NodeRef insert_sibling(NodeInit const &i, ConstNodeRef const &after)
NodeRef(NodeRef &&) noexcept=default
NodeRef(Tree *t, id_type id, id_type seed_pos) noexcept
NodeRef prepend_sibling(NodeInit const &i)
csubstr to_arena(T const &s)
serialize a variable to the arena
void _clear_seed() noexcept
NodeRef insert_child(NodeRef after)
void set_val(csubstr val)
NodeRef prepend_sibling()
size_t set_key_serialized(T const &k)
void set_val_style(NodeType_e style)
NodeRef(Tree *t, id_type id) noexcept
NodeRef insert_child(NodeInit const &i, NodeRef after)
Tree const * tree() const noexcept
size_t set_val_serialized(std::nullptr_t)
id_type id() const noexcept
void move(NodeRef const &parent, ConstNodeRef const &after)
move the node to a different parent (which may belong to a different tree), placing it after after.
void set_container_style(NodeType_e style)
NodeRef duplicate(ConstNodeRef const &after) const
duplicate the current node somewhere within its parent, and place it after the node after.
bool readable() const noexcept
true if the object is not invalid and not in seed state.
void duplicate_children(NodeRef const &parent, ConstNodeRef const &after) const
NodeRef(Tree *t) noexcept
size_t set_val_serialized(T const &v)
NodeRef duplicate(NodeRef const &parent, ConstNodeRef const &after) const
duplicate the current node somewhere into a different parent (possibly from a different tree),...
void set_type(NodeType t)
void remove_child(csubstr key)
remove a child by name
NodeRef(NodeRef const &) noexcept=default
void set_key_tag(csubstr key_tag)
size_t set_key_serialized(std::nullptr_t)
NodeRef append_child(NodeInit const &i)
NodeRef(std::nullptr_t) noexcept
void set_key_ref(csubstr key_ref)
void remove_child(NodeRef &child)
void set_key_anchor(csubstr key_anchor)
void change_type(NodeType t)
NodeRef(Tree &t) noexcept
bool is_seed() const noexcept
true if the object is not invalid and in seed state.
void set_key(csubstr key)
void set_val_ref(csubstr val_ref)
void remove_child(id_type pos)
remove the nth child of this node
void move(id_type node, id_type after)
change the node's position in the parent
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
id_type duplicate_children(id_type node, id_type parent, id_type after)
recursively duplicate the node's children (but not the node)
#define RYML_NOEXCEPT
Conditionally expands to noexcept when RYML_USE_ASSERT is 0 and is empty otherwise.
base64_wrapper_< byte > base64_wrapper
a tag type to mark a payload to be encoded as base64
base64_wrapper_< cbyte > const_base64_wrapper
a tag type to mark a payload as base64-encoded
OStream & operator<<(OStream &s, Tree const &t)
emit YAML to an STL-like ostream
bool from_chars(csubstr buf, uint8_t *v) noexcept
NodeType_e & operator|=(NodeType_e &subject, NodeType_e bits) noexcept
NodeType_e
a bit mask for marking node types and styles
bool readkey(ConstNodeRef const &n, T *v)
void write(NodeRef *n, T const &v)
bool read(ConstNodeRef const &n, T *v)
bool operator!=(const char(&s)[N], basic_substring< C > const that) noexcept
bool operator==(const char(&s)[N], basic_substring< C > const that) noexcept
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
fmt::base64_wrapper wrapper
fmt::const_base64_wrapper wrapper
contains the data for each YAML node.
convenience class to initialize nodes
a node scalar is a csubstr, which may be tagged and anchored.
wraps a NodeType_e element with some syntactic sugar and predicates
auto at(csubstr key) -> Impl
Find child by key; complexity is O(num_children).
bool type_has_none(NodeType_e bits) const RYML_NOEXCEPT
Forward to Tree::type_has_none().
const_children_view cchildren() const RYML_NOEXCEPT
get an iterable view over children
bool is_key_anchor() const noexcept
auto first_child() RYML_NOEXCEPT -> Impl
Forward to Tree::first_child().
id_type depth_asc() const RYML_NOEXCEPT
bool get_if(csubstr name, T *var) const
look for a child by name, if it exists assign to var.
id_type depth_desc() const RYML_NOEXCEPT
O(log(num_nodes)).
bool has_anchor() const RYML_NOEXCEPT
Forward to Tree::has_anchor().
auto children() RYML_NOEXCEPT -> children_view
get an iterable view over children
bool is_flow_ml() const RYML_NOEXCEPT
Forward to Tree::is_flow_ml().
bool is_val() const RYML_NOEXCEPT
Forward to Tree::is_val().
bool is_key_styled() const RYML_NOEXCEPT
Forward to Tree::is_key_styled().
bool is_root() const RYML_NOEXCEPT
Forward to Tree::is_root().
csubstr key_anchor() const RYML_NOEXCEPT
Forward to Tree::key_anchor().
bool has_val_anchor() const RYML_NOEXCEPT
Forward to Tree::has_val_anchor().
bool has_siblings() const RYML_NOEXCEPT
auto last_child() RYML_NOEXCEPT -> Impl
Forward to Tree::last_child().
auto visit_stacked(Visitor fn, id_type indentation_level=0, bool skip_root=true) RYML_NOEXCEPT -> bool
visit every child node calling fn(node, level)
bool is_key_plain() const RYML_NOEXCEPT
Forward to Tree::is_key_plain().
bool is_key_quoted() const RYML_NOEXCEPT
Forward to Tree::is_key_quoted().
bool is_stream() const RYML_NOEXCEPT
Forward to Tree::is_stream().
NodeType type() const RYML_NOEXCEPT
Forward to Tree::type_str().
bool empty() const RYML_NOEXCEPT
Forward to Tree::empty().
NodeScalar const & valsc() const RYML_NOEXCEPT
Forward to Tree::valsc().
auto parent() RYML_NOEXCEPT -> Impl
Forward to Tree::parent().
bool has_key_anchor() const RYML_NOEXCEPT
Forward to Tree::has_key_anchor().
bool is_key_unfiltered() const noexcept
Forward to Tree::is_key_unfiltered().
id_type sibling_pos(ConstImpl const &n) const RYML_NOEXCEPT
O(num_siblings).
const_children_view siblings() const RYML_NOEXCEPT
get an iterable view over all siblings (including the calling node)
bool is_key_literal() const RYML_NOEXCEPT
Forward to Tree::is_key_literal().
const_iterator cbegin() const RYML_NOEXCEPT
get an iterator to the first child
csubstr key_ref() const RYML_NOEXCEPT
Forward to Tree::key_ref().
ConstImpl sibling(id_type pos) const RYML_NOEXCEPT
Forward to Tree::sibling().
bool visit_stacked(Visitor fn, id_type indentation_level=0, bool skip_root=true) const RYML_NOEXCEPT
visit every child node calling fn(node, level)
bool has_child(ConstImpl const &n) const RYML_NOEXCEPT
Forward to Tree::has_child().
ConstImpl const & operator>>(T &v) const
deserialize the node's val to the given variable, forwarding to the user-overrideable read() function...
auto next_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::next_sibling().
bool visit(Visitor fn, id_type indentation_level=0, bool skip_root=true) const RYML_NOEXCEPT
visit every child node calling fn(node)
bool is_quoted() const RYML_NOEXCEPT
Forward to Tree::is_quoted().
bool parent_is_map() const RYML_NOEXCEPT
Forward to Tree::parent_is_map().
auto last_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::last_sibling().
bool has_child(csubstr name) const RYML_NOEXCEPT
Forward to Tree::has_child().
auto find_sibling(csubstr name) RYML_NOEXCEPT -> Impl
Forward to Tree::find_sibling().
bool get_if(csubstr name, T *var, T const &fallback) const
look for a child by name, if it exists assign to var, otherwise default to fallback.
bool is_map() const RYML_NOEXCEPT
Forward to Tree::is_map().
bool type_has_any(NodeType_e bits) const RYML_NOEXCEPT
Forward to Tree::type_has_any().
ConstImpl last_sibling() const RYML_NOEXCEPT
Forward to Tree::last_sibling().
bool is_container() const RYML_NOEXCEPT
Forward to Tree::is_container().
id_type num_siblings() const RYML_NOEXCEPT
O(num_children).
ConstImpl last_child() const RYML_NOEXCEPT
Forward to Tree::last_child().
bool has_key() const RYML_NOEXCEPT
Forward to Tree::has_key().
csubstr key_tag() const RYML_NOEXCEPT
Forward to Tree::key_tag().
const_children_view csiblings() const RYML_NOEXCEPT
get an iterable view over all siblings (including the calling node)
auto find_child(csubstr name) RYML_NOEXCEPT -> Impl
Forward to Tree::first_child().
detail::child_iterator< Impl > iterator
csubstr val_ref() const RYML_NOEXCEPT
Forward to Tree::val_ref().
csubstr key() const RYML_NOEXCEPT
Forward to Tree::key().
ConstImpl child(id_type pos) const RYML_NOEXCEPT
Forward to Tree::child().
bool has_sibling(csubstr name) const RYML_NOEXCEPT
Forward to Tree::has_sibling().
NodeScalar const & keysc() const RYML_NOEXCEPT
Forward to Tree::keysc().
size_t deserialize_val(fmt::base64_wrapper v) const
decode the base64-encoded key and assign the decoded blob to the given buffer/
bool has_key_tag() const RYML_NOEXCEPT
Forward to Tree::has_key_tag().
bool is_anchor() const noexcept
csubstr val_tag() const RYML_NOEXCEPT
Forward to Tree::val_tag().
ConstImpl next_sibling() const RYML_NOEXCEPT
Forward to Tree::next_sibling().
ConstImpl find_sibling(csubstr name) const RYML_NOEXCEPT
Forward to Tree::find_sibling().
bool is_anchor_or_ref() const noexcept
const char * type_str() const RYML_NOEXCEPT
Forward to Tree::type_str().
csubstr val_anchor() const RYML_NOEXCEPT
Forward to Tree::val_anchor().
const_children_view children() const RYML_NOEXCEPT
get an iterable view over children
auto end() RYML_NOEXCEPT -> iterator
get an iterator to after the last child
auto siblings() RYML_NOEXCEPT -> children_view
get an iterable view over all siblings (including the calling node)
bool has_parent() const RYML_NOEXCEPT
Forward to Tree::has_parent() Node must be readable.
bool is_val_squo() const RYML_NOEXCEPT
Forward to Tree::is_val_squo().
ConstImpl find_child(csubstr name) const RYML_NOEXCEPT
Forward to Tree::first_child().
NodeData const * get() const RYML_NOEXCEPT
returns the data or null when the id is NONE
ConstImpl at(csubstr key) const
Get a child by name, with error checking; complexity is O(num_children).
bool is_val_ref() const RYML_NOEXCEPT
Forward to Tree::is_val_ref().
bool has_other_siblings() const RYML_NOEXCEPT
Forward to Tree::has_sibling().
bool is_val_styled() const RYML_NOEXCEPT
Forward to Tree::is_val_styled().
bool val_is_null() const RYML_NOEXCEPT
Forward to Tree::val_is_null().
auto begin() RYML_NOEXCEPT -> iterator
get an iterator to the first child
bool has_sibling(id_type node) const RYML_NOEXCEPT
Forward to Tree::has_sibling().
id_type child_pos(ConstImpl const &n) const RYML_NOEXCEPT
O(num_children).
bool is_container_styled() const RYML_NOEXCEPT
Forward to Tree::is_container_styled().
detail::children_view_< ConstImpl > const_children_view
auto first_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::first_sibling().
csubstr val() const RYML_NOEXCEPT
Forward to Tree::val().
bool type_has_all(NodeType_e bits) const RYML_NOEXCEPT
Forward to Tree::type_has_all().
bool is_key_ref() const RYML_NOEXCEPT
Forward to Tree::is_key_ref().
const_iterator end() const RYML_NOEXCEPT
get an iterator to after the last child
ConstImpl parent() const RYML_NOEXCEPT
Forward to Tree::parent().
bool key_is_null() const RYML_NOEXCEPT
Forward to Tree::key_is_null().
auto get() RYML_NOEXCEPT -> NodeData *
returns the data or null when the id is NONE
detail::children_view_< Impl > children_view
bool parent_is_seq() const RYML_NOEXCEPT
Forward to Tree::parent_is_seq().
bool is_doc() const RYML_NOEXCEPT
Forward to Tree::is_doc().
auto doc(id_type i) RYML_NOEXCEPT -> Impl
Forward to Tree::doc().
auto visit(Visitor fn, id_type indentation_level=0, bool skip_root=true) RYML_NOEXCEPT -> bool
visit every child node calling fn(node)
bool is_key_dquo() const RYML_NOEXCEPT
Forward to Tree::is_key_dquo().
size_t deserialize_key(fmt::base64_wrapper v) const
decode the base64-encoded key and assign the decoded blob to the given buffer/
id_type num_children() const RYML_NOEXCEPT
O(num_children).
bool is_val_unfiltered() const noexcept
Forward to Tree::is_val_unfiltered().
ConstImpl first_sibling() const RYML_NOEXCEPT
Forward to Tree::first_sibling().
ConstImpl doc(id_type i) const RYML_NOEXCEPT
Forward to Tree::doc().
bool is_flow_sl() const RYML_NOEXCEPT
Forward to Tree::is_flow_sl().
auto at(id_type pos) -> Impl
Find child by position; complexity is O(pos).
bool is_flow() const RYML_NOEXCEPT
Forward to Tree::is_flow().
ConstImpl at(id_type pos) const
Get a child by position, with error checking; complexity is O(pos).
auto child(id_type pos) RYML_NOEXCEPT -> Impl
Forward to Tree::child().
bool is_block() const RYML_NOEXCEPT
Forward to Tree::is_block().
const_iterator cend() const RYML_NOEXCEPT
get an iterator to after the last child
bool is_key_folded() const RYML_NOEXCEPT
Forward to Tree::is_key_folded().
bool is_val_plain() const RYML_NOEXCEPT
Forward to Tree::is_val_plain().
bool is_seq() const RYML_NOEXCEPT
Forward to Tree::is_seq().
bool is_val_folded() const RYML_NOEXCEPT
Forward to Tree::is_val_folded().
detail::child_iterator< ConstImpl > const_iterator
bool has_children() const RYML_NOEXCEPT
Forward to Tree::has_child().
bool is_val_quoted() const RYML_NOEXCEPT
Forward to Tree::is_val_quoted().
auto sibling(id_type pos) RYML_NOEXCEPT -> Impl
Forward to Tree::sibling().
bool is_val_literal() const RYML_NOEXCEPT
Forward to Tree::is_val_literal().
bool has_child(id_type node) const RYML_NOEXCEPT
Forward to Tree::has_child().
bool is_key_squo() const RYML_NOEXCEPT
Forward to Tree::is_key_squo().
bool is_val_hanchor() const noexcept
auto operator[](csubstr key) RYML_NOEXCEPT -> Impl
Find child by key; complexity is O(num_children).
bool has_val() const RYML_NOEXCEPT
Forward to Tree::has_val().
ConstImpl first_child() const RYML_NOEXCEPT
Forward to Tree::first_child().
bool has_sibling(ConstImpl const &n) const RYML_NOEXCEPT
Forward to Tree::has_sibling().
bool is_keyval() const RYML_NOEXCEPT
Forward to Tree::is_keyval().
bool has_val_tag() const RYML_NOEXCEPT
Forward to Tree::has_val_tag().
auto prev_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::prev_sibling().
ConstImpl prev_sibling() const RYML_NOEXCEPT
Forward to Tree::prev_sibling().
id_type num_other_siblings() const RYML_NOEXCEPT
O(num_siblings).
const_iterator begin() const RYML_NOEXCEPT
get an iterator to the first child
bool is_val_dquo() const RYML_NOEXCEPT
Forward to Tree::is_val_dquo().
bool is_ref() const RYML_NOEXCEPT
Forward to Tree::is_ref().