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_); }
331 template<
class U=Impl>
332 C4_ALWAYS_INLINE
auto doc(
id_type i)
RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { RYML_ASSERT(tree_);
return {tree__, tree__->doc(i)}; }
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>
375 template<
class U=Impl>
383 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); }
414 template<
class U=Impl>
419 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__,
key);
440 template<
class U=Impl>
444 id_type ch = tree__->child(id__, pos);
445 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
461 _RYML_CB_ASSERT(tree_->m_callbacks, ch !=
NONE);
477 id_type ch = tree_->child(id_, pos);
478 _RYML_CB_ASSERT(tree_->m_callbacks, ch !=
NONE);
521 template<
class U=Impl>
522 C4_ALWAYS_INLINE
auto at(csubstr
key) -> _C4_IF_MUTABLE(Impl)
524 RYML_CHECK(tree_ !=
nullptr);
525 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
526 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
527 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
529 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__,
key);
557 template<
class U=Impl>
558 C4_ALWAYS_INLINE
auto at(
id_type pos) -> _C4_IF_MUTABLE(Impl)
560 RYML_CHECK(tree_ !=
nullptr);
561 const id_type cap = tree_->capacity();
562 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
563 _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
564 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
565 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
566 id_type ch = tree__->child(id__, pos);
567 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
581 RYML_CHECK(tree_ !=
nullptr);
582 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
583 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
584 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
586 _RYML_CB_CHECK(tree_->m_callbacks, ch !=
NONE);
601 RYML_CHECK(tree_ !=
nullptr);
602 const id_type cap = tree_->capacity();
603 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
604 _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
605 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
606 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
607 const id_type ch = tree_->child(id_, pos);
608 _RYML_CB_CHECK(tree_->m_callbacks, ch !=
NONE);
622 return tree_->location(parser, id_);
638 if( !
read((ConstImpl
const&)*
this, &v))
639 _RYML_CB_ERR(tree_->m_callbacks,
"could not deserialize value");
640 return *((ConstImpl
const*)
this);
650 if( !
readkey((ConstImpl
const&)*
this, &v.
k))
651 _RYML_CB_ERR(tree_->m_callbacks,
"could not deserialize key");
652 return *((ConstImpl
const*)
this);
672 bool get_if(csubstr name, T *var, T
const& fallback)
const
695 return *((ConstImpl
const*)
this);
702 return *((ConstImpl
const*)
this);
728 #if defined(__clang__)
729 # pragma clang diagnostic push
730 # pragma clang diagnostic ignored "-Wnull-dereference"
731 #elif defined(__GNUC__)
732 # pragma GCC diagnostic push
734 # pragma GCC diagnostic ignored "-Wnull-dereference"
747 template<
class U=Impl>
755 template<
class U=Impl>
763 template<
class U=Impl>
771 template<
class U=Impl>
775 NodeData const *nd = tree__->get(id__);
785 NodeData const *nd = tree_->get(id_);
795 template<
class Visitor>
799 return detail::_visit(*(ConstImpl
const*)
this, fn, indentation_level, skip_root);
802 template<
class Visitor,
class U=Impl>
804 -> _C4_IF_MUTABLE(
bool)
807 return detail::_visit(*(Impl*)
this, fn, indentation_level, skip_root);
811 template<
class Visitor>
815 return detail::_visit_stacked(*(ConstImpl
const*)
this, fn, indentation_level, skip_root);
818 template<
class Visitor,
class U=Impl>
820 -> _C4_IF_MUTABLE(
bool)
823 return detail::_visit_stacked(*(Impl*)
this, fn, indentation_level, skip_root);
828 #if defined(__clang__)
829 # pragma clang diagnostic pop
830 #elif defined(__GNUC__)
831 # pragma GCC diagnostic pop
834 #undef _C4_IF_MUTABLE
841 C4_SUPPRESS_WARNING_GCC_CLANG_POP
892 ConstNodeRef& operator= (std::nullptr_t) noexcept { m_tree =
nullptr; m_id =
NONE;
return *
this; }
909 C4_ALWAYS_INLINE
bool invalid() const noexcept {
return (!m_tree) || (m_id ==
NONE); }
912 C4_ALWAYS_INLINE
bool readable() const noexcept {
return m_tree !=
nullptr && m_id !=
NONE; }
915 constexpr
static C4_ALWAYS_INLINE
bool is_seed() noexcept {
return false; }
917 RYML_DEPRECATED(
"use one of readable(), is_seed() or !invalid()") bool valid() const noexcept {
return m_tree !=
nullptr && m_id !=
NONE; }
926 C4_ALWAYS_INLINE
Tree const*
tree() const noexcept {
return m_tree; }
927 C4_ALWAYS_INLINE
id_type id() const noexcept {
return m_id; }
940 RYML_DEPRECATED(
"use invalid()") bool operator== (std::nullptr_t) const noexcept {
return m_tree ==
nullptr || m_id ==
NONE; }
941 RYML_DEPRECATED(
"use !invalid()") bool operator!= (std::nullptr_t) const noexcept {
return !(m_tree ==
nullptr || m_id ==
NONE); }
943 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; }
944 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; }
1003 Tree *C4_RESTRICT m_tree;
1023 RYML_ASSERT(m_tree != nullptr); \
1024 _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE && !is_seed())
1027 RYML_ASSERT(m_tree != nullptr); \
1028 _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE)
1035 NodeRef() noexcept : m_tree(
nullptr), m_id(
NONE), m_seed() { _clear_seed(); }
1036 NodeRef(
Tree &t) noexcept : m_tree(&t), m_id(t .root_id()), m_seed() { _clear_seed(); }
1037 NodeRef(
Tree *t) noexcept : m_tree(t ), m_id(t->root_id()), m_seed() { _clear_seed(); }
1039 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; }
1041 NodeRef(std::nullptr_t) noexcept : m_tree(
nullptr), m_id(
NONE), m_seed() {}
1066 bool invalid() const noexcept {
return m_tree ==
nullptr || m_id ==
NONE; }
1068 bool is_seed() const noexcept {
return (m_tree !=
nullptr && m_id !=
NONE) && (m_seed.str !=
nullptr || m_seed.len != (size_t)
NONE); }
1070 bool readable() const noexcept {
return (m_tree !=
nullptr && m_id !=
NONE) && (m_seed.str ==
nullptr && m_seed.len == (size_t)
NONE); }
1072 RYML_DEPRECATED(
"use one of readable(), is_seed() or !invalid()") inline
bool valid()
const {
return m_tree !=
nullptr && m_id !=
NONE; }
1083 if(m_tree == that.m_tree && m_id == that.m_id)
1085 bool seed = is_seed();
1090 return (m_seed.len == that.m_seed.len)
1091 && (m_seed.str == that.m_seed.str
1092 || m_seed == that.m_seed);
1105 RYML_DEPRECATED(
"use !readable()") bool operator== (std::nullptr_t)
const {
return m_tree ==
nullptr || m_id ==
NONE || is_seed(); }
1106 RYML_DEPRECATED(
"use readable()") bool operator!= (std::nullptr_t)
const {
return !(m_tree ==
nullptr || m_id ==
NONE || is_seed()); }
1108 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; }
1109 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; }
1117 C4_ALWAYS_INLINE
Tree *
tree() noexcept {
return m_tree; }
1118 C4_ALWAYS_INLINE
Tree const*
tree() const noexcept {
return m_tree; }
1120 C4_ALWAYS_INLINE
id_type id() const noexcept {
return m_id; }
1135 void set_val(csubstr val) { _apply_seed(); m_tree->_set_val(m_id, val); }
1136 void set_key_tag(csubstr key_tag) { _apply_seed(); m_tree->set_key_tag(m_id, key_tag); }
1137 void set_val_tag(csubstr val_tag) { _apply_seed(); m_tree->set_val_tag(m_id, val_tag); }
1138 void set_key_anchor(csubstr key_anchor) { _apply_seed(); m_tree->set_key_anchor(m_id, key_anchor); }
1139 void set_val_anchor(csubstr val_anchor) { _apply_seed(); m_tree->set_val_anchor(m_id, val_anchor); }
1140 void set_key_ref(csubstr key_ref) { _apply_seed(); m_tree->set_key_ref(m_id, key_ref); }
1141 void set_val_ref(csubstr val_ref) { _apply_seed(); m_tree->set_val_ref(m_id, val_ref); }
1152 _C4RR(); m_tree->set_style_conditionally(m_id, type_mask, rem_style_flags, add_style_flags, recurse);
1161 m_tree->remove_children(m_id);
1162 m_tree->_clear(m_id);
1169 m_tree->_clear_key(m_id);
1176 m_tree->_clear_val(m_id);
1183 m_tree->remove_children(m_id);
1189 m_tree->_add_flags(m_id, t);
1195 m_tree->_add_flags(m_id, t);
1210 void operator= (std::nullptr_t)
1216 void operator= (csubstr v)
1223 void operator= (
const char (&v)[N])
1242 RYML_ASSERT(m_tree);
1243 return m_tree->to_arena(s);
1250 csubstr s = m_tree->to_arena(k);
1251 m_tree->_set_key(m_id, s);
1257 m_tree->_set_key(m_id, csubstr{});
1265 csubstr s = m_tree->to_arena(v);
1266 m_tree->_set_val(m_id, s);
1272 m_tree->_set_val(m_id, csubstr{});
1292 _RYML_CB_ASSERT(m_tree->m_callbacks, val() == s);
1309 set_key_serialized(v.
k);
1318 set_key_serialized(v.
k);
1324 set_key_serialized(w.
wrapper);
1330 set_val_serialized(w);
1343 m_id = m_tree->append_child(m_id);
1344 m_tree->_set_key(m_id, m_seed);
1345 m_seed.str =
nullptr;
1346 m_seed.len = (size_t)
NONE;
1348 else if(m_seed.len != (
size_t)
NONE)
1350 _RYML_CB_ASSERT(m_tree->m_callbacks, (
size_t)m_tree->num_children(m_id) == m_seed.len);
1351 m_id = m_tree->append_child(m_id);
1352 m_seed.str =
nullptr;
1353 m_seed.len = (size_t)
NONE;
1357 _RYML_CB_ASSERT(m_tree->m_callbacks, readable());
1361 void _apply(csubstr v)
1363 m_tree->_set_val(m_id, v);
1366 void _apply(NodeScalar
const& v)
1368 m_tree->_set_val(m_id, v);
1371 void _apply(NodeInit
const& i)
1373 m_tree->_set(m_id, i);
1384 _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1385 NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1392 _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1393 NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1401 NodeRef r(m_tree, m_tree->insert_child(m_id,
NONE));
1408 NodeRef r(m_tree, m_tree->insert_child(m_id,
NONE));
1416 NodeRef r(m_tree, m_tree->append_child(m_id));
1423 NodeRef r(m_tree, m_tree->append_child(m_id));
1431 _RYML_CB_ASSERT(m_tree->m_callbacks, after.
m_tree == m_tree);
1432 NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.
m_id));
1439 _RYML_CB_ASSERT(m_tree->m_callbacks, after.
m_tree == m_tree);
1440 NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.
m_id));
1448 NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1455 NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1463 NodeRef r(m_tree, m_tree->append_sibling(m_id));
1470 NodeRef r(m_tree, m_tree->append_sibling(m_id));
1480 _RYML_CB_ASSERT(m_tree->m_callbacks, has_child(child));
1481 _RYML_CB_ASSERT(m_tree->m_callbacks, child.
parent().id() ==
id());
1482 m_tree->remove(child.
id());
1490 _RYML_CB_ASSERT(m_tree->m_callbacks, pos >= 0 && pos < num_children());
1491 id_type child = m_tree->child(m_id, pos);
1492 _RYML_CB_ASSERT(m_tree->m_callbacks, child !=
NONE);
1493 m_tree->remove(child);
1500 id_type child = m_tree->find_child(m_id,
key);
1501 _RYML_CB_ASSERT(m_tree->m_callbacks, child !=
NONE);
1502 m_tree->remove(child);
1514 m_tree->move(m_id, after.
m_id);
1524 if(parent.m_tree == m_tree)
1526 m_tree->move(m_id, parent.m_id, after.
m_id);
1530 parent.m_tree->
move(m_tree, m_id, parent.m_id, after.
m_id);
1531 m_tree = parent.m_tree;
1542 _RYML_CB_ASSERT(m_tree->m_callbacks, m_tree == after.
m_tree || after.
m_id ==
NONE);
1543 id_type dup = m_tree->duplicate(m_id, m_tree->parent(m_id), after.
m_id);
1556 _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.
m_tree || after.
m_id ==
NONE);
1557 if(parent.m_tree == m_tree)
1559 id_type dup = m_tree->duplicate(m_id, parent.m_id, after.
m_id);
1566 NodeRef r(parent.m_tree, dup);
1574 _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.
m_tree);
1575 if(parent.m_tree == m_tree)
1577 m_tree->duplicate_children(m_id, parent.m_id, after.
m_id);
1597 : m_tree(that.m_tree)
1598 , m_id(!that.is_seed() ? that.id() : (
id_type)
NONE)
1603 : m_tree(that.m_tree)
1604 , m_id(!that.is_seed() ? that.id() : (
id_type)
NONE)
1611 m_tree = (that.m_tree);
1612 m_id = (!that.is_seed() ? that.id() : (
id_type)
NONE);
1618 m_tree = (that.m_tree);
1619 m_id = (!that.is_seed() ? that.id() : (
id_type)
NONE);
1640 return read(n.m_tree, n.m_id, v);
1646 return read(n.tree(), n.id(), v);
1652 return readkey(n.m_tree, n.m_id, v);
1658 return readkey(n.tree(), n.id(), v);
1672 # pragma clang diagnostic pop
1673 #elif defined(__GNUC__)
1674 # pragma GCC diagnostic pop
1675 #elif defined(_MSC_VER)
1676 # 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)
void set_style_conditionally(NodeType type_mask, NodeType rem_style_flags, NodeType add_style_flags, bool recurse=false)
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)
void clear_style(bool recurse=false)
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
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
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().
NodeType key_style() const RYML_NOEXCEPT
Forward to Tree::key_style().
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().
bool is_ancestor(ConstImpl const &ancestor) const RYML_NOEXCEPT
Forward to Tree::is_ancestor() Node must be readable.
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().
NodeType val_style() const RYML_NOEXCEPT
Forward to Tree::val_style().
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().
Location location(Parser const &parser) const
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().