rapidyaml  0.9.0
parse and emit YAML, and do it fast
node.hpp
Go to the documentation of this file.
1 #ifndef _C4_YML_NODE_HPP_
2 #define _C4_YML_NODE_HPP_
3 
4 /** @file node.hpp Node classes */
5 
6 #include <cstddef>
7 
8 #include "c4/yml/tree.hpp"
9 #include "c4/base64.hpp"
10 
11 #ifdef __clang__
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/*needs to have dll-interface to be used by clients of struct*/)
23 # pragma warning(disable: 4296/*expression is always 'boolean_value'*/)
24 #endif
25 
26 namespace c4 {
27 namespace yml {
28 
29 /** @addtogroup doc_node_classes
30  *
31  * @{
32  */
33 
34 
35 /** @defgroup doc_serialization_helpers Serialization helpers
36  *
37  * @{
38  */
39 template<class K> struct Key { K & k; }; // NOLINT
41 template<> struct Key<fmt::base64_wrapper> { fmt::base64_wrapper wrapper; };
42 
43 template<class K> C4_ALWAYS_INLINE Key<K> key(K & k) { return Key<K>{k}; }
45 C4_ALWAYS_INLINE Key<fmt::base64_wrapper> key(fmt::base64_wrapper w) { return {w}; }
46 
47 
48 template<class T> void write(NodeRef *n, T const& v);
49 
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);
54 
55 /** @} */
56 
57 
58 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 
62 // forward decls
63 class NodeRef;
64 class ConstNodeRef;
65 
66 
67 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
70 
71 /** @cond dev */
72 namespace detail {
73 
74 template<class NodeRefType>
75 struct child_iterator
76 {
77  using value_type = NodeRefType;
78  using tree_type = typename NodeRefType::tree_type;
79 
80  tree_type * C4_RESTRICT m_tree;
81  id_type m_child_id;
82 
83  child_iterator(tree_type * t, id_type id) : m_tree(t), m_child_id(id) {}
84 
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; }
87 
88  NodeRefType operator* () const { return NodeRefType(m_tree, m_child_id); }
89  NodeRefType operator-> () const { return NodeRefType(m_tree, m_child_id); }
90 
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; }
93 };
94 
95 template<class NodeRefType>
96 struct children_view_
97 {
98  using n_iterator = child_iterator<NodeRefType>;
99 
100  n_iterator b, e;
101 
102  children_view_(n_iterator const& C4_RESTRICT b_,
103  n_iterator const& C4_RESTRICT e_) : b(b_), e(e_) {}
104 
105  n_iterator begin() const { return b; }
106  n_iterator end () const { return e; }
107 };
108 
109 template<class NodeRefType, class Visitor>
110 bool _visit(NodeRefType &node, Visitor fn, id_type indentation_level, bool skip_root=false)
111 {
112  id_type increment = 0;
113  if( ! (node.is_root() && skip_root))
114  {
115  if(fn(node, indentation_level))
116  return true;
117  ++increment;
118  }
119  if(node.has_children())
120  {
121  for(auto ch : node.children())
122  {
123  if(_visit(ch, fn, indentation_level + increment, false)) // no need to forward skip_root as it won't be root
124  {
125  return true;
126  }
127  }
128  }
129  return false;
130 }
131 
132 template<class NodeRefType, class Visitor>
133 bool _visit_stacked(NodeRefType &node, Visitor fn, id_type indentation_level, bool skip_root=false)
134 {
135  id_type increment = 0;
136  if( ! (node.is_root() && skip_root))
137  {
138  if(fn(node, indentation_level))
139  {
140  return true;
141  }
142  ++increment;
143  }
144  if(node.has_children())
145  {
146  fn.push(node, indentation_level);
147  for(auto ch : node.children())
148  {
149  if(_visit_stacked(ch, fn, indentation_level + increment, false)) // no need to forward skip_root as it won't be root
150  {
151  fn.pop(node, indentation_level);
152  return true;
153  }
154  }
155  fn.pop(node, indentation_level);
156  }
157  return false;
158 }
159 
160 template<class Impl, class ConstImpl>
161 struct RoNodeMethods;
162 } // detail
163 /** @endcond */
164 
165 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
168 
169 
170 /** a CRTP base providing read-only methods for @ref ConstNodeRef and @ref NodeRef */
171 namespace detail {
172 template<class Impl, class ConstImpl>
174 {
175  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wcast-align")
176  /** @cond dev */
177  // helper CRTP macros, undefined at the end
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
182  // require readable: this is a precondition for reading from the
183  // tree using this object.
184  #define _C4RR() \
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()))
188  // a SFINAE beautifier to enable a function only if the
189  // implementation is mutable
190  #define _C4_IF_MUTABLE(ty) typename std::enable_if<!std::is_same<U, ConstImpl>::value, ty>::type
191  /** @endcond */
192 
193 public:
194 
195  /** @name node property getters */
196  /** @{ */
197 
198  /** returns the data or null when the id is NONE */
199  C4_ALWAYS_INLINE NodeData const* get() const RYML_NOEXCEPT { return ((Impl const*)this)->readable() ? tree_->get(id_) : nullptr; }
200  /** returns the data or null when the id is NONE */
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; }
203 
204  C4_ALWAYS_INLINE NodeType type() const RYML_NOEXCEPT { _C4RR(); return tree_->type(id_); } /**< Forward to @ref Tree::type_str(). Node must be readable. */
205  C4_ALWAYS_INLINE const char* type_str() const RYML_NOEXCEPT { _C4RR(); return tree_->type_str(id_); } /**< Forward to @ref Tree::type_str(). Node must be readable. */
206 
207  C4_ALWAYS_INLINE csubstr key() const RYML_NOEXCEPT { _C4RR(); return tree_->key(id_); } /**< Forward to @ref Tree::key(). Node must be readable. */
208  C4_ALWAYS_INLINE csubstr key_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->key_tag(id_); } /**< Forward to @ref Tree::key_tag(). Node must be readable. */
209  C4_ALWAYS_INLINE csubstr key_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->key_ref(id_); } /**< Forward to @ref Tree::key_ref(). Node must be readable. */
210  C4_ALWAYS_INLINE csubstr key_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->key_anchor(id_); } /**< Forward to @ref Tree::key_anchor(). Node must be readable. */
211 
212  C4_ALWAYS_INLINE csubstr val() const RYML_NOEXCEPT { _C4RR(); return tree_->val(id_); } /**< Forward to @ref Tree::val(). Node must be readable. */
213  C4_ALWAYS_INLINE csubstr val_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->val_tag(id_); } /**< Forward to @ref Tree::val_tag(). Node must be readable. */
214  C4_ALWAYS_INLINE csubstr val_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->val_ref(id_); } /**< Forward to @ref Tree::val_ref(). Node must be readable. */
215  C4_ALWAYS_INLINE csubstr val_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->val_anchor(id_); } /**< Forward to @ref Tree::val_anchor(). Node must be readable. */
216 
217  C4_ALWAYS_INLINE NodeScalar const& keysc() const RYML_NOEXCEPT { _C4RR(); return tree_->keysc(id_); } /**< Forward to @ref Tree::keysc(). Node must be readable. */
218  C4_ALWAYS_INLINE NodeScalar const& valsc() const RYML_NOEXCEPT { _C4RR(); return tree_->valsc(id_); } /**< Forward to @ref Tree::valsc(). Node must be readable. */
219 
220  C4_ALWAYS_INLINE bool key_is_null() const RYML_NOEXCEPT { _C4RR(); return tree_->key_is_null(id_); } /**< Forward to @ref Tree::key_is_null(). Node must be readable. */
221  C4_ALWAYS_INLINE bool val_is_null() const RYML_NOEXCEPT { _C4RR(); return tree_->val_is_null(id_); } /**< Forward to @ref Tree::val_is_null(). Node must be readable. */
222 
223  C4_ALWAYS_INLINE bool is_key_unfiltered() const noexcept { _C4RR(); return tree_->is_key_unfiltered(id_); } /**< Forward to @ref Tree::is_key_unfiltered(). Node must be readable. */
224  C4_ALWAYS_INLINE bool is_val_unfiltered() const noexcept { _C4RR(); return tree_->is_val_unfiltered(id_); } /**< Forward to @ref Tree::is_val_unfiltered(). Node must be readable. */
225 
226  /** @} */
227 
228 public:
229 
230  /** @name node type predicates */
231  /** @{ */
232 
233  C4_ALWAYS_INLINE bool empty() const RYML_NOEXCEPT { _C4RR(); return tree_->empty(id_); } /**< Forward to @ref Tree::empty(). Node must be readable. */
234  C4_ALWAYS_INLINE bool is_stream() const RYML_NOEXCEPT { _C4RR(); return tree_->is_stream(id_); } /**< Forward to @ref Tree::is_stream(). Node must be readable. */
235  C4_ALWAYS_INLINE bool is_doc() const RYML_NOEXCEPT { _C4RR(); return tree_->is_doc(id_); } /**< Forward to @ref Tree::is_doc(). Node must be readable. */
236  C4_ALWAYS_INLINE bool is_container() const RYML_NOEXCEPT { _C4RR(); return tree_->is_container(id_); } /**< Forward to @ref Tree::is_container(). Node must be readable. */
237  C4_ALWAYS_INLINE bool is_map() const RYML_NOEXCEPT { _C4RR(); return tree_->is_map(id_); } /**< Forward to @ref Tree::is_map(). Node must be readable. */
238  C4_ALWAYS_INLINE bool is_seq() const RYML_NOEXCEPT { _C4RR(); return tree_->is_seq(id_); } /**< Forward to @ref Tree::is_seq(). Node must be readable. */
239  C4_ALWAYS_INLINE bool has_val() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val(id_); } /**< Forward to @ref Tree::has_val(). Node must be readable. */
240  C4_ALWAYS_INLINE bool has_key() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key(id_); } /**< Forward to @ref Tree::has_key(). Node must be readable. */
241  C4_ALWAYS_INLINE bool is_val() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val(id_); } /**< Forward to @ref Tree::is_val(). Node must be readable. */
242  C4_ALWAYS_INLINE bool is_keyval() const RYML_NOEXCEPT { _C4RR(); return tree_->is_keyval(id_); } /**< Forward to @ref Tree::is_keyval(). Node must be readable. */
243  C4_ALWAYS_INLINE bool has_key_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key_tag(id_); } /**< Forward to @ref Tree::has_key_tag(). Node must be readable. */
244  C4_ALWAYS_INLINE bool has_val_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val_tag(id_); } /**< Forward to @ref Tree::has_val_tag(). Node must be readable. */
245  C4_ALWAYS_INLINE bool has_key_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key_anchor(id_); } /**< Forward to @ref Tree::has_key_anchor(). Node must be readable. */
246  C4_ALWAYS_INLINE bool has_val_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val_anchor(id_); } /**< Forward to @ref Tree::has_val_anchor(). Node must be readable. */
247  C4_ALWAYS_INLINE bool has_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_anchor(id_); } /**< Forward to @ref Tree::has_anchor(). Node must be readable. */
248  C4_ALWAYS_INLINE bool is_key_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_ref(id_); } /**< Forward to @ref Tree::is_key_ref(). Node must be readable. */
249  C4_ALWAYS_INLINE bool is_val_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_ref(id_); } /**< Forward to @ref Tree::is_val_ref(). Node must be readable. */
250  C4_ALWAYS_INLINE bool is_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_ref(id_); } /**< Forward to @ref Tree::is_ref(). Node must be readable. */
251  C4_ALWAYS_INLINE bool parent_is_seq() const RYML_NOEXCEPT { _C4RR(); return tree_->parent_is_seq(id_); } /**< Forward to @ref Tree::parent_is_seq(). Node must be readable. */
252  C4_ALWAYS_INLINE bool parent_is_map() const RYML_NOEXCEPT { _C4RR(); return tree_->parent_is_map(id_); } /**< Forward to @ref Tree::parent_is_map(). Node must be readable. */
253 
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_); }
258 
259  /** @} */
260 
261 public:
262 
263  /** @name node container+scalar style predicates */
264  /** @{ */
265 
266  // documentation to the right -->
267 
268  C4_ALWAYS_INLINE bool type_has_any(NodeType_e bits) const RYML_NOEXCEPT { _C4RR(); return tree_->type_has_any(id_, bits); } /**< Forward to @ref Tree::type_has_any(). Node must be readable. */
269  C4_ALWAYS_INLINE bool type_has_all(NodeType_e bits) const RYML_NOEXCEPT { _C4RR(); return tree_->type_has_all(id_, bits); } /**< Forward to @ref Tree::type_has_all(). Node must be readable. */
270  C4_ALWAYS_INLINE bool type_has_none(NodeType_e bits) const RYML_NOEXCEPT { _C4RR(); return tree_->type_has_none(id_, bits); } /**< Forward to @ref Tree::type_has_none(). Node must be readable. */
271 
272  C4_ALWAYS_INLINE bool is_container_styled() const RYML_NOEXCEPT { _C4RR(); return tree_->is_container_styled(id_); } /**< Forward to @ref Tree::is_container_styled(). Node must be readable. */
273  C4_ALWAYS_INLINE bool is_block() const RYML_NOEXCEPT { _C4RR(); return tree_->is_block(id_); } /**< Forward to @ref Tree::is_block(). Node must be readable. */
274  C4_ALWAYS_INLINE bool is_flow_sl() const RYML_NOEXCEPT { _C4RR(); return tree_->is_flow_sl(id_); } /**< Forward to @ref Tree::is_flow_sl(). Node must be readable. */
275  C4_ALWAYS_INLINE bool is_flow_ml() const RYML_NOEXCEPT { _C4RR(); return tree_->is_flow_ml(id_); } /**< Forward to @ref Tree::is_flow_ml(). Node must be readable. */
276  C4_ALWAYS_INLINE bool is_flow() const RYML_NOEXCEPT { _C4RR(); return tree_->is_flow(id_); } /**< Forward to @ref Tree::is_flow(). Node must be readable. */
277 
278  C4_ALWAYS_INLINE bool is_key_styled() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_styled(id_); } /**< Forward to @ref Tree::is_key_styled(). Node must be readable. */
279  C4_ALWAYS_INLINE bool is_val_styled() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_styled(id_); } /**< Forward to @ref Tree::is_val_styled(). Node must be readable. */
280  C4_ALWAYS_INLINE bool is_key_literal() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_literal(id_); } /**< Forward to @ref Tree::is_key_literal(). Node must be readable. */
281  C4_ALWAYS_INLINE bool is_val_literal() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_literal(id_); } /**< Forward to @ref Tree::is_val_literal(). Node must be readable. */
282  C4_ALWAYS_INLINE bool is_key_folded() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_folded(id_); } /**< Forward to @ref Tree::is_key_folded(). Node must be readable. */
283  C4_ALWAYS_INLINE bool is_val_folded() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_folded(id_); } /**< Forward to @ref Tree::is_val_folded(). Node must be readable. */
284  C4_ALWAYS_INLINE bool is_key_squo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_squo(id_); } /**< Forward to @ref Tree::is_key_squo(). Node must be readable. */
285  C4_ALWAYS_INLINE bool is_val_squo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_squo(id_); } /**< Forward to @ref Tree::is_val_squo(). Node must be readable. */
286  C4_ALWAYS_INLINE bool is_key_dquo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_dquo(id_); } /**< Forward to @ref Tree::is_key_dquo(). Node must be readable. */
287  C4_ALWAYS_INLINE bool is_val_dquo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_dquo(id_); } /**< Forward to @ref Tree::is_val_dquo(). Node must be readable. */
288  C4_ALWAYS_INLINE bool is_key_plain() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_plain(id_); } /**< Forward to @ref Tree::is_key_plain(). Node must be readable. */
289  C4_ALWAYS_INLINE bool is_val_plain() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_plain(id_); } /**< Forward to @ref Tree::is_val_plain(). Node must be readable. */
290  C4_ALWAYS_INLINE bool is_key_quoted() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_quoted(id_); } /**< Forward to @ref Tree::is_key_quoted(). Node must be readable. */
291  C4_ALWAYS_INLINE bool is_val_quoted() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_quoted(id_); } /**< Forward to @ref Tree::is_val_quoted(). Node must be readable. */
292  C4_ALWAYS_INLINE bool is_quoted() const RYML_NOEXCEPT { _C4RR(); return tree_->is_quoted(id_); } /**< Forward to @ref Tree::is_quoted(). Node must be readable. */
293 
294  /** @} */
295 
296 public:
297 
298  /** @name hierarchy predicates */
299  /** @{ */
300 
301  // documentation to the right -->
302 
303  C4_ALWAYS_INLINE bool is_root() const RYML_NOEXCEPT { _C4RR(); return tree_->is_root(id_); } /**< Forward to @ref Tree::is_root(). Node must be readable. */
304  C4_ALWAYS_INLINE bool has_parent() const RYML_NOEXCEPT { _C4RR(); return tree_->has_parent(id_); } /**< Forward to @ref Tree::has_parent() Node must be readable. */
305  C4_ALWAYS_INLINE bool is_ancestor(ConstImpl const& ancestor) const RYML_NOEXCEPT { _C4RR(); return tree_->is_ancestor(id_, ancestor.m_id); } /**< Forward to @ref Tree::is_ancestor() Node must be readable. */
306 
307  C4_ALWAYS_INLINE bool has_child(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); return n.readable() ? tree_->has_child(id_, n.m_id) : false; } /**< Forward to @ref Tree::has_child(). Node must be readable. */
308  C4_ALWAYS_INLINE bool has_child(id_type node) const RYML_NOEXCEPT { _C4RR(); return tree_->has_child(id_, node); } /**< Forward to @ref Tree::has_child(). Node must be readable. */
309  C4_ALWAYS_INLINE bool has_child(csubstr name) const RYML_NOEXCEPT { _C4RR(); return tree_->has_child(id_, name); } /**< Forward to @ref Tree::has_child(). Node must be readable. */
310  C4_ALWAYS_INLINE bool has_children() const RYML_NOEXCEPT { _C4RR(); return tree_->has_children(id_); } /**< Forward to @ref Tree::has_child(). Node must be readable. */
311 
312  C4_ALWAYS_INLINE bool has_sibling(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); return n.readable() ? tree_->has_sibling(id_, n.m_id) : false; } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */
313  C4_ALWAYS_INLINE bool has_sibling(id_type node) const RYML_NOEXCEPT { _C4RR(); return tree_->has_sibling(id_, node); } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */
314  C4_ALWAYS_INLINE bool has_sibling(csubstr name) const RYML_NOEXCEPT { _C4RR(); return tree_->has_sibling(id_, name); } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */
315  C4_ALWAYS_INLINE bool has_other_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->has_other_siblings(id_); } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */
316 
317  RYML_DEPRECATED("use has_other_siblings()") bool has_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->has_siblings(id_); }
318 
319  /** @} */
320 
321 public:
322 
323  /** @name hierarchy getters */
324  /** @{ */
325 
326  // documentation to the right -->
327 
328  template<class U=Impl>
329  C4_ALWAYS_INLINE auto doc(id_type i) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { RYML_ASSERT(tree_); return {tree__, tree__->doc(i)}; } /**< Forward to @ref Tree::doc(). Node must be readable. */
330  C4_ALWAYS_INLINE ConstImpl doc(id_type i) const RYML_NOEXCEPT { RYML_ASSERT(tree_); return {tree_, tree_->doc(i)}; } /**< Forward to @ref Tree::doc(). Node must be readable. succeeds even when the node may have invalid or seed id */
331 
332  template<class U=Impl>
333  C4_ALWAYS_INLINE auto parent() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->parent(id__)}; } /**< Forward to @ref Tree::parent(). Node must be readable. */
334  C4_ALWAYS_INLINE ConstImpl parent() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->parent(id_)}; } /**< Forward to @ref Tree::parent(). Node must be readable. */
335 
336  template<class U=Impl>
337  C4_ALWAYS_INLINE auto first_child() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->first_child(id__)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */
338  C4_ALWAYS_INLINE ConstImpl first_child() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->first_child(id_)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */
339 
340  template<class U=Impl>
341  C4_ALWAYS_INLINE auto last_child() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->last_child(id__)}; } /**< Forward to @ref Tree::last_child(). Node must be readable. */
342  C4_ALWAYS_INLINE ConstImpl last_child () const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->last_child (id_)}; } /**< Forward to @ref Tree::last_child(). Node must be readable. */
343 
344  template<class U=Impl>
345  C4_ALWAYS_INLINE auto child(id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->child(id__, pos)}; } /**< Forward to @ref Tree::child(). Node must be readable. */
346  C4_ALWAYS_INLINE ConstImpl child(id_type pos) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->child(id_, pos)}; } /**< Forward to @ref Tree::child(). Node must be readable. */
347 
348  template<class U=Impl>
349  C4_ALWAYS_INLINE auto find_child(csubstr name) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->find_child(id__, name)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */
350  C4_ALWAYS_INLINE ConstImpl find_child(csubstr name) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->find_child(id_, name)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */
351 
352  template<class U=Impl>
353  C4_ALWAYS_INLINE auto prev_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->prev_sibling(id__)}; } /**< Forward to @ref Tree::prev_sibling(). Node must be readable. */
354  C4_ALWAYS_INLINE ConstImpl prev_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->prev_sibling(id_)}; } /**< Forward to @ref Tree::prev_sibling(). Node must be readable. */
355 
356  template<class U=Impl>
357  C4_ALWAYS_INLINE auto next_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->next_sibling(id__)}; } /**< Forward to @ref Tree::next_sibling(). Node must be readable. */
358  C4_ALWAYS_INLINE ConstImpl next_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->next_sibling(id_)}; } /**< Forward to @ref Tree::next_sibling(). Node must be readable. */
359 
360  template<class U=Impl>
361  C4_ALWAYS_INLINE auto first_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->first_sibling(id__)}; } /**< Forward to @ref Tree::first_sibling(). Node must be readable. */
362  C4_ALWAYS_INLINE ConstImpl first_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->first_sibling(id_)}; } /**< Forward to @ref Tree::first_sibling(). Node must be readable. */
363 
364  template<class U=Impl>
365  C4_ALWAYS_INLINE auto last_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->last_sibling(id__)}; } /**< Forward to @ref Tree::last_sibling(). Node must be readable. */
366  C4_ALWAYS_INLINE ConstImpl last_sibling () const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->last_sibling(id_)}; } /**< Forward to @ref Tree::last_sibling(). Node must be readable. */
367 
368  template<class U=Impl>
369  C4_ALWAYS_INLINE auto sibling(id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->sibling(id__, pos)}; } /**< Forward to @ref Tree::sibling(). Node must be readable. */
370  C4_ALWAYS_INLINE ConstImpl sibling(id_type pos) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->sibling(id_, pos)}; } /**< Forward to @ref Tree::sibling(). Node must be readable. */
371 
372  template<class U=Impl>
373  C4_ALWAYS_INLINE auto find_sibling(csubstr name) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->find_sibling(id__, name)}; } /**< Forward to @ref Tree::find_sibling(). Node must be readable. */
374  C4_ALWAYS_INLINE ConstImpl find_sibling(csubstr name) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->find_sibling(id_, name)}; } /**< Forward to @ref Tree::find_sibling(). Node must be readable. */
375 
376  C4_ALWAYS_INLINE id_type num_children() const RYML_NOEXCEPT { _C4RR(); return tree_->num_children(id_); } /**< O(num_children). Forward to @ref Tree::num_children(). */
377  C4_ALWAYS_INLINE id_type num_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->num_siblings(id_); } /**< O(num_children). Forward to @ref Tree::num_siblings(). */
378  C4_ALWAYS_INLINE id_type num_other_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->num_other_siblings(id_); } /**< O(num_siblings). Forward to @ref Tree::num_other_siblings(). */
379  C4_ALWAYS_INLINE id_type child_pos(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); _RYML_CB_ASSERT(tree_->m_callbacks, n.readable()); return tree_->child_pos(id_, n.m_id); } /**< O(num_children). Forward to @ref Tree::child_pos(). */
380  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); } /**< O(num_siblings). Forward to @ref Tree::sibling_pos(). */
381 
382  C4_ALWAYS_INLINE id_type depth_asc() const RYML_NOEXCEPT { _C4RR(); return tree_->depth_asc(id_); } /** O(log(num_nodes)). Forward to Tree::depth_asc(). Node must be readable. */
383  C4_ALWAYS_INLINE id_type depth_desc() const RYML_NOEXCEPT { _C4RR(); return tree_->depth_desc(id_); } /** O(num_nodes). Forward to Tree::depth_desc(). Node must be readable. */
384 
385  /** @} */
386 
387 public:
388 
389  /** @name square_brackets
390  * operator[] */
391  /** @{ */
392 
393  /** Find child by key; complexity is O(num_children).
394  *
395  * Returns the requested node, or an object in seed state if no
396  * such child is found (see @ref NodeRef for an explanation of
397  * what is seed state). When the object is in seed state, using it
398  * to read from the tree is UB. The seed node can be used to write
399  * to the tree provided that its create() method is called prior
400  * to writing, which happens in most modifying methods in
401  * NodeRef. It is the caller's responsibility to verify that the
402  * returned node is readable before subsequently using it to read
403  * from the tree.
404  *
405  * @warning the calling object must be readable. This precondition
406  * is asserted. The assertion is performed only if @ref
407  * RYML_USE_ASSERT is set to true. As with the non-const overload,
408  * it is UB to call this method if the node is not readable.
409  *
410  * @see https://github.com/biojppm/rapidyaml/issues/389 */
411  template<class U=Impl>
412  C4_ALWAYS_INLINE auto operator[] (csubstr key) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl)
413  {
414  _C4RR();
415  id_type ch = tree__->find_child(id__, key);
416  return ch != NONE ? Impl(tree__, ch) : Impl(tree__, id__, key);
417  }
418 
419  /** Find child by position; complexity is O(pos).
420  *
421  * Returns the requested node, or an object in seed state if no
422  * such child is found (see @ref NodeRef for an explanation of
423  * what is seed state). When the object is in seed state, using it
424  * to read from the tree is UB. The seed node can be used to write
425  * to the tree provided that its create() method is called prior
426  * to writing, which happens in most modifying methods in
427  * NodeRef. It is the caller's responsibility to verify that the
428  * returned node is readable before subsequently using it to read
429  * from the tree.
430  *
431  * @warning the calling object must be readable. This precondition
432  * is asserted. The assertion is performed only if @ref
433  * RYML_USE_ASSERT is set to true. As with the non-const overload,
434  * it is UB to call this method if the node is not readable.
435  *
436  * @see https://github.com/biojppm/rapidyaml/issues/389 */
437  template<class U=Impl>
438  C4_ALWAYS_INLINE auto operator[] (id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl)
439  {
440  _C4RR();
441  id_type ch = tree__->child(id__, pos);
442  return ch != NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
443  }
444 
445  /** Find a child by key; complexity is O(num_children).
446  *
447  * Behaves similar to the non-const overload, but further asserts
448  * that the returned node is readable (because it can never be in
449  * a seed state). The assertion is performed only if @ref
450  * RYML_USE_ASSERT is set to true. As with the non-const overload,
451  * it is UB to use the return value if it is not valid.
452  *
453  * @see https://github.com/biojppm/rapidyaml/issues/389 */
454  C4_ALWAYS_INLINE ConstImpl operator[] (csubstr key) const RYML_NOEXCEPT
455  {
456  _C4RR();
457  id_type ch = tree_->find_child(id_, key);
458  _RYML_CB_ASSERT(tree_->m_callbacks, ch != NONE);
459  return {tree_, ch};
460  }
461 
462  /** Find a child by position; complexity is O(pos).
463  *
464  * Behaves similar to the non-const overload, but further asserts
465  * that the returned node is readable (because it can never be in
466  * a seed state). This assertion is performed only if @ref
467  * RYML_USE_ASSERT is set to true. As with the non-const overload,
468  * it is UB to use the return value if it is not valid.
469  *
470  * @see https://github.com/biojppm/rapidyaml/issues/389 */
471  C4_ALWAYS_INLINE ConstImpl operator[] (id_type pos) const RYML_NOEXCEPT
472  {
473  _C4RR();
474  id_type ch = tree_->child(id_, pos);
475  _RYML_CB_ASSERT(tree_->m_callbacks, ch != NONE);
476  return {tree_, ch};
477  }
478 
479  /** @} */
480 
481 public:
482 
483  /** @name at
484  *
485  * These functions are the analogue to operator[], with the
486  * difference that they emit an error instead of an
487  * assertion. That is, if any of the pre or post conditions is
488  * violated, an error is always emitted (resulting in a call to
489  * the error callback).
490  *
491  * @{ */
492 
493  /** Find child by key; complexity is O(num_children).
494  *
495  * Returns the requested node, or an object in seed state if no
496  * such child is found (see @ref NodeRef for an explanation of
497  * what is seed state). When the object is in seed state, using it
498  * to read from the tree is UB. The seed node can be subsequently
499  * used to write to the tree provided that its create() method is
500  * called prior to writing, which happens inside most mutating
501  * methods in NodeRef. It is the caller's responsibility to verify
502  * that the returned node is readable before subsequently using it
503  * to read from the tree.
504  *
505  * @warning This method will call the error callback (regardless
506  * of build type or of the value of RYML_USE_ASSERT) whenever any
507  * of the following preconditions is violated: a) the object is
508  * valid (points at a tree and a node), b) the calling object must
509  * be readable (must not be in seed state), c) the calling object
510  * must be pointing at a MAP node. The preconditions are similar
511  * to the non-const operator[](csubstr), but instead of using
512  * assertions, this function directly checks those conditions and
513  * calls the error callback if any of the checks fail.
514  *
515  * @note since it is valid behavior for the returned node to be in
516  * seed state, the error callback is not invoked when this
517  * happens. */
518  template<class U=Impl>
519  C4_ALWAYS_INLINE auto at(csubstr key) -> _C4_IF_MUTABLE(Impl)
520  {
521  RYML_CHECK(tree_ != nullptr);
522  _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
523  _RYML_CB_CHECK(tree_->m_callbacks, ((Impl const*)this)->readable());
524  _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
525  id_type ch = tree__->find_child(id__, key);
526  return ch != NONE ? Impl(tree__, ch) : Impl(tree__, id__, key);
527  }
528 
529  /** Find child by position; complexity is O(pos).
530  *
531  * Returns the requested node, or an object in seed state if no
532  * such child is found (see @ref NodeRef for an explanation of
533  * what is seed state). When the object is in seed state, using it
534  * to read from the tree is UB. The seed node can be used to write
535  * to the tree provided that its create() method is called prior
536  * to writing, which happens in most modifying methods in
537  * NodeRef. It is the caller's responsibility to verify that the
538  * returned node is readable before subsequently using it to read
539  * from the tree.
540  *
541  * @warning This method will call the error callback (regardless
542  * of build type or of the value of RYML_USE_ASSERT) whenever any
543  * of the following preconditions is violated: a) the object is
544  * valid (points at a tree and a node), b) the calling object must
545  * be readable (must not be in seed state), c) the calling object
546  * must be pointing at a MAP node. The preconditions are similar
547  * to the non-const operator[](id_type), but instead of using
548  * assertions, this function directly checks those conditions and
549  * calls the error callback if any of the checks fail.
550  *
551  * @note since it is valid behavior for the returned node to be in
552  * seed state, the error callback is not invoked when this
553  * happens. */
554  template<class U=Impl>
555  C4_ALWAYS_INLINE auto at(id_type pos) -> _C4_IF_MUTABLE(Impl)
556  {
557  RYML_CHECK(tree_ != nullptr);
558  const id_type cap = tree_->capacity();
559  _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
560  _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
561  _RYML_CB_CHECK(tree_->m_callbacks, ((Impl const*)this)->readable());
562  _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
563  id_type ch = tree__->child(id__, pos);
564  return ch != NONE ? Impl(tree__, ch) : Impl(tree__, id__, pos);
565  }
566 
567  /** Get a child by name, with error checking; complexity is
568  * O(num_children).
569  *
570  * Behaves as operator[](csubstr) const, but always raises an
571  * error (even when RYML_USE_ASSERT is set to false) when the
572  * returned node does not exist, or when this node is not
573  * readable, or when it is not a map. This behaviour is similar to
574  * std::vector::at(), but the error consists in calling the error
575  * callback instead of directly raising an exception. */
576  ConstImpl at(csubstr key) const
577  {
578  RYML_CHECK(tree_ != nullptr);
579  _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < tree_->capacity()));
580  _RYML_CB_CHECK(tree_->m_callbacks, ((Impl const*)this)->readable());
581  _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_map(id_));
582  id_type ch = tree_->find_child(id_, key);
583  _RYML_CB_CHECK(tree_->m_callbacks, ch != NONE);
584  return {tree_, ch};
585  }
586 
587  /** Get a child by position, with error checking; complexity is
588  * O(pos).
589  *
590  * Behaves as operator[](id_type) const, but always raises an error
591  * (even when RYML_USE_ASSERT is set to false) when the returned
592  * node does not exist, or when this node is not readable, or when
593  * it is not a container. This behaviour is similar to
594  * std::vector::at(), but the error consists in calling the error
595  * callback instead of directly raising an exception. */
596  ConstImpl at(id_type pos) const
597  {
598  RYML_CHECK(tree_ != nullptr);
599  const id_type cap = tree_->capacity();
600  _RYML_CB_CHECK(tree_->m_callbacks, (id_ >= 0 && id_ < cap));
601  _RYML_CB_CHECK(tree_->m_callbacks, (pos >= 0 && pos < cap));
602  _RYML_CB_CHECK(tree_->m_callbacks, ((Impl const*)this)->readable());
603  _RYML_CB_CHECK(tree_->m_callbacks, tree_->is_container(id_));
604  const id_type ch = tree_->child(id_, pos);
605  _RYML_CB_CHECK(tree_->m_callbacks, ch != NONE);
606  return {tree_, ch};
607  }
608 
609  /** @} */
610 
611 public:
612 
613  /** @name deserialization */
614  /** @{ */
615 
616  /** deserialize the node's val to the given variable, forwarding
617  * to the user-overrideable @ref read() function. */
618  template<class T>
619  ConstImpl const& operator>> (T &v) const
620  {
621  _C4RR();
622  if( ! read((ConstImpl const&)*this, &v))
623  _RYML_CB_ERR(tree_->m_callbacks, "could not deserialize value");
624  return *((ConstImpl const*)this);
625  }
626 
627  /** deserialize the node's key to the given variable, forwarding
628  * to the user-overrideable @ref read() function; use @ref key()
629  * to disambiguate; for example: `node >> ryml::key(var)` */
630  template<class T>
631  ConstImpl const& operator>> (Key<T> v) const
632  {
633  _C4RR();
634  if( ! readkey((ConstImpl const&)*this, &v.k))
635  _RYML_CB_ERR(tree_->m_callbacks, "could not deserialize key");
636  return *((ConstImpl const*)this);
637  }
638 
639  /** look for a child by name, if it exists assign to var. return
640  * true if the child existed. */
641  template<class T>
642  bool get_if(csubstr name, T *var) const
643  {
644  _C4RR();
645  ConstImpl ch = find_child(name);
646  if(!ch.readable())
647  return false;
648  ch >> *var;
649  return true;
650  }
651 
652  /** look for a child by name, if it exists assign to var,
653  * otherwise default to fallback. return true if the child
654  * existed. */
655  template<class T>
656  bool get_if(csubstr name, T *var, T const& fallback) const
657  {
658  _C4RR();
659  ConstImpl ch = find_child(name);
660  if(ch.readable())
661  {
662  ch >> *var;
663  return true;
664  }
665  else
666  {
667  *var = fallback;
668  return false;
669  }
670  }
671 
672  /** @name deserialization_base64 */
673  /** @{ */
674 
675  /** deserialize the node's key as base64. lightweight wrapper over @ref deserialize_key() */
676  ConstImpl const& operator>> (Key<fmt::base64_wrapper> w) const
677  {
679  return *((ConstImpl const*)this);
680  }
681 
682  /** deserialize the node's val as base64. lightweight wrapper over @ref deserialize_val() */
683  ConstImpl const& operator>> (fmt::base64_wrapper w) const
684  {
685  deserialize_val(w);
686  return *((ConstImpl const*)this);
687  }
688 
689  /** decode the base64-encoded key and assign the
690  * decoded blob to the given buffer/
691  * @return the size of base64-decoded blob */
693  {
694  _C4RR();
695  return from_chars(key(), &v);
696  }
697  /** decode the base64-encoded key and assign the
698  * decoded blob to the given buffer/
699  * @return the size of base64-decoded blob */
701  {
702  _C4RR();
703  return from_chars(val(), &v);
704  };
705 
706  /** @} */
707 
708  /** @} */
709 
710 public:
711 
712  #if defined(__clang__)
713  # pragma clang diagnostic push
714  # pragma clang diagnostic ignored "-Wnull-dereference"
715  #elif defined(__GNUC__)
716  # pragma GCC diagnostic push
717  # if __GNUC__ >= 6
718  # pragma GCC diagnostic ignored "-Wnull-dereference"
719  # endif
720  #endif
721 
722  /** @name iteration */
723  /** @{ */
724 
725  using iterator = detail::child_iterator<Impl>;
726  using const_iterator = detail::child_iterator<ConstImpl>;
727  using children_view = detail::children_view_<Impl>;
728  using const_children_view = detail::children_view_<ConstImpl>;
729 
730  /** get an iterator to the first child */
731  template<class U=Impl>
732  C4_ALWAYS_INLINE auto begin() RYML_NOEXCEPT -> _C4_IF_MUTABLE(iterator) { _C4RR(); return iterator(tree__, tree__->first_child(id__)); }
733  /** get an iterator to the first child */
734  C4_ALWAYS_INLINE const_iterator begin() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, tree_->first_child(id_)); }
735  /** get an iterator to the first child */
736  C4_ALWAYS_INLINE const_iterator cbegin() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, tree_->first_child(id_)); }
737 
738  /** get an iterator to after the last child */
739  template<class U=Impl>
740  C4_ALWAYS_INLINE auto end() RYML_NOEXCEPT -> _C4_IF_MUTABLE(iterator) { _C4RR(); return iterator(tree__, NONE); }
741  /** get an iterator to after the last child */
742  C4_ALWAYS_INLINE const_iterator end() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, NONE); }
743  /** get an iterator to after the last child */
744  C4_ALWAYS_INLINE const_iterator cend() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, tree_->first_child(id_)); }
745 
746  /** get an iterable view over children */
747  template<class U=Impl>
748  C4_ALWAYS_INLINE auto children() RYML_NOEXCEPT -> _C4_IF_MUTABLE(children_view) { _C4RR(); return children_view(begin(), end()); }
749  /** get an iterable view over children */
750  C4_ALWAYS_INLINE const_children_view children() const RYML_NOEXCEPT { _C4RR(); return const_children_view(begin(), end()); }
751  /** get an iterable view over children */
752  C4_ALWAYS_INLINE const_children_view cchildren() const RYML_NOEXCEPT { _C4RR(); return const_children_view(begin(), end()); }
753 
754  /** get an iterable view over all siblings (including the calling node) */
755  template<class U=Impl>
756  C4_ALWAYS_INLINE auto siblings() RYML_NOEXCEPT -> _C4_IF_MUTABLE(children_view)
757  {
758  _C4RR();
759  NodeData const *nd = tree__->get(id__);
760  return (nd->m_parent != NONE) ? // does it have a parent?
761  children_view(iterator(tree__, tree_->get(nd->m_parent)->m_first_child), iterator(tree__, NONE))
762  :
763  children_view(end(), end());
764  }
765  /** get an iterable view over all siblings (including the calling node) */
766  C4_ALWAYS_INLINE const_children_view siblings() const RYML_NOEXCEPT
767  {
768  _C4RR();
769  NodeData const *nd = tree_->get(id_);
770  return (nd->m_parent != NONE) ? // does it have a parent?
771  const_children_view(const_iterator(tree_, tree_->get(nd->m_parent)->m_first_child), const_iterator(tree_, NONE))
772  :
774  }
775  /** get an iterable view over all siblings (including the calling node) */
776  C4_ALWAYS_INLINE const_children_view csiblings() const RYML_NOEXCEPT { return siblings(); }
777 
778  /** visit every child node calling fn(node) */
779  template<class Visitor>
780  bool visit(Visitor fn, id_type indentation_level=0, bool skip_root=true) const RYML_NOEXCEPT
781  {
782  _C4RR();
783  return detail::_visit(*(ConstImpl const*)this, fn, indentation_level, skip_root);
784  }
785  /** visit every child node calling fn(node) */
786  template<class Visitor, class U=Impl>
787  auto visit(Visitor fn, id_type indentation_level=0, bool skip_root=true) RYML_NOEXCEPT
788  -> _C4_IF_MUTABLE(bool)
789  {
790  _C4RR();
791  return detail::_visit(*(Impl*)this, fn, indentation_level, skip_root);
792  }
793 
794  /** visit every child node calling fn(node, level) */
795  template<class Visitor>
796  bool visit_stacked(Visitor fn, id_type indentation_level=0, bool skip_root=true) const RYML_NOEXCEPT
797  {
798  _C4RR();
799  return detail::_visit_stacked(*(ConstImpl const*)this, fn, indentation_level, skip_root);
800  }
801  /** visit every child node calling fn(node, level) */
802  template<class Visitor, class U=Impl>
803  auto visit_stacked(Visitor fn, id_type indentation_level=0, bool skip_root=true) RYML_NOEXCEPT
804  -> _C4_IF_MUTABLE(bool)
805  {
806  _C4RR();
807  return detail::_visit_stacked(*(Impl*)this, fn, indentation_level, skip_root);
808  }
809 
810  /** @} */
811 
812  #if defined(__clang__)
813  # pragma clang diagnostic pop
814  #elif defined(__GNUC__)
815  # pragma GCC diagnostic pop
816  #endif
817 
818  #undef _C4_IF_MUTABLE
819  #undef _C4RR
820  #undef tree_
821  #undef tree__
822  #undef id_
823  #undef id__
824 
825  C4_SUPPRESS_WARNING_GCC_CLANG_POP
826 };
827 } // detail
828 
829 
830 //-----------------------------------------------------------------------------
831 //-----------------------------------------------------------------------------
832 //-----------------------------------------------------------------------------
833 /** Holds a pointer to an existing tree, and a node id. It can be used
834  * only to read from the tree.
835  *
836  * @warning The lifetime of the tree must be larger than that of this
837  * object. It is up to the user to ensure that this happens. */
838 class RYML_EXPORT ConstNodeRef : public detail::RoNodeMethods<ConstNodeRef, ConstNodeRef> // NOLINT
839 {
840 public:
841 
842  using tree_type = Tree const;
843 
844 public:
845 
846  Tree const* C4_RESTRICT m_tree;
848 
849  friend NodeRef;
851 
852 public:
853 
854  /** @name construction */
855  /** @{ */
856 
857  ConstNodeRef() noexcept : m_tree(nullptr), m_id(NONE) {}
858  ConstNodeRef(Tree const &t) noexcept : m_tree(&t), m_id(t .root_id()) {}
859  ConstNodeRef(Tree const *t) noexcept : m_tree(t ), m_id(t->root_id()) {}
860  ConstNodeRef(Tree const *t, id_type id) noexcept : m_tree(t), m_id(id) {}
861  ConstNodeRef(std::nullptr_t) noexcept : m_tree(nullptr), m_id(NONE) {}
862 
863  ConstNodeRef(ConstNodeRef const&) noexcept = default;
864  ConstNodeRef(ConstNodeRef &&) noexcept = default;
865 
866  inline ConstNodeRef(NodeRef const&) noexcept;
867  inline ConstNodeRef(NodeRef &&) noexcept;
868 
869  /** @} */
870 
871 public:
872 
873  /** @name assignment */
874  /** @{ */
875 
876  ConstNodeRef& operator= (std::nullptr_t) noexcept { m_tree = nullptr; m_id = NONE; return *this; }
877 
878  ConstNodeRef& operator= (ConstNodeRef const&) noexcept = default;
879  ConstNodeRef& operator= (ConstNodeRef &&) noexcept = default;
880 
881  ConstNodeRef& operator= (NodeRef const&) noexcept;
882  ConstNodeRef& operator= (NodeRef &&) noexcept;
883 
884 
885  /** @} */
886 
887 public:
888 
889  /** @name state queries
890  *
891  * see @ref NodeRef for an explanation on what these states mean */
892  /** @{ */
893 
894  C4_ALWAYS_INLINE bool invalid() const noexcept { return (!m_tree) || (m_id == NONE); }
895  /** because a ConstNodeRef cannot be used to write to the tree,
896  * readable() has the same meaning as !invalid() */
897  C4_ALWAYS_INLINE bool readable() const noexcept { return m_tree != nullptr && m_id != NONE; }
898  /** because a ConstNodeRef cannot be used to write to the tree, it can never be a seed.
899  * This method is provided for API equivalence between ConstNodeRef and NodeRef. */
900  constexpr static C4_ALWAYS_INLINE bool is_seed() noexcept { return false; }
901 
902  RYML_DEPRECATED("use one of readable(), is_seed() or !invalid()") bool valid() const noexcept { return m_tree != nullptr && m_id != NONE; }
903 
904  /** @} */
905 
906 public:
907 
908  /** @name member getters */
909  /** @{ */
910 
911  C4_ALWAYS_INLINE Tree const* tree() const noexcept { return m_tree; }
912  C4_ALWAYS_INLINE id_type id() const noexcept { return m_id; }
913 
914  /** @} */
915 
916 public:
917 
918  /** @name comparisons */
919  /** @{ */
920 
921  C4_ALWAYS_INLINE bool operator== (ConstNodeRef const& that) const RYML_NOEXCEPT { return that.m_tree == m_tree && m_id == that.m_id; }
922  C4_ALWAYS_INLINE bool operator!= (ConstNodeRef const& that) const RYML_NOEXCEPT { return ! this->operator== (that); }
923 
924  /** @cond dev */
925  RYML_DEPRECATED("use invalid()") bool operator== (std::nullptr_t) const noexcept { return m_tree == nullptr || m_id == NONE; }
926  RYML_DEPRECATED("use !invalid()") bool operator!= (std::nullptr_t) const noexcept { return !(m_tree == nullptr || m_id == NONE); }
927 
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; }
929  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; }
930  /** @endcond */
931 
932  /** @} */
933 
934 };
935 
936 
937 //-----------------------------------------------------------------------------
938 //-----------------------------------------------------------------------------
939 //-----------------------------------------------------------------------------
940 
941 // NOLINTBEGIN(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
942 
943 /** A reference to a node in an existing yaml tree, offering a more
944  * convenient API than the index-based API used in the tree.
945  *
946  * Unlike its imutable ConstNodeRef peer, a NodeRef can be used to
947  * mutate the tree, both by writing to existing nodes and by creating
948  * new nodes to subsequently write to. Semantically, a NodeRef
949  * object can be in one of three states:
950  *
951  * ```text
952  * invalid := not pointing at anything
953  * readable := points at an existing tree/node
954  * seed := points at an existing tree, and the node
955  * may come to exist, if we write to it.
956  * ```
957  *
958  * So both `readable` and `seed` are states where the node is also `valid`.
959  *
960  * ```cpp
961  * Tree t = parse_in_arena("{a: b}");
962  * NodeRef invalid; // not pointing at anything.
963  * NodeRef readable = t["a"]; // also valid, because "a" exists
964  * NodeRef seed = t["none"]; // also valid, but is seed because "none" is not in the map
965  * ```
966  *
967  * When the object is in seed state, using it to read from the tree is
968  * UB. The seed node can be used to write to the tree, provided that
969  * its create() method is called prior to writing, which happens in
970  * most modifying methods in NodeRef.
971  *
972  * It is the owners's responsibility to verify that an existing
973  * node is readable before subsequently using it to read from the
974  * tree.
975  *
976  * @warning The lifetime of the tree must be larger than that of this
977  * object. It is up to the user to ensure that this happens.
978  */
979 class RYML_EXPORT NodeRef : public detail::RoNodeMethods<NodeRef, ConstNodeRef> // NOLINT
980 {
981 public:
982 
983  using tree_type = Tree;
985 
986 private:
987 
988  Tree *C4_RESTRICT m_tree;
989  id_type m_id;
990 
991  /** This member is used to enable lazy operator[] writing. When a child
992  * with a key or index is not found, m_id is set to the id of the parent
993  * and the asked-for key or index are stored in this member until a write
994  * does happen. Then it is given as key or index for creating the child.
995  * When a key is used, the csubstr stores it (so the csubstr's string is
996  * non-null and the csubstr's size is different from NONE). When an index is
997  * used instead, the csubstr's string is set to null, and only the csubstr's
998  * size is set to a value different from NONE. Otherwise, when operator[]
999  * does find the child then this member is empty: the string is null and
1000  * the size is NONE. */
1001  csubstr m_seed;
1002 
1004  friend struct detail::RoNodeMethods<NodeRef, ConstNodeRef>;
1005 
1006  // require valid: a helper macro, undefined at the end
1007  #define _C4RR() \
1008  RYML_ASSERT(m_tree != nullptr); \
1009  _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE && !is_seed())
1010  // require id: a helper macro, undefined at the end
1011  #define _C4RID() \
1012  RYML_ASSERT(m_tree != nullptr); \
1013  _RYML_CB_ASSERT(m_tree->m_callbacks, m_id != NONE)
1014 
1015 public:
1016 
1017  /** @name construction */
1018  /** @{ */
1019 
1020  NodeRef() noexcept : m_tree(nullptr), m_id(NONE), m_seed() { _clear_seed(); }
1021  NodeRef(Tree &t) noexcept : m_tree(&t), m_id(t .root_id()), m_seed() { _clear_seed(); }
1022  NodeRef(Tree *t) noexcept : m_tree(t ), m_id(t->root_id()), m_seed() { _clear_seed(); }
1023  NodeRef(Tree *t, id_type id) noexcept : m_tree(t), m_id(id), m_seed() { _clear_seed(); }
1024  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(Tree *t, id_type id, csubstr seed_key) noexcept : m_tree(t), m_id(id), m_seed(seed_key) {}
1026  NodeRef(std::nullptr_t) noexcept : m_tree(nullptr), m_id(NONE), m_seed() {}
1027 
1028  void _clear_seed() noexcept { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = npos; }
1029 
1030  /** @} */
1031 
1032 public:
1033 
1034  /** @name assignment */
1035  /** @{ */
1036 
1037  NodeRef(NodeRef const&) noexcept = default;
1038  NodeRef(NodeRef &&) noexcept = default;
1039 
1040  NodeRef& operator= (NodeRef const&) noexcept = default;
1041  NodeRef& operator= (NodeRef &&) noexcept = default;
1042 
1043  /** @} */
1044 
1045 public:
1046 
1047  /** @name state_queries
1048  * @{ */
1049 
1050  /** true if the object is not referring to any existing or seed node. @see the doc for @ref NodeRef */
1051  bool invalid() const noexcept { return m_tree == nullptr || m_id == NONE; }
1052  /** true if the object is not invalid and in seed state. @see the doc for @ref NodeRef */
1053  bool is_seed() const noexcept { return (m_tree != nullptr && m_id != NONE) && (m_seed.str != nullptr || m_seed.len != (size_t)NONE); }
1054  /** true if the object is not invalid and not in seed state. @see the doc for @ref NodeRef */
1055  bool readable() const noexcept { return (m_tree != nullptr && m_id != NONE) && (m_seed.str == nullptr && m_seed.len == (size_t)NONE); }
1056 
1057  RYML_DEPRECATED("use one of readable(), is_seed() or !invalid()") inline bool valid() const { return m_tree != nullptr && m_id != NONE; }
1058 
1059  /** @} */
1060 
1061 public:
1062 
1063  /** @name comparisons */
1064  /** @{ */
1065 
1066  bool operator== (NodeRef const& that) const
1067  {
1068  if(m_tree == that.m_tree && m_id == that.m_id)
1069  {
1070  bool seed = is_seed();
1071  if(seed == that.is_seed())
1072  {
1073  if(seed)
1074  {
1075  return (m_seed.len == that.m_seed.len)
1076  && (m_seed.str == that.m_seed.str
1077  || m_seed == that.m_seed); // do strcmp only in the last resort
1078  }
1079  return true;
1080  }
1081  }
1082  return false;
1083  }
1084  bool operator!= (NodeRef const& that) const { return ! this->operator==(that); }
1085 
1086  bool operator== (ConstNodeRef const& that) const { return m_tree == that.m_tree && m_id == that.m_id && !is_seed(); }
1087  bool operator!= (ConstNodeRef const& that) const { return ! this->operator==(that); }
1088 
1089  /** @cond dev */
1090  RYML_DEPRECATED("use !readable()") bool operator== (std::nullptr_t) const { return m_tree == nullptr || m_id == NONE || is_seed(); }
1091  RYML_DEPRECATED("use readable()") bool operator!= (std::nullptr_t) const { return !(m_tree == nullptr || m_id == NONE || is_seed()); }
1092 
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; }
1094  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; }
1095  /** @endcond */
1096 
1097 public:
1098 
1099  /** @name node_property_getters
1100  * @{ */
1101 
1102  C4_ALWAYS_INLINE Tree * tree() noexcept { return m_tree; }
1103  C4_ALWAYS_INLINE Tree const* tree() const noexcept { return m_tree; }
1104 
1105  C4_ALWAYS_INLINE id_type id() const noexcept { return m_id; }
1106 
1107  /** @} */
1108 
1109 public:
1110 
1111  /** @name node_modifiers */
1112  /** @{ */
1113 
1114  void create() { _apply_seed(); }
1115 
1116  void change_type(NodeType t) { _C4RR(); m_tree->change_type(m_id, t); }
1117 
1118  void set_type(NodeType t) { _apply_seed(); m_tree->_set_flags(m_id, t); }
1119  void set_key(csubstr key) { _apply_seed(); m_tree->_set_key(m_id, key); }
1120  void set_val(csubstr val) { _apply_seed(); m_tree->_set_val(m_id, val); }
1121  void set_key_tag(csubstr key_tag) { _apply_seed(); m_tree->set_key_tag(m_id, key_tag); }
1122  void set_val_tag(csubstr val_tag) { _apply_seed(); m_tree->set_val_tag(m_id, val_tag); }
1123  void set_key_anchor(csubstr key_anchor) { _apply_seed(); m_tree->set_key_anchor(m_id, key_anchor); }
1124  void set_val_anchor(csubstr val_anchor) { _apply_seed(); m_tree->set_val_anchor(m_id, val_anchor); }
1125  void set_key_ref(csubstr key_ref) { _apply_seed(); m_tree->set_key_ref(m_id, key_ref); }
1126  void set_val_ref(csubstr val_ref) { _apply_seed(); m_tree->set_val_ref(m_id, val_ref); }
1127 
1128  void set_container_style(NodeType_e style) { _C4RR(); m_tree->set_container_style(m_id, style); }
1129  void set_key_style(NodeType_e style) { _C4RR(); m_tree->set_key_style(m_id, style); }
1130  void set_val_style(NodeType_e style) { _C4RR(); m_tree->set_val_style(m_id, style); }
1131 
1132 public:
1133 
1134  void clear()
1135  {
1136  if(is_seed())
1137  return;
1138  m_tree->remove_children(m_id);
1139  m_tree->_clear(m_id);
1140  }
1141 
1142  void clear_key()
1143  {
1144  if(is_seed())
1145  return;
1146  m_tree->_clear_key(m_id);
1147  }
1148 
1149  void clear_val()
1150  {
1151  if(is_seed())
1152  return;
1153  m_tree->_clear_val(m_id);
1154  }
1155 
1157  {
1158  if(is_seed())
1159  return;
1160  m_tree->remove_children(m_id);
1161  }
1162 
1163  void operator= (NodeType_e t)
1164  {
1165  _apply_seed();
1166  m_tree->_add_flags(m_id, t);
1167  }
1168 
1170  {
1171  _apply_seed();
1172  m_tree->_add_flags(m_id, t);
1173  }
1174 
1175  void operator= (NodeInit const& v)
1176  {
1177  _apply_seed();
1178  _apply(v);
1179  }
1180 
1181  void operator= (NodeScalar const& v)
1182  {
1183  _apply_seed();
1184  _apply(v);
1185  }
1186 
1187  void operator= (std::nullptr_t)
1188  {
1189  _apply_seed();
1190  _apply(csubstr{});
1191  }
1192 
1193  void operator= (csubstr v)
1194  {
1195  _apply_seed();
1196  _apply(v);
1197  }
1198 
1199  template<size_t N>
1200  void operator= (const char (&v)[N])
1201  {
1202  _apply_seed();
1203  csubstr sv;
1204  sv.assign<N>(v);
1205  _apply(sv);
1206  }
1207 
1208  /** @} */
1209 
1210 public:
1211 
1212  /** @name serialization */
1213  /** @{ */
1214 
1215  /** serialize a variable to the arena */
1216  template<class T>
1217  csubstr to_arena(T const& C4_RESTRICT s)
1218  {
1219  RYML_ASSERT(m_tree); // no need for valid or readable
1220  return m_tree->to_arena(s);
1221  }
1222 
1223  template<class T>
1224  size_t set_key_serialized(T const& C4_RESTRICT k)
1225  {
1226  _apply_seed();
1227  csubstr s = m_tree->to_arena(k);
1228  m_tree->_set_key(m_id, s);
1229  return s.len;
1230  }
1231  size_t set_key_serialized(std::nullptr_t)
1232  {
1233  _apply_seed();
1234  m_tree->_set_key(m_id, csubstr{});
1235  return 0;
1236  }
1237 
1238  template<class T>
1239  size_t set_val_serialized(T const& C4_RESTRICT v)
1240  {
1241  _apply_seed();
1242  csubstr s = m_tree->to_arena(v);
1243  m_tree->_set_val(m_id, s);
1244  return s.len;
1245  }
1246  size_t set_val_serialized(std::nullptr_t)
1247  {
1248  _apply_seed();
1249  m_tree->_set_val(m_id, csubstr{});
1250  return 0;
1251  }
1252 
1253  /** encode a blob as base64 into the tree's arena, then assign the
1254  * result to the node's key
1255  * @return the size of base64-encoded blob */
1256  size_t set_key_serialized(fmt::const_base64_wrapper w);
1257  /** encode a blob as base64 into the tree's arena, then assign the
1258  * result to the node's val
1259  * @return the size of base64-encoded blob */
1260  size_t set_val_serialized(fmt::const_base64_wrapper w);
1261 
1262  /** serialize a variable, then assign the result to the node's val */
1263  NodeRef& operator<< (csubstr s)
1264  {
1265  // this overload is needed to prevent ambiguity (there's also
1266  // operator<< for writing a substr to a stream)
1267  _apply_seed();
1268  write(this, s);
1269  _RYML_CB_ASSERT(m_tree->m_callbacks, val() == s);
1270  return *this;
1271  }
1272 
1273  template<class T>
1274  NodeRef& operator<< (T const& C4_RESTRICT v)
1275  {
1276  _apply_seed();
1277  write(this, v);
1278  return *this;
1279  }
1280 
1281  /** serialize a variable, then assign the result to the node's key */
1282  template<class T>
1283  NodeRef& operator<< (Key<const T> const& C4_RESTRICT v)
1284  {
1285  _apply_seed();
1286  set_key_serialized(v.k);
1287  return *this;
1288  }
1289 
1290  /** serialize a variable, then assign the result to the node's key */
1291  template<class T>
1292  NodeRef& operator<< (Key<T> const& C4_RESTRICT v)
1293  {
1294  _apply_seed();
1295  set_key_serialized(v.k);
1296  return *this;
1297  }
1298 
1300  {
1301  set_key_serialized(w.wrapper);
1302  return *this;
1303  }
1304 
1306  {
1307  set_val_serialized(w);
1308  return *this;
1309  }
1310 
1311  /** @} */
1312 
1313 private:
1314 
1315  void _apply_seed()
1316  {
1317  _C4RID();
1318  if(m_seed.str) // we have a seed key: use it to create the new child
1319  {
1320  m_id = m_tree->append_child(m_id);
1321  m_tree->_set_key(m_id, m_seed);
1322  m_seed.str = nullptr;
1323  m_seed.len = (size_t)NONE;
1324  }
1325  else if(m_seed.len != (size_t)NONE) // we have a seed index: create a child at that position
1326  {
1327  _RYML_CB_ASSERT(m_tree->m_callbacks, (size_t)m_tree->num_children(m_id) == m_seed.len);
1328  m_id = m_tree->append_child(m_id);
1329  m_seed.str = nullptr;
1330  m_seed.len = (size_t)NONE;
1331  }
1332  else
1333  {
1334  _RYML_CB_ASSERT(m_tree->m_callbacks, readable());
1335  }
1336  }
1337 
1338  void _apply(csubstr v)
1339  {
1340  m_tree->_set_val(m_id, v);
1341  }
1342 
1343  void _apply(NodeScalar const& v)
1344  {
1345  m_tree->_set_val(m_id, v);
1346  }
1347 
1348  void _apply(NodeInit const& i)
1349  {
1350  m_tree->_set(m_id, i);
1351  }
1352 
1353 public:
1354 
1355  /** @name modification of hierarchy */
1356  /** @{ */
1357 
1359  {
1360  _C4RR();
1361  _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1362  NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1363  return r;
1364  }
1365 
1367  {
1368  _C4RR();
1369  _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1370  NodeRef r(m_tree, m_tree->insert_child(m_id, after.m_id));
1371  r._apply(i);
1372  return r;
1373  }
1374 
1376  {
1377  _C4RR();
1378  NodeRef r(m_tree, m_tree->insert_child(m_id, NONE));
1379  return r;
1380  }
1381 
1383  {
1384  _C4RR();
1385  NodeRef r(m_tree, m_tree->insert_child(m_id, NONE));
1386  r._apply(i);
1387  return r;
1388  }
1389 
1391  {
1392  _C4RR();
1393  NodeRef r(m_tree, m_tree->append_child(m_id));
1394  return r;
1395  }
1396 
1398  {
1399  _C4RR();
1400  NodeRef r(m_tree, m_tree->append_child(m_id));
1401  r._apply(i);
1402  return r;
1403  }
1404 
1406  {
1407  _C4RR();
1408  _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1409  NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.m_id));
1410  return r;
1411  }
1412 
1414  {
1415  _C4RR();
1416  _RYML_CB_ASSERT(m_tree->m_callbacks, after.m_tree == m_tree);
1417  NodeRef r(m_tree, m_tree->insert_sibling(m_id, after.m_id));
1418  r._apply(i);
1419  return r;
1420  }
1421 
1423  {
1424  _C4RR();
1425  NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1426  return r;
1427  }
1428 
1430  {
1431  _C4RR();
1432  NodeRef r(m_tree, m_tree->prepend_sibling(m_id));
1433  r._apply(i);
1434  return r;
1435  }
1436 
1438  {
1439  _C4RR();
1440  NodeRef r(m_tree, m_tree->append_sibling(m_id));
1441  return r;
1442  }
1443 
1445  {
1446  _C4RR();
1447  NodeRef r(m_tree, m_tree->append_sibling(m_id));
1448  r._apply(i);
1449  return r;
1450  }
1451 
1452 public:
1453 
1454  void remove_child(NodeRef & child)
1455  {
1456  _C4RR();
1457  _RYML_CB_ASSERT(m_tree->m_callbacks, has_child(child));
1458  _RYML_CB_ASSERT(m_tree->m_callbacks, child.parent().id() == id());
1459  m_tree->remove(child.id());
1460  child.clear();
1461  }
1462 
1463  //! remove the nth child of this node
1465  {
1466  _C4RR();
1467  _RYML_CB_ASSERT(m_tree->m_callbacks, pos >= 0 && pos < num_children());
1468  id_type child = m_tree->child(m_id, pos);
1469  _RYML_CB_ASSERT(m_tree->m_callbacks, child != NONE);
1470  m_tree->remove(child);
1471  }
1472 
1473  //! remove a child by name
1474  void remove_child(csubstr key)
1475  {
1476  _C4RR();
1477  id_type child = m_tree->find_child(m_id, key);
1478  _RYML_CB_ASSERT(m_tree->m_callbacks, child != NONE);
1479  m_tree->remove(child);
1480  }
1481 
1482 public:
1483 
1484  /** change the node's position within its parent, placing it after
1485  * @p after. To move to the first position in the parent, simply
1486  * pass an empty or default-constructed reference like this:
1487  * `n.move({})`. */
1488  void move(ConstNodeRef const& after)
1489  {
1490  _C4RR();
1491  m_tree->move(m_id, after.m_id);
1492  }
1493 
1494  /** move the node to a different @p parent (which may belong to a
1495  * different tree), placing it after @p after. When the
1496  * destination parent is in a new tree, then this node's tree
1497  * pointer is reset to the tree of the parent node. */
1498  void move(NodeRef const& parent, ConstNodeRef const& after)
1499  {
1500  _C4RR();
1501  if(parent.m_tree == m_tree)
1502  {
1503  m_tree->move(m_id, parent.m_id, after.m_id);
1504  }
1505  else
1506  {
1507  parent.m_tree->move(m_tree, m_id, parent.m_id, after.m_id);
1508  m_tree = parent.m_tree;
1509  }
1510  }
1511 
1512  /** duplicate the current node somewhere within its parent, and
1513  * place it after the node @p after. To place into the first
1514  * position of the parent, simply pass an empty or
1515  * default-constructed reference like this: `n.move({})`. */
1516  NodeRef duplicate(ConstNodeRef const& after) const
1517  {
1518  _C4RR();
1519  _RYML_CB_ASSERT(m_tree->m_callbacks, m_tree == after.m_tree || after.m_id == NONE);
1520  id_type dup = m_tree->duplicate(m_id, m_tree->parent(m_id), after.m_id);
1521  NodeRef r(m_tree, dup);
1522  return r;
1523  }
1524 
1525  /** duplicate the current node somewhere into a different @p parent
1526  * (possibly from a different tree), and place it after the node
1527  * @p after. To place into the first position of the parent,
1528  * simply pass an empty or default-constructed reference like
1529  * this: `n.move({})`. */
1530  NodeRef duplicate(NodeRef const& parent, ConstNodeRef const& after) const
1531  {
1532  _C4RR();
1533  _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.m_tree || after.m_id == NONE);
1534  if(parent.m_tree == m_tree)
1535  {
1536  id_type dup = m_tree->duplicate(m_id, parent.m_id, after.m_id);
1537  NodeRef r(m_tree, dup);
1538  return r;
1539  }
1540  else
1541  {
1542  id_type dup = parent.m_tree->duplicate(m_tree, m_id, parent.m_id, after.m_id);
1543  NodeRef r(parent.m_tree, dup);
1544  return r;
1545  }
1546  }
1547 
1548  void duplicate_children(NodeRef const& parent, ConstNodeRef const& after) const
1549  {
1550  _C4RR();
1551  _RYML_CB_ASSERT(m_tree->m_callbacks, parent.m_tree == after.m_tree);
1552  if(parent.m_tree == m_tree)
1553  {
1554  m_tree->duplicate_children(m_id, parent.m_id, after.m_id);
1555  }
1556  else
1557  {
1558  parent.m_tree->duplicate_children(m_tree, m_id, parent.m_id, after.m_id);
1559  }
1560  }
1561 
1562  /** @} */
1563 
1564 #undef _C4RR
1565 #undef _C4RID
1566 };
1567 
1568 // NOLINTEND(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
1569 
1570 
1571 //-----------------------------------------------------------------------------
1572 
1573 inline ConstNodeRef::ConstNodeRef(NodeRef const& that) noexcept
1574  : m_tree(that.m_tree)
1575  , m_id(!that.is_seed() ? that.id() : (id_type)NONE)
1576 {
1577 }
1578 
1579 inline ConstNodeRef::ConstNodeRef(NodeRef && that) noexcept // NOLINT
1580  : m_tree(that.m_tree)
1581  , m_id(!that.is_seed() ? that.id() : (id_type)NONE)
1582 {
1583 }
1584 
1585 
1586 inline ConstNodeRef& ConstNodeRef::operator= (NodeRef const& that) noexcept
1587 {
1588  m_tree = (that.m_tree);
1589  m_id = (!that.is_seed() ? that.id() : (id_type)NONE);
1590  return *this;
1591 }
1592 
1593 inline ConstNodeRef& ConstNodeRef::operator= (NodeRef && that) noexcept // NOLINT
1594 {
1595  m_tree = (that.m_tree);
1596  m_id = (!that.is_seed() ? that.id() : (id_type)NONE);
1597  return *this;
1598 }
1599 
1600 
1601 //-----------------------------------------------------------------------------
1602 
1603 /** @addtogroup doc_serialization_helpers
1604  *
1605  * @{
1606  */
1607 
1608 template<class T>
1609 C4_ALWAYS_INLINE void write(NodeRef *n, T const& v)
1610 {
1611  n->set_val_serialized(v);
1612 }
1613 
1614 template<class T>
1615 C4_ALWAYS_INLINE bool read(ConstNodeRef const& C4_RESTRICT n, T *v)
1616 {
1617  return read(n.m_tree, n.m_id, v);
1618 }
1619 
1620 template<class T>
1621 C4_ALWAYS_INLINE bool read(NodeRef const& C4_RESTRICT n, T *v)
1622 {
1623  return read(n.tree(), n.id(), v);
1624 }
1625 
1626 template<class T>
1627 C4_ALWAYS_INLINE bool readkey(ConstNodeRef const& C4_RESTRICT n, T *v)
1628 {
1629  return readkey(n.m_tree, n.m_id, v);
1630 }
1631 
1632 template<class T>
1633 C4_ALWAYS_INLINE bool readkey(NodeRef const& C4_RESTRICT n, T *v)
1634 {
1635  return readkey(n.tree(), n.id(), v);
1636 }
1637 
1638 /** @} */
1639 
1640 /** @} */
1641 
1642 
1643 } // namespace yml
1644 } // namespace c4
1645 
1646 
1647 
1648 #ifdef __clang__
1649 # pragma clang diagnostic pop
1650 #elif defined(__GNUC__)
1651 # pragma GCC diagnostic pop
1652 #elif defined(_MSC_VER)
1653 # pragma warning(pop)
1654 #endif
1655 
1656 #endif /* _C4_YML_NODE_HPP_ */
encoding/decoding for base64.
Holds a pointer to an existing tree, and a node id.
Definition: node.hpp:839
Tree const * tree() const noexcept
Definition: node.hpp:911
ConstNodeRef() noexcept
Definition: node.hpp:857
ConstNodeRef(ConstNodeRef const &) noexcept=default
id_type id() const noexcept
Definition: node.hpp:912
ConstNodeRef(ConstNodeRef &&) noexcept=default
ConstNodeRef(Tree const *t) noexcept
Definition: node.hpp:859
ConstNodeRef(std::nullptr_t) noexcept
Definition: node.hpp:861
ConstNodeRef(Tree const *t, id_type id) noexcept
Definition: node.hpp:860
constexpr static bool is_seed() noexcept
because a ConstNodeRef cannot be used to write to the tree, it can never be a seed.
Definition: node.hpp:900
ConstNodeRef(Tree const &t) noexcept
Definition: node.hpp:858
Tree const tree_type
Definition: node.hpp:842
Tree const * m_tree
Definition: node.hpp:846
ConstNodeRef & operator=(std::nullptr_t) noexcept
Definition: node.hpp:876
bool readable() const noexcept
because a ConstNodeRef cannot be used to write to the tree, readable() has the same meaning as !...
Definition: node.hpp:897
A reference to a node in an existing yaml tree, offering a more convenient API than the index-based A...
Definition: node.hpp:980
void set_val_anchor(csubstr val_anchor)
Definition: node.hpp:1124
void move(ConstNodeRef const &after)
change the node's position within its parent, placing it after after.
Definition: node.hpp:1488
void set_key_style(NodeType_e style)
Definition: node.hpp:1129
NodeRef prepend_child(NodeInit const &i)
Definition: node.hpp:1382
NodeRef insert_sibling(ConstNodeRef const &after)
Definition: node.hpp:1405
NodeRef(Tree *t, id_type id, csubstr seed_key) noexcept
Definition: node.hpp:1025
void set_val_tag(csubstr val_tag)
Definition: node.hpp:1122
NodeRef append_sibling(NodeInit const &i)
Definition: node.hpp:1444
NodeRef insert_sibling(NodeInit const &i, ConstNodeRef const &after)
Definition: node.hpp:1413
NodeRef(NodeRef &&) noexcept=default
NodeRef(Tree *t, id_type id, id_type seed_pos) noexcept
Definition: node.hpp:1024
NodeRef prepend_sibling(NodeInit const &i)
Definition: node.hpp:1429
csubstr to_arena(T const &s)
serialize a variable to the arena
Definition: node.hpp:1217
void _clear_seed() noexcept
Definition: node.hpp:1028
NodeRef insert_child(NodeRef after)
Definition: node.hpp:1358
void set_val(csubstr val)
Definition: node.hpp:1120
NodeRef prepend_sibling()
Definition: node.hpp:1422
void clear()
Definition: node.hpp:1134
size_t set_key_serialized(T const &k)
Definition: node.hpp:1224
void clear_children()
Definition: node.hpp:1156
void set_val_style(NodeType_e style)
Definition: node.hpp:1130
NodeRef(Tree *t, id_type id) noexcept
Definition: node.hpp:1023
NodeRef insert_child(NodeInit const &i, NodeRef after)
Definition: node.hpp:1366
Tree const * tree() const noexcept
Definition: node.hpp:1103
NodeRef() noexcept
Definition: node.hpp:1020
void clear_val()
Definition: node.hpp:1149
NodeRef append_sibling()
Definition: node.hpp:1437
size_t set_val_serialized(std::nullptr_t)
Definition: node.hpp:1246
id_type id() const noexcept
Definition: node.hpp:1105
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.
Definition: node.hpp:1498
void set_container_style(NodeType_e style)
Definition: node.hpp:1128
NodeRef duplicate(ConstNodeRef const &after) const
duplicate the current node somewhere within its parent, and place it after the node after.
Definition: node.hpp:1516
bool readable() const noexcept
true if the object is not invalid and not in seed state.
Definition: node.hpp:1055
void duplicate_children(NodeRef const &parent, ConstNodeRef const &after) const
Definition: node.hpp:1548
NodeRef(Tree *t) noexcept
Definition: node.hpp:1022
NodeRef append_child()
Definition: node.hpp:1390
void clear_key()
Definition: node.hpp:1142
size_t set_val_serialized(T const &v)
Definition: node.hpp:1239
void create()
Definition: node.hpp:1114
NodeRef duplicate(NodeRef const &parent, ConstNodeRef const &after) const
duplicate the current node somewhere into a different parent (possibly from a different tree),...
Definition: node.hpp:1530
void set_type(NodeType t)
Definition: node.hpp:1118
void remove_child(csubstr key)
remove a child by name
Definition: node.hpp:1474
NodeRef prepend_child()
Definition: node.hpp:1375
NodeRef(NodeRef const &) noexcept=default
void set_key_tag(csubstr key_tag)
Definition: node.hpp:1121
size_t set_key_serialized(std::nullptr_t)
Definition: node.hpp:1231
NodeRef append_child(NodeInit const &i)
Definition: node.hpp:1397
NodeRef(std::nullptr_t) noexcept
Definition: node.hpp:1026
void set_key_ref(csubstr key_ref)
Definition: node.hpp:1125
void remove_child(NodeRef &child)
Definition: node.hpp:1454
void set_key_anchor(csubstr key_anchor)
Definition: node.hpp:1123
void change_type(NodeType t)
Definition: node.hpp:1116
NodeRef(Tree &t) noexcept
Definition: node.hpp:1021
bool is_seed() const noexcept
true if the object is not invalid and in seed state.
Definition: node.hpp:1053
void set_key(csubstr key)
Definition: node.hpp:1119
void set_val_ref(csubstr val_ref)
Definition: node.hpp:1126
Tree * tree() noexcept
Definition: node.hpp:1102
void remove_child(id_type pos)
remove the nth child of this node
Definition: node.hpp:1464
void move(id_type node, id_type after)
change the node's position in the parent
Definition: tree.cpp:782
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
Definition: tree.cpp:892
id_type duplicate_children(id_type node, id_type parent, id_type after)
recursively duplicate the node's children (but not the node)
Definition: tree.cpp:914
#define RYML_NOEXCEPT
Conditionally expands to noexcept when RYML_USE_ASSERT is 0 and is empty otherwise.
Definition: common.hpp:167
#define RYML_EXPORT
Definition: export.hpp:15
base64_wrapper_< byte > base64_wrapper
a tag type to mark a payload to be encoded as base64
Definition: base64.hpp:80
base64_wrapper_< cbyte > const_base64_wrapper
a tag type to mark a payload as base64-encoded
Definition: base64.hpp:78
OStream & operator<<(OStream &s, Tree const &t)
emit YAML to an STL-like ostream
Definition: emit.hpp:362
bool from_chars(csubstr buf, uint8_t *v) noexcept
Definition: charconv.hpp:2363
NodeType_e & operator|=(NodeType_e &subject, NodeType_e bits) noexcept
Definition: node_type.hpp:108
NodeType_e
a bit mask for marking node types and styles
Definition: node_type.hpp:30
bool readkey(ConstNodeRef const &n, T *v)
Definition: node.hpp:1627
void write(NodeRef *n, T const &v)
Definition: node.hpp:1609
Key< K > key(K &k)
Definition: node.hpp:43
bool read(ConstNodeRef const &n, T *v)
Definition: node.hpp:1615
bool operator!=(const char(&s)[N], basic_substring< C > const that) noexcept
Definition: substr.hpp:2224
bool operator==(const char(&s)[N], basic_substring< C > const that) noexcept
Definition: substr.hpp:2223
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...
Definition: common.hpp:253
@ npos
a null string position
Definition: common.hpp:267
@ NONE
an index to none
Definition: common.hpp:260
Definition: common.cpp:12
#define _C4RR()
Definition: node.hpp:1007
#define _C4RID()
Definition: node.hpp:1011
fmt::base64_wrapper wrapper
Definition: node.hpp:41
fmt::const_base64_wrapper wrapper
Definition: node.hpp:40
contains the data for each YAML node.
Definition: tree.hpp:181
id_type m_parent
Definition: tree.hpp:187
convenience class to initialize nodes
Definition: tree.hpp:115
a node scalar is a csubstr, which may be tagged and anchored.
Definition: tree.hpp:64
wraps a NodeType_e element with some syntactic sugar and predicates
Definition: node_type.hpp:117
auto at(csubstr key) -> Impl
Find child by key; complexity is O(num_children).
Definition: node.hpp:519
bool type_has_none(NodeType_e bits) const RYML_NOEXCEPT
Forward to Tree::type_has_none().
Definition: node.hpp:270
const_children_view cchildren() const RYML_NOEXCEPT
get an iterable view over children
Definition: node.hpp:752
bool is_key_anchor() const noexcept
Definition: node.hpp:254
auto first_child() RYML_NOEXCEPT -> Impl
Forward to Tree::first_child().
Definition: node.hpp:337
id_type depth_asc() const RYML_NOEXCEPT
Definition: node.hpp:382
bool get_if(csubstr name, T *var) const
look for a child by name, if it exists assign to var.
Definition: node.hpp:642
id_type depth_desc() const RYML_NOEXCEPT
O(log(num_nodes)).
Definition: node.hpp:383
bool has_anchor() const RYML_NOEXCEPT
Forward to Tree::has_anchor().
Definition: node.hpp:247
auto children() RYML_NOEXCEPT -> children_view
get an iterable view over children
Definition: node.hpp:748
bool is_flow_ml() const RYML_NOEXCEPT
Forward to Tree::is_flow_ml().
Definition: node.hpp:275
bool is_val() const RYML_NOEXCEPT
Forward to Tree::is_val().
Definition: node.hpp:241
bool is_key_styled() const RYML_NOEXCEPT
Forward to Tree::is_key_styled().
Definition: node.hpp:278
bool is_root() const RYML_NOEXCEPT
Forward to Tree::is_root().
Definition: node.hpp:303
csubstr key_anchor() const RYML_NOEXCEPT
Forward to Tree::key_anchor().
Definition: node.hpp:210
bool has_val_anchor() const RYML_NOEXCEPT
Forward to Tree::has_val_anchor().
Definition: node.hpp:246
bool has_siblings() const RYML_NOEXCEPT
Definition: node.hpp:317
auto last_child() RYML_NOEXCEPT -> Impl
Forward to Tree::last_child().
Definition: node.hpp:341
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)
Definition: node.hpp:803
bool is_key_plain() const RYML_NOEXCEPT
Forward to Tree::is_key_plain().
Definition: node.hpp:288
bool is_key_quoted() const RYML_NOEXCEPT
Forward to Tree::is_key_quoted().
Definition: node.hpp:290
bool is_stream() const RYML_NOEXCEPT
Forward to Tree::is_stream().
Definition: node.hpp:234
NodeType type() const RYML_NOEXCEPT
Forward to Tree::type_str().
Definition: node.hpp:204
bool empty() const RYML_NOEXCEPT
Forward to Tree::empty().
Definition: node.hpp:233
NodeScalar const & valsc() const RYML_NOEXCEPT
Forward to Tree::valsc().
Definition: node.hpp:218
auto parent() RYML_NOEXCEPT -> Impl
Forward to Tree::parent().
Definition: node.hpp:333
bool has_key_anchor() const RYML_NOEXCEPT
Forward to Tree::has_key_anchor().
Definition: node.hpp:245
bool is_key_unfiltered() const noexcept
Forward to Tree::is_key_unfiltered().
Definition: node.hpp:223
id_type sibling_pos(ConstImpl const &n) const RYML_NOEXCEPT
O(num_siblings).
Definition: node.hpp:380
const_children_view siblings() const RYML_NOEXCEPT
get an iterable view over all siblings (including the calling node)
Definition: node.hpp:766
bool is_key_literal() const RYML_NOEXCEPT
Forward to Tree::is_key_literal().
Definition: node.hpp:280
const_iterator cbegin() const RYML_NOEXCEPT
get an iterator to the first child
Definition: node.hpp:736
csubstr key_ref() const RYML_NOEXCEPT
Forward to Tree::key_ref().
Definition: node.hpp:209
ConstImpl sibling(id_type pos) const RYML_NOEXCEPT
Forward to Tree::sibling().
Definition: node.hpp:370
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)
Definition: node.hpp:796
bool has_child(ConstImpl const &n) const RYML_NOEXCEPT
Forward to Tree::has_child().
Definition: node.hpp:307
ConstImpl const & operator>>(T &v) const
deserialize the node's val to the given variable, forwarding to the user-overrideable read() function...
Definition: node.hpp:619
auto next_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::next_sibling().
Definition: node.hpp:357
bool visit(Visitor fn, id_type indentation_level=0, bool skip_root=true) const RYML_NOEXCEPT
visit every child node calling fn(node)
Definition: node.hpp:780
bool is_quoted() const RYML_NOEXCEPT
Forward to Tree::is_quoted().
Definition: node.hpp:292
bool parent_is_map() const RYML_NOEXCEPT
Forward to Tree::parent_is_map().
Definition: node.hpp:252
auto last_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::last_sibling().
Definition: node.hpp:365
bool has_child(csubstr name) const RYML_NOEXCEPT
Forward to Tree::has_child().
Definition: node.hpp:309
auto find_sibling(csubstr name) RYML_NOEXCEPT -> Impl
Forward to Tree::find_sibling().
Definition: node.hpp:373
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.
Definition: node.hpp:656
bool is_map() const RYML_NOEXCEPT
Forward to Tree::is_map().
Definition: node.hpp:237
bool type_has_any(NodeType_e bits) const RYML_NOEXCEPT
Forward to Tree::type_has_any().
Definition: node.hpp:268
ConstImpl last_sibling() const RYML_NOEXCEPT
Forward to Tree::last_sibling().
Definition: node.hpp:366
bool is_container() const RYML_NOEXCEPT
Forward to Tree::is_container().
Definition: node.hpp:236
id_type num_siblings() const RYML_NOEXCEPT
O(num_children).
Definition: node.hpp:377
ConstImpl last_child() const RYML_NOEXCEPT
Forward to Tree::last_child().
Definition: node.hpp:342
bool has_key() const RYML_NOEXCEPT
Forward to Tree::has_key().
Definition: node.hpp:240
csubstr key_tag() const RYML_NOEXCEPT
Forward to Tree::key_tag().
Definition: node.hpp:208
const_children_view csiblings() const RYML_NOEXCEPT
get an iterable view over all siblings (including the calling node)
Definition: node.hpp:776
auto find_child(csubstr name) RYML_NOEXCEPT -> Impl
Forward to Tree::first_child().
Definition: node.hpp:349
detail::child_iterator< Impl > iterator
Definition: node.hpp:725
csubstr val_ref() const RYML_NOEXCEPT
Forward to Tree::val_ref().
Definition: node.hpp:214
csubstr key() const RYML_NOEXCEPT
Forward to Tree::key().
Definition: node.hpp:207
ConstImpl child(id_type pos) const RYML_NOEXCEPT
Forward to Tree::child().
Definition: node.hpp:346
bool has_sibling(csubstr name) const RYML_NOEXCEPT
Forward to Tree::has_sibling().
Definition: node.hpp:314
NodeScalar const & keysc() const RYML_NOEXCEPT
Forward to Tree::keysc().
Definition: node.hpp:217
size_t deserialize_val(fmt::base64_wrapper v) const
decode the base64-encoded key and assign the decoded blob to the given buffer/
Definition: node.hpp:700
bool has_key_tag() const RYML_NOEXCEPT
Forward to Tree::has_key_tag().
Definition: node.hpp:243
bool is_anchor() const noexcept
Definition: node.hpp:256
csubstr val_tag() const RYML_NOEXCEPT
Forward to Tree::val_tag().
Definition: node.hpp:213
bool is_ancestor(ConstImpl const &ancestor) const RYML_NOEXCEPT
Forward to Tree::is_ancestor() Node must be readable.
Definition: node.hpp:305
ConstImpl next_sibling() const RYML_NOEXCEPT
Forward to Tree::next_sibling().
Definition: node.hpp:358
ConstImpl find_sibling(csubstr name) const RYML_NOEXCEPT
Forward to Tree::find_sibling().
Definition: node.hpp:374
bool is_anchor_or_ref() const noexcept
Definition: node.hpp:257
const char * type_str() const RYML_NOEXCEPT
Forward to Tree::type_str().
Definition: node.hpp:205
csubstr val_anchor() const RYML_NOEXCEPT
Forward to Tree::val_anchor().
Definition: node.hpp:215
const_children_view children() const RYML_NOEXCEPT
get an iterable view over children
Definition: node.hpp:750
auto end() RYML_NOEXCEPT -> iterator
get an iterator to after the last child
Definition: node.hpp:740
auto siblings() RYML_NOEXCEPT -> children_view
get an iterable view over all siblings (including the calling node)
Definition: node.hpp:756
bool has_parent() const RYML_NOEXCEPT
Forward to Tree::has_parent() Node must be readable.
Definition: node.hpp:304
bool is_val_squo() const RYML_NOEXCEPT
Forward to Tree::is_val_squo().
Definition: node.hpp:285
ConstImpl find_child(csubstr name) const RYML_NOEXCEPT
Forward to Tree::first_child().
Definition: node.hpp:350
NodeData const * get() const RYML_NOEXCEPT
returns the data or null when the id is NONE
Definition: node.hpp:199
ConstImpl at(csubstr key) const
Get a child by name, with error checking; complexity is O(num_children).
Definition: node.hpp:576
bool is_val_ref() const RYML_NOEXCEPT
Forward to Tree::is_val_ref().
Definition: node.hpp:249
bool has_other_siblings() const RYML_NOEXCEPT
Forward to Tree::has_sibling().
Definition: node.hpp:315
bool is_val_styled() const RYML_NOEXCEPT
Forward to Tree::is_val_styled().
Definition: node.hpp:279
bool val_is_null() const RYML_NOEXCEPT
Forward to Tree::val_is_null().
Definition: node.hpp:221
auto begin() RYML_NOEXCEPT -> iterator
get an iterator to the first child
Definition: node.hpp:732
bool has_sibling(id_type node) const RYML_NOEXCEPT
Forward to Tree::has_sibling().
Definition: node.hpp:313
id_type child_pos(ConstImpl const &n) const RYML_NOEXCEPT
O(num_children).
Definition: node.hpp:379
bool is_container_styled() const RYML_NOEXCEPT
Forward to Tree::is_container_styled().
Definition: node.hpp:272
detail::children_view_< ConstImpl > const_children_view
Definition: node.hpp:728
auto first_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::first_sibling().
Definition: node.hpp:361
csubstr val() const RYML_NOEXCEPT
Forward to Tree::val().
Definition: node.hpp:212
bool type_has_all(NodeType_e bits) const RYML_NOEXCEPT
Forward to Tree::type_has_all().
Definition: node.hpp:269
bool is_key_ref() const RYML_NOEXCEPT
Forward to Tree::is_key_ref().
Definition: node.hpp:248
const_iterator end() const RYML_NOEXCEPT
get an iterator to after the last child
Definition: node.hpp:742
ConstImpl parent() const RYML_NOEXCEPT
Forward to Tree::parent().
Definition: node.hpp:334
bool key_is_null() const RYML_NOEXCEPT
Forward to Tree::key_is_null().
Definition: node.hpp:220
auto get() RYML_NOEXCEPT -> NodeData *
returns the data or null when the id is NONE
Definition: node.hpp:202
detail::children_view_< Impl > children_view
Definition: node.hpp:727
bool parent_is_seq() const RYML_NOEXCEPT
Forward to Tree::parent_is_seq().
Definition: node.hpp:251
bool is_doc() const RYML_NOEXCEPT
Forward to Tree::is_doc().
Definition: node.hpp:235
auto doc(id_type i) RYML_NOEXCEPT -> Impl
Forward to Tree::doc().
Definition: node.hpp:329
auto visit(Visitor fn, id_type indentation_level=0, bool skip_root=true) RYML_NOEXCEPT -> bool
visit every child node calling fn(node)
Definition: node.hpp:787
bool is_key_dquo() const RYML_NOEXCEPT
Forward to Tree::is_key_dquo().
Definition: node.hpp:286
size_t deserialize_key(fmt::base64_wrapper v) const
decode the base64-encoded key and assign the decoded blob to the given buffer/
Definition: node.hpp:692
id_type num_children() const RYML_NOEXCEPT
O(num_children).
Definition: node.hpp:376
bool is_val_unfiltered() const noexcept
Forward to Tree::is_val_unfiltered().
Definition: node.hpp:224
ConstImpl first_sibling() const RYML_NOEXCEPT
Forward to Tree::first_sibling().
Definition: node.hpp:362
ConstImpl doc(id_type i) const RYML_NOEXCEPT
Forward to Tree::doc().
Definition: node.hpp:330
bool is_flow_sl() const RYML_NOEXCEPT
Forward to Tree::is_flow_sl().
Definition: node.hpp:274
auto at(id_type pos) -> Impl
Find child by position; complexity is O(pos).
Definition: node.hpp:555
bool is_flow() const RYML_NOEXCEPT
Forward to Tree::is_flow().
Definition: node.hpp:276
ConstImpl at(id_type pos) const
Get a child by position, with error checking; complexity is O(pos).
Definition: node.hpp:596
auto child(id_type pos) RYML_NOEXCEPT -> Impl
Forward to Tree::child().
Definition: node.hpp:345
bool is_block() const RYML_NOEXCEPT
Forward to Tree::is_block().
Definition: node.hpp:273
const_iterator cend() const RYML_NOEXCEPT
get an iterator to after the last child
Definition: node.hpp:744
bool is_key_folded() const RYML_NOEXCEPT
Forward to Tree::is_key_folded().
Definition: node.hpp:282
bool is_val_plain() const RYML_NOEXCEPT
Forward to Tree::is_val_plain().
Definition: node.hpp:289
bool is_seq() const RYML_NOEXCEPT
Forward to Tree::is_seq().
Definition: node.hpp:238
bool is_val_folded() const RYML_NOEXCEPT
Forward to Tree::is_val_folded().
Definition: node.hpp:283
detail::child_iterator< ConstImpl > const_iterator
Definition: node.hpp:726
bool has_children() const RYML_NOEXCEPT
Forward to Tree::has_child().
Definition: node.hpp:310
bool is_val_quoted() const RYML_NOEXCEPT
Forward to Tree::is_val_quoted().
Definition: node.hpp:291
auto sibling(id_type pos) RYML_NOEXCEPT -> Impl
Forward to Tree::sibling().
Definition: node.hpp:369
bool is_val_literal() const RYML_NOEXCEPT
Forward to Tree::is_val_literal().
Definition: node.hpp:281
bool has_child(id_type node) const RYML_NOEXCEPT
Forward to Tree::has_child().
Definition: node.hpp:308
bool is_key_squo() const RYML_NOEXCEPT
Forward to Tree::is_key_squo().
Definition: node.hpp:284
bool is_val_hanchor() const noexcept
Definition: node.hpp:255
auto operator[](csubstr key) RYML_NOEXCEPT -> Impl
Find child by key; complexity is O(num_children).
Definition: node.hpp:412
bool has_val() const RYML_NOEXCEPT
Forward to Tree::has_val().
Definition: node.hpp:239
ConstImpl first_child() const RYML_NOEXCEPT
Forward to Tree::first_child().
Definition: node.hpp:338
bool has_sibling(ConstImpl const &n) const RYML_NOEXCEPT
Forward to Tree::has_sibling().
Definition: node.hpp:312
bool is_keyval() const RYML_NOEXCEPT
Forward to Tree::is_keyval().
Definition: node.hpp:242
bool has_val_tag() const RYML_NOEXCEPT
Forward to Tree::has_val_tag().
Definition: node.hpp:244
auto prev_sibling() RYML_NOEXCEPT -> Impl
Forward to Tree::prev_sibling().
Definition: node.hpp:353
ConstImpl prev_sibling() const RYML_NOEXCEPT
Forward to Tree::prev_sibling().
Definition: node.hpp:354
id_type num_other_siblings() const RYML_NOEXCEPT
O(num_siblings).
Definition: node.hpp:378
const_iterator begin() const RYML_NOEXCEPT
get an iterator to the first child
Definition: node.hpp:734
bool is_val_dquo() const RYML_NOEXCEPT
Forward to Tree::is_val_dquo().
Definition: node.hpp:287
bool is_ref() const RYML_NOEXCEPT
Forward to Tree::is_ref().
Definition: node.hpp:250