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; };
47 template<
class T>
void write(NodeRef *n, T
const& v);
50 typename std::enable_if< ! std::is_floating_point<T>::value,
bool>::type
51 read(NodeRef
const& n, T *v);
54 typename std::enable_if< std::is_floating_point<T>::value,
bool>::type
55 read(NodeRef
const& n, T *v);
76 template<
class NodeRefType>
79 using value_type = NodeRefType;
80 using tree_type =
typename NodeRefType::tree_type;
82 tree_type * C4_RESTRICT m_tree;
85 child_iterator(tree_type * t,
id_type id) : m_tree(t), m_child_id(id) {}
87 child_iterator& operator++ () { RYML_ASSERT(m_child_id !=
NONE); m_child_id = m_tree->next_sibling(m_child_id);
return *
this; }
88 child_iterator& operator-- () { RYML_ASSERT(m_child_id !=
NONE); m_child_id = m_tree->prev_sibling(m_child_id);
return *
this; }
90 NodeRefType operator* ()
const {
return NodeRefType(m_tree, m_child_id); }
91 NodeRefType operator-> ()
const {
return NodeRefType(m_tree, m_child_id); }
93 bool operator!= (child_iterator that)
const { RYML_ASSERT(m_tree == that.m_tree);
return m_child_id != that.m_child_id; }
94 bool operator== (child_iterator that)
const { RYML_ASSERT(m_tree == that.m_tree);
return m_child_id == that.m_child_id; }
97 template<
class NodeRefType>
100 using n_iterator = child_iterator<NodeRefType>;
104 inline children_view_(n_iterator
const& C4_RESTRICT b_,
105 n_iterator
const& C4_RESTRICT e_) : b(b_), e(e_) {}
107 inline n_iterator begin()
const {
return b; }
108 inline n_iterator end ()
const {
return e; }
111 template<
class NodeRefType,
class Visitor>
112 bool _visit(NodeRefType &node, Visitor fn,
id_type indentation_level,
bool skip_root=
false)
115 if( ! (node.is_root() && skip_root))
117 if(fn(node, indentation_level))
121 if(node.has_children())
123 for(
auto ch : node.children())
125 if(_visit(ch, fn, indentation_level + increment,
false))
134 template<
class NodeRefType,
class Visitor>
135 bool _visit_stacked(NodeRefType &node, Visitor fn,
id_type indentation_level,
bool skip_root=
false)
138 if( ! (node.is_root() && skip_root))
140 if(fn(node, indentation_level))
146 if(node.has_children())
148 fn.push(node, indentation_level);
149 for(
auto ch : node.children())
151 if(_visit_stacked(ch, fn, indentation_level + increment,
false))
153 fn.pop(node, indentation_level);
157 fn.pop(node, indentation_level);
162 template<
class Impl,
class ConstImpl>
163 struct RoNodeMethods;
174 template<
class Impl,
class ConstImpl>
177 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wcast-align")
180 #define tree_ ((ConstImpl const* C4_RESTRICT)this)->m_tree
181 #define id_ ((ConstImpl const* C4_RESTRICT)this)->m_id
182 #define tree__ ((Impl const* C4_RESTRICT)this)->m_tree
183 #define id__ ((Impl const* C4_RESTRICT)this)->m_id
187 RYML_ASSERT(tree_ != nullptr); \
188 _RYML_CB_ASSERT(tree_->m_callbacks, id_ != NONE); \
189 _RYML_CB_ASSERT(tree_->m_callbacks, (((Impl const* C4_RESTRICT)this)->readable()))
192 #define _C4_IF_MUTABLE(ty) typename std::enable_if<!std::is_same<U, ConstImpl>::value, ty>::type
203 template<
class U=Impl>
204 C4_ALWAYS_INLINE
auto get()
RYML_NOEXCEPT -> _C4_IF_MUTABLE(
NodeData*) {
return ((Impl
const*)
this)->readable() ? tree__->get(id__) :
nullptr; }
256 RYML_DEPRECATED(
"use has_key_anchor()") bool
is_key_anchor() const noexcept {
_C4RR();
return tree_->has_key_anchor(id_); }
257 RYML_DEPRECATED(
"use has_val_anchor()") bool
is_val_hanchor() const noexcept {
_C4RR();
return tree_->has_val_anchor(id_); }
258 RYML_DEPRECATED(
"use has_anchor()") bool
is_anchor() const noexcept {
_C4RR();
return tree_->has_anchor(id_); }
259 RYML_DEPRECATED(
"use has_anchor() || is_ref()") bool
is_anchor_or_ref() const noexcept {
_C4RR();
return tree_->is_anchor_or_ref(id_); }
329 template<
class U=Impl>
330 C4_ALWAYS_INLINE
auto doc(
id_type i)
RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { RYML_ASSERT(tree_);
return {tree__, tree__->doc(i)}; }
334 template<
class U=Impl>
338 template<
class U=Impl>
342 template<
class U=Impl>
346 template<
class U=Impl>
350 template<
class U=Impl>
354 template<
class U=Impl>
358 template<
class U=Impl>
362 template<
class U=Impl>
366 template<
class U=Impl>
370 template<
class U=Impl>
374 template<
class U=Impl>
382 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); }
413 template<
class U=Impl>
418 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__,
key);
439 template<
class U=Impl>
443 id_type ch = tree__->child(id__, pos);
444 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
460 _RYML_CB_ASSERT(tree_->m_callbacks, ch !=
NONE);
476 id_type ch = tree_->child(id_, pos);
477 _RYML_CB_ASSERT(tree_->m_callbacks, ch !=
NONE);
520 template<
class U=Impl>
521 C4_ALWAYS_INLINE
auto at(csubstr
key) -> _C4_IF_MUTABLE(Impl)
523 RYML_CHECK(tree_ !=
nullptr);
524 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
525 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
526 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
528 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__,
key);
556 template<
class U=Impl>
557 C4_ALWAYS_INLINE
auto at(
id_type pos) -> _C4_IF_MUTABLE(Impl)
559 RYML_CHECK(tree_ !=
nullptr);
560 const id_type cap = tree_->capacity();
561 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
562 _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
563 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
564 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
565 id_type ch = tree__->child(id__, pos);
566 return ch !=
NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
580 RYML_CHECK(tree_ !=
nullptr);
581 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
582 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
583 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
585 _RYML_CB_CHECK(tree_->m_callbacks, ch !=
NONE);
600 RYML_CHECK(tree_ !=
nullptr);
601 const id_type cap = tree_->capacity();
602 _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
603 _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
604 _RYML_CB_CHECK(tree_->m_callbacks, ((Impl
const*)
this)->readable());
605 _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
606 const id_type ch = tree_->child(id_, pos);
607 _RYML_CB_CHECK(tree_->m_callbacks, ch !=
NONE);
624 if( !
read((ConstImpl
const&)*
this, &v))
625 _RYML_CB_ERR(tree_->m_callbacks,
"could not deserialize value");
626 return *((ConstImpl
const*)
this);
637 _RYML_CB_ERR(tree_->m_callbacks,
"could not deserialize key");
638 return *((ConstImpl
const*)
this);
645 return *((ConstImpl
const*)
this);
652 return *((ConstImpl
const*)
this);
689 bool get_if(csubstr name, T *var, T
const& fallback)
const
709 #if defined(__clang__)
710 # pragma clang diagnostic push
711 # pragma clang diagnostic ignored "-Wnull-dereference"
712 #elif defined(__GNUC__)
713 # pragma GCC diagnostic push
715 # pragma GCC diagnostic ignored "-Wnull-dereference"
728 template<
class U=Impl>
736 template<
class U=Impl>
744 template<
class U=Impl>
752 template<
class U=Impl>
756 NodeData const *nd = tree__->get(id__);
766 NodeData const *nd = tree_->get(id_);
776 template<
class Visitor>
780 return detail::_visit(*(ConstImpl
const*)
this, fn, indentation_level, skip_root);
783 template<
class Visitor,
class U=Impl>
785 -> _C4_IF_MUTABLE(
bool)
788 return detail::_visit(*(Impl*)
this, fn, indentation_level, skip_root);
792 template<
class Visitor>
796 return detail::_visit_stacked(*(ConstImpl
const*)
this, fn, indentation_level, skip_root);
799 template<
class Visitor,
class U=Impl>
801 -> _C4_IF_MUTABLE(
bool)
804 return detail::_visit_stacked(*(Impl*)
this, fn, indentation_level, skip_root);
809 #if defined(__clang__)
810 # pragma clang diagnostic pop
811 #elif defined(__GNUC__)
812 # pragma GCC diagnostic pop
815 #undef _C4_IF_MUTABLE
822 C4_SUPPRESS_WARNING_GCC_CLANG_POP
873 ConstNodeRef& operator= (std::nullptr_t) noexcept { m_tree =
nullptr; m_id =
NONE;
return *
this; }
891 C4_ALWAYS_INLINE
bool invalid() const noexcept {
return (!m_tree) || (m_id ==
NONE); }
894 C4_ALWAYS_INLINE
bool readable() const noexcept {
return m_tree !=
nullptr && m_id !=
NONE; }
897 constexpr
static C4_ALWAYS_INLINE
bool is_seed() noexcept {
return false; }
899 RYML_DEPRECATED(
"use one of readable(), is_seed() or !invalid()") bool valid() const noexcept {
return m_tree !=
nullptr && m_id !=
NONE; }
908 C4_ALWAYS_INLINE
Tree const*
tree() const noexcept {
return m_tree; }
909 C4_ALWAYS_INLINE
id_type id() const noexcept {
return m_id; }
922 RYML_DEPRECATED(
"use invalid()") bool operator== (std::nullptr_t) const noexcept {
return m_tree ==
nullptr || m_id ==
NONE; }
923 RYML_DEPRECATED(
"use !invalid()") bool operator!= (std::nullptr_t) const noexcept {
return !(m_tree ==
nullptr || m_id ==
NONE); }
925 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; }
926 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; }
983 Tree *C4_RESTRICT m_tree;
1003 RYML_ASSERT(m_tree != nullptr); \
1004 _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE && !is_seed())
1007 RYML_ASSERT(m_tree != nullptr); \
1008 _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE)
1015 NodeRef() noexcept : m_tree(
nullptr), m_id(
NONE), m_seed() { _clear_seed(); }
1016 NodeRef(
Tree &t) noexcept : m_tree(&t), m_id(t .root_id()), m_seed() { _clear_seed(); }
1017 NodeRef(
Tree *t) noexcept : m_tree(t ), m_id(t->root_id()), m_seed() { _clear_seed(); }
1019 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; }
1021 NodeRef(std::nullptr_t) noexcept : m_tree(
nullptr), m_id(
NONE), m_seed() {}
1046 inline
bool invalid() const noexcept {
return m_tree ==
nullptr || m_id ==
NONE; }
1048 inline bool is_seed() const noexcept {
return (m_tree != NULL && m_id !=
NONE) && (m_seed.str !=
nullptr || m_seed.len != (size_t)
NONE); }
1050 inline bool readable() const noexcept {
return (m_tree != NULL && m_id !=
NONE) && (m_seed.str ==
nullptr && m_seed.len == (size_t)
NONE); }
1052 RYML_DEPRECATED(
"use one of readable(), is_seed() or !invalid()") inline
bool valid()
const {
return m_tree !=
nullptr && m_id !=
NONE; }
1063 if(m_tree == that.m_tree && m_id == that.m_id)
1065 bool seed = is_seed();
1070 return (m_seed.len == that.m_seed.len)
1071 && (m_seed.str == that.m_seed.str
1072 || m_seed == that.m_seed);
1085 RYML_DEPRECATED(
"use !readable()") bool operator== (std::nullptr_t)
const {
return m_tree ==
nullptr || m_id ==
NONE || is_seed(); }
1086 RYML_DEPRECATED(
"use readable()") bool operator!= (std::nullptr_t)
const {
return !(m_tree ==
nullptr || m_id ==
NONE || is_seed()); }
1088 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; }
1089 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; }
1097 C4_ALWAYS_INLINE
Tree *
tree() noexcept {
return m_tree; }
1098 C4_ALWAYS_INLINE
Tree const*
tree() const noexcept {
return m_tree; }
1100 C4_ALWAYS_INLINE
id_type id() const noexcept {
return m_id; }
1115 void set_val(csubstr val) { _apply_seed(); m_tree->_set_val(m_id, val); }
1116 void set_key_tag(csubstr key_tag) { _apply_seed(); m_tree->set_key_tag(m_id, key_tag); }
1117 void set_val_tag(csubstr val_tag) { _apply_seed(); m_tree->set_val_tag(m_id, val_tag); }
1118 void set_key_anchor(csubstr key_anchor) { _apply_seed(); m_tree->set_key_anchor(m_id, key_anchor); }
1119 void set_val_anchor(csubstr val_anchor) { _apply_seed(); m_tree->set_val_anchor(m_id, val_anchor); }
1120 void set_key_ref(csubstr key_ref) { _apply_seed(); m_tree->set_key_ref(m_id, key_ref); }
1121 void set_val_ref(csubstr val_ref) { _apply_seed(); m_tree->set_val_ref(m_id, val_ref); }
1133 m_tree->remove_children(m_id);
1134 m_tree->_clear(m_id);
1141 m_tree->_clear_key(m_id);
1148 m_tree->_clear_val(m_id);
1155 m_tree->remove_children(m_id);
1161 m_tree->_add_flags(m_id, t);
1167 m_tree->_add_flags(m_id, t);
1182 inline void operator= (std::nullptr_t)
1188 inline void operator= (csubstr v)
1195 inline void operator= (
const char (&v)[N])
1214 RYML_ASSERT(m_tree);
1215 return m_tree->to_arena(s);
1222 csubstr s = m_tree->to_arena(k);
1223 m_tree->_set_key(m_id, s);
1229 m_tree->_set_key(m_id, csubstr{});
1237 csubstr s = m_tree->to_arena(v);
1238 m_tree->_set_val(m_id, s);
1244 m_tree->_set_val(m_id, csubstr{});
1264 _RYML_CB_ASSERT(m_tree->m_callbacks, val() == s);
1281 set_key_serialized(v.
k);
1290 set_key_serialized(v.
k);
1296 set_key_serialized(w.
wrapper);
1302 set_val_serialized(w);
1315 m_id = m_tree->append_child(m_id);
1316 m_tree->_set_key(m_id, m_seed);
1317 m_seed.str =
nullptr;
1318 m_seed.len = (size_t)
NONE;
1320 else if(m_seed.len != (
size_t)
NONE)
1322 _RYML_CB_ASSERT(m_tree->m_callbacks, (
size_t)m_tree->num_children(m_id) == m_seed.len);
1323 m_id = m_tree->append_child(m_id);
1324 m_seed.str =
nullptr;
1325 m_seed.len = (size_t)
NONE;
1329 _RYML_CB_ASSERT(m_tree->m_callbacks, readable());
1333 inline void _apply(csubstr v)
1335 m_tree->_set_val(m_id, v);
1338 inline void _apply(NodeScalar
const& v)
1340 m_tree->_set_val(m_id, v);
1343 inline void _apply(NodeInit
const& i)
1345 m_tree->_set(m_id, i);
1356 _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1357 NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1364 _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1365 NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1373 NodeRef r(m_tree, m_tree->insert_child(m_id,
NONE));
1380 NodeRef r(m_tree, m_tree->insert_child(m_id,
NONE));
1388 NodeRef r(m_tree, m_tree->append_child(m_id));
1395 NodeRef r(m_tree, m_tree->append_child(m_id));
1403 _RYML_CB_ASSERT(m_tree->m_callbacks, after.
m_tree == m_tree);
1404 NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.
m_id));
1411 _RYML_CB_ASSERT(m_tree->m_callbacks, after.
m_tree == m_tree);
1412 NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.
m_id));
1420 NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1427 NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1435 NodeRef r(m_tree, m_tree->append_sibling(m_id));
1442 NodeRef r(m_tree, m_tree->append_sibling(m_id));
1452 _RYML_CB_ASSERT(m_tree->m_callbacks, has_child(child));
1453 _RYML_CB_ASSERT(m_tree->m_callbacks, child.
parent().id() ==
id());
1454 m_tree->remove(child.
id());
1462 _RYML_CB_ASSERT(m_tree->m_callbacks, pos >= 0 && pos < num_children());
1463 id_type child = m_tree->child(m_id, pos);
1464 _RYML_CB_ASSERT(m_tree->m_callbacks, child !=
NONE);
1465 m_tree->remove(child);
1472 id_type child = m_tree->find_child(m_id,
key);
1473 _RYML_CB_ASSERT(m_tree->m_callbacks, child !=
NONE);
1474 m_tree->remove(child);
1486 m_tree->move(m_id, after.
m_id);
1496 if(parent.m_tree == m_tree)
1498 m_tree->move(m_id, parent.m_id, after.
m_id);
1502 parent.m_tree->
move(m_tree, m_id, parent.m_id, after.
m_id);
1503 m_tree = parent.m_tree;
1514 _RYML_CB_ASSERT(m_tree->m_callbacks, m_tree == after.
m_tree || after.
m_id ==
NONE);
1515 id_type dup = m_tree->duplicate(m_id, m_tree->parent(m_id), after.
m_id);
1528 _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.
m_tree || after.
m_id ==
NONE);
1529 if(parent.m_tree == m_tree)
1531 id_type dup = m_tree->duplicate(m_id, parent.m_id, after.
m_id);
1538 NodeRef r(parent.m_tree, dup);
1546 _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.
m_tree);
1547 if(parent.m_tree == m_tree)
1549 m_tree->duplicate_children(m_id, parent.m_id, after.
m_id);
1567 : m_tree(that.m_tree)
1568 , m_id(!that.is_seed() ? that.id() : (
id_type)
NONE)
1573 : m_tree(that.m_tree)
1574 , m_id(!that.is_seed() ? that.id() : (
id_type)
NONE)
1581 m_tree = (that.m_tree);
1582 m_id = (!that.is_seed() ? that.id() : (
id_type)
NONE);
1588 m_tree = (that.m_tree);
1589 m_id = (!that.is_seed() ? that.id() : (
id_type)
NONE);
1612 typename std::enable_if< ! std::is_floating_point<T>::value,
bool>::type
1615 csubstr val = n.
val();
1625 typename std::enable_if< ! std::is_floating_point<T>::value,
bool>::type
1628 csubstr val = n.
val();
1657 typename std::enable_if<std::is_floating_point<T>::value,
bool>::type
1660 csubstr val = n.
val();
1688 typename std::enable_if<std::is_floating_point<T>::value,
bool>::type
1691 csubstr val = n.
val();
1708 # pragma clang diagnostic pop
1709 #elif defined(__GNUC__)
1710 # pragma GCC diagnostic pop
1711 #elif defined(_MSC_VER)
1712 # 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
void write(NodeRef *n, T const &v)
std::enable_if< ! std::is_floating_point< T >::value, bool >::type read(NodeRef const &n, T *v)
convert the val of a scalar node to a particular type, by forwarding its val to from_chars<T>().
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
bool from_chars_float(csubstr buf, T *val)
decode a floating point from string.
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
succeeds even when the node may have invalid or seed id
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().