rapidyaml 0.16.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
c4::yml::Tree Class Reference

#include <tree.hpp>

Classes

struct  lookup_result

Public Member Functions

construction and assignment
 Tree ()
 Tree (Callbacks const &cb)
 Tree (id_type node_capacity, size_t arena_capacity=RYML_DEFAULT_TREE_ARENA_CAPACITY)
 Tree (id_type node_capacity, size_t arena_capacity, Callbacks const &cb)
 ~Tree () noexcept
 Tree (Tree const &that)
 Tree (Tree &&that) noexcept
Tree & operator= (Tree const &that)
Tree & operator= (Tree &&that) noexcept
memory and sizing
void reserve (id_type node_capacity=RYML_DEFAULT_TREE_CAPACITY)
void clear ()
 clear the tree
void clear_arena ()
bool empty () const
 Query for zero size.
id_type size () const
 Get the number of existing nodes.
id_type capacity () const
id_type slack () const
Callbacks const & callbacks () const
void callbacks (Callbacks const &cb)
node getters
NodeData * get (id_type node)
 get a pointer to a node's NodeData. node can be NONE, in which case a nullptr is returned
NodeData const * get (id_type node) const
 get a pointer to a node's NodeData. node can be NONE, in which case a nullptr is returned.
NodeData * _p (id_type node)
 An if-less form of get() that demands a valid node index. This function is implementation only; use at your own risk.
NodeData const * _p (id_type node) const
 An if-less form of get() that demands a valid node index. This function is implementation only; use at your own risk.
id_type root_id () const
 Get the id of the root node. The tree must not be empty. The tree can be empty only when constructed with explicitly zero-capacity.
id_type root_id_maybe () const
 Get the id of the root node, or NONE if the tree is empty.
id_type id (NodeData const *n) const
 get the id of a node belonging to this tree. n can be nullptr, in which case NONE is returned n must belong to this tree
NodeRef helpers
NodeRef ref (id_type node)
 Get a NodeRef of a node by id.
ConstNodeRef ref (id_type node) const
 Get a NodeRef of a node by id.
ConstNodeRef cref (id_type node) const
 Get a NodeRef of a node by id.
NodeRef rootref ()
 Get the root as a NodeRef . Note that a non-const Tree implicitly converts to NodeRef.
ConstNodeRef rootref () const
 Get the root as a ConstNodeRef . Note that Tree implicitly converts to ConstNodeRef.
ConstNodeRef crootref () const
 Get the root as a ConstNodeRef . Note that Tree implicitly converts to ConstNodeRef.
NodeRef docref (id_type i)
 get the i-th document of the stream
ConstNodeRef docref (id_type i) const
 get the i-th document of the stream
ConstNodeRef cdocref (id_type i) const
 get the i-th document of the stream
NodeRef operator[] (csubstr key)
 find a root child (ie child of root) by name, return it as a NodeRef
ConstNodeRef operator[] (csubstr key) const
 find a root child (ie child of root) by name, return it as a NodeRef
NodeRef operator[] (id_type i)
 find a root child (ie child of root) by index: return the root node's i-th child as a NodeRef
ConstNodeRef operator[] (id_type i) const
 find a root child (ie child of root) by index: return the root node's i-th child as a NodeRef
node property getters
NodeType type (id_type node) const
csubstr const & key (id_type node) const
csubstr const & key_tag (id_type node) const
csubstr const & key_ref (id_type node) const
csubstr const & key_anchor (id_type node) const
NodeScalar const & keysc (id_type node) const
csubstr const & val (id_type node) const
csubstr const & val_tag (id_type node) const
csubstr const & val_ref (id_type node) const
csubstr const & val_anchor (id_type node) const
NodeScalar const & valsc (id_type node) const
node type predicates
bool type_has_any (id_type node, type_bits bits) const
bool type_has_all (id_type node, type_bits bits) const
bool type_has_none (id_type node, type_bits bits) const
bool is_stream (id_type node) const
bool is_doc (id_type node) const
bool is_container (id_type node) const
bool is_map (id_type node) const
bool is_seq (id_type node) const
bool has_key (id_type node) const
bool has_val (id_type node) const
bool is_val (id_type node) const
bool is_keyval (id_type node) const
bool has_key_tag (id_type node) const
bool has_val_tag (id_type node) const
bool has_key_anchor (id_type node) const
bool has_val_anchor (id_type node) const
bool has_anchor (id_type node) const
bool is_key_ref (id_type node) const
bool is_val_ref (id_type node) const
bool is_ref (id_type node) const
bool parent_is_seq (id_type node) const
bool parent_is_map (id_type node) const
bool has_anchor (id_type node, csubstr a) const
 true when the node has an anchor named a
bool key_is_null (id_type node) const
 true if the node key is empty, or its scalar verifies scalar_is_null().
bool val_is_null (id_type node) const
 true if the node val is empty, or its scalar verifies scalar_is_null().
bool is_key_unfiltered (id_type node) const
 true if the key was a scalar requiring filtering and was left unfiltered during the parsing (see ParserOptions)
bool is_val_unfiltered (id_type node) const
 true if the val was a scalar requiring filtering and was left unfiltered during the parsing (see ParserOptions)
bool is_key_anchor (id_type node) const
bool is_val_anchor (id_type node) const
bool is_anchor (id_type node) const
bool is_anchor_or_ref (id_type node) const
hierarchy predicates
bool is_root (id_type node) const
bool has_parent (id_type node) const
bool is_ancestor (id_type node, id_type ancestor) const
 true when ancestor is parent or parent of a parent of node
bool empty (id_type node) const
 true when key and val are empty, and has no children
bool has_child (id_type node, id_type ch) const
 true if node has a child with id ch
bool has_child (id_type node, csubstr key) const
 true if node has a child with key key
bool has_children (id_type node) const
 true if node has any children
bool has_sibling (id_type node, id_type sib) const
 true if node has a sibling with id sib
bool has_sibling (id_type node, csubstr key) const
 true if one of the node's siblings has the given key
bool has_other_siblings (id_type node) const
 true if node is not a single child
hierarchy getters
id_type parent (id_type node) const
id_type prev_sibling (id_type node) const
id_type next_sibling (id_type node) const
id_type num_children (id_type node) const
 O(num_children).
id_type child_pos (id_type node, id_type ch) const
id_type first_child (id_type node) const
id_type last_child (id_type node) const
id_type child (id_type node, id_type pos) const
 find child by position, or NONE if there are less than pos children posi
id_type find_child (id_type node, csubstr const &key) const
 find child by name, or NONE if no child is found with this key like Tree::child(), but return a ReadResult with the status
ReadResult child_r (id_type node, id_type pos, id_type *child_id) const
ReadResult find_child_r (id_type node, csubstr const &key, id_type *child_id) const
 like Tree::find_child(), but return a ReadResult with the status
id_type num_siblings (id_type node) const
 O(num_siblings).
id_type num_other_siblings (id_type node) const
 does not count with this
id_type sibling_pos (id_type node, id_type sib) const
id_type first_sibling (id_type node) const
id_type last_sibling (id_type node) const
id_type sibling (id_type node, id_type pos) const
id_type find_sibling (id_type node, csubstr const &key) const
ReadResult sibling_r (id_type node, id_type pos, id_type *sibling_id) const
 like Tree::sibling(), but return a ReadResult with the status
ReadResult find_sibling_r (id_type node, csubstr const &key, id_type *sibling_id) const
 like Tree::find_sibling(), but return a ReadResult if with the status
id_type depth_asc (id_type node) const
 O(log(num_tree_nodes)) get the ascending depth of the node: number of levels between root and node.
id_type depth_desc (id_type node) const
 O(num_tree_nodes) get the descending depth of the node: number of levels between node and deepest child.
id_type doc (id_type i) const
 gets the i document node index.
id_type ancestor_doc (id_type node) const
 get the document which is a parent document of node i, or the root if the tree is not a stream
node style predicates and modifiers. see the corresponding predicate in NodeType
bool is_container_styled (id_type node) const
bool is_block (id_type node) const
bool is_flow_sl (id_type node) const
bool is_flow_ml (id_type node) const
bool is_flow_ml1 (id_type node) const
bool is_flow_mln (id_type node) const
bool is_flow_mlx (id_type node) const
bool is_flow (id_type node) const
bool has_flow_space (id_type node) const
bool is_key_styled (id_type node) const
bool is_val_styled (id_type node) const
bool is_key_literal (id_type node) const
bool is_val_literal (id_type node) const
bool is_key_folded (id_type node) const
bool is_val_folded (id_type node) const
bool is_key_squo (id_type node) const
bool is_val_squo (id_type node) const
bool is_key_dquo (id_type node) const
bool is_val_dquo (id_type node) const
bool is_key_plain (id_type node) const
bool is_val_plain (id_type node) const
bool is_key_quoted (id_type node) const
bool is_val_quoted (id_type node) const
bool is_quoted (id_type node) const
NodeType key_style (id_type node) const
NodeType val_style (id_type node) const
void set_container_style (id_type node, type_bits style)
void set_key_style (id_type node, type_bits style)
void set_val_style (id_type node, type_bits style)
void clear_style (id_type node, bool recurse=false)
void set_style_conditionally (id_type node, NodeType type_mask, NodeType rem_style_flags, NodeType add_style_flags, bool recurse=false)
node type modifiers
void set_stream (id_type node)
void set_doc (id_type node)
void set_val (id_type node, csubstr val) RYML_NOEXCEPT
void set_val (id_type node, csubstr val, NodeType more_flags) RYML_NOEXCEPT
void set_key (id_type node, csubstr key) RYML_NOEXCEPT
void set_key (id_type node, csubstr key, NodeType more_flags) RYML_NOEXCEPT
void set_seq (id_type node) RYML_NOEXCEPT
void set_seq (id_type node, NodeType more_flags) RYML_NOEXCEPT
void set_map (id_type node) RYML_NOEXCEPT
void set_map (id_type node, NodeType more_flags) RYML_NOEXCEPT
void set_key_tag (id_type node, csubstr tag)
void set_val_tag (id_type node, csubstr tag)
void set_key_anchor (id_type node, csubstr anchor)
void set_val_anchor (id_type node, csubstr anchor)
void set_key_ref (id_type node, csubstr ref)
void set_val_ref (id_type node, csubstr ref)
void rem_key_anchor (id_type node)
void rem_val_anchor (id_type node)
void rem_key_ref (id_type node)
void rem_val_ref (id_type node)
void rem_anchor_ref (id_type node)
serialization - checked
template<class T>
void save (id_type node, T const &val)
template<class T>
void save (id_type node, T const &val, NodeType more_flags)
template<class T>
void save_key (id_type node, T const &key)
template<class T>
void save_key (id_type node, T const &key, NodeType more_flags)
serialization - asserted
template<class T>
void set_serialized (id_type node, T const &val) RYML_NOEXCEPT
template<class T>
void set_serialized (id_type node, T const &val, NodeType more_flags) RYML_NOEXCEPT
template<class T>
void set_key_serialized (id_type node, T const &key) RYML_NOEXCEPT
template<class T>
void set_key_serialized (id_type node, T const &key, NodeType more_flags) RYML_NOEXCEPT
deserialization - asserted preconditions
template<class T>
ReadResult deserialize (id_type node, T *v) const
 (1) deserialize a node's contents to a variable
template<class Wrapper>
ReadResult deserialize (id_type node, Wrapper const &w) const
 (2) like (1), but for a wrapper type like those used in tag functions
template<class T>
ReadResult deserialize_key (id_type node, T *v) const
 (1) deserialize a node's key to a variable
template<class Wrapper>
ReadResult deserialize_key (id_type node, Wrapper const &w) const
 (2) like (1), but for a wrapper type like those used in tag functions
lookup and deserialize
template<class T>
ReadResult deserialize_child (id_type node, csubstr child_key, T *v) const
 (1) find a child by name and deserialize its contents to the given variable (ie call .deserialize() on the child if it exists).
template<class T>
ReadResult deserialize_child (id_type node, csubstr child_key, T *v, T const &fallback) const
 (2) like (1), but assign from fallback if no such child exists.
template<class Wrapper>
ReadResult deserialize_child (id_type node, csubstr child_key, Wrapper const &wrapper) const
 (3) like (1), but for wrapper tag types such as c4::fmt::base64()
template<class T>
ReadResult deserialize_child (id_type node, id_type child_pos, T *v) const
 (1) find a child by position and deserialize its contents to the given variable (ie call .deserialize() on the child if it exists).
template<class T>
ReadResult deserialize_child (id_type node, id_type child_pos, T *v, T const &fallback) const
 (2) like (1), but assign from fallback if no such child exists
template<class Wrapper>
ReadResult deserialize_child (id_type node, id_type child_pos, Wrapper const &wrapper) const
 (3) like (1), but for wrapper tag types such as c4::fmt::base64()
tree modifiers
void reorder ()
 reorder the tree in memory so that all the nodes are stored in a linear sequence when visited in depth-first order.
anchors and references/aliases
void resolve (ReferenceResolver *rr, ResolveOptions const &opts={})
 Resolve references (aliases <- anchors), by forwarding to ReferenceResolver::resolve().
void resolve (ResolveOptions const &opts={})
 Resolve references (aliases <- anchors), by forwarding to ReferenceResolver::resolve().
tags and tag directives
void resolve_tags (TagCache &cache, bool all=true)
 Resolve tags in the tree such as "!!str" -> "<tag:yaml.org,2002:str>", "!foo" -> "<!foo>" and custom tags as well, ie tags of the form "!handle!tag" for which there is a corresponding "%TAG" directive.
void normalize_tags ()
void normalize_tags_long ()
id_type num_tag_directives () const
void add_tag_directive (csubstr handle, csubstr prefix, id_type id)
void clear_tag_directives ()
size_t resolve_tag (substr output, csubstr tag, id_type node_id) const
 resolve the given tag, appearing at node_id.
csubstr resolve_tag_sub (substr output, csubstr tag, id_type node_id) const
 Wrapper for Tree::resolve_tag(), returning a substring.
c4::yml::TagDirectiveRange tag_directives () const
modifying hierarchy
id_type insert_child (id_type parent, id_type after)
 create and insert a new child of parent.
id_type prepend_child (id_type parent)
 create and insert a node as the first child of parent
id_type append_child (id_type parent)
 create and insert a node as the last child of parent
id_type _append_child__unprotected (id_type parent)
id_type insert_sibling (id_type node, id_type after)
 create and insert a new sibling of n. insert after "after"
id_type prepend_sibling (id_type node)
 create and insert a node as the first node of parent
id_type append_sibling (id_type node)
void remove (id_type node)
 remove an entire branch at once: ie remove the children and the node itself
void remove_children (id_type node)
 remove all the node's children, but keep the node itself
void move (id_type node, id_type after)
 change the node's position in the parent
void move (id_type node, id_type new_parent, id_type after)
 change the node's parent and position
id_type move (Tree *src, id_type node, id_type new_parent, id_type after)
 change the node's parent and position to a different tree
void set_root_as_stream ()
 ensure the first node is a stream.
bool change_type (id_type node, NodeType type)
bool change_type (id_type node, type_bits type)
id_type duplicate (id_type node, id_type new_parent, id_type after)
 recursively duplicate a node from this tree into a new parent, placing it after one of its children
id_type duplicate (Tree const *src, id_type node, id_type new_parent, id_type after)
 recursively duplicate a node from a different tree into a new parent, placing it after one of its children
id_type duplicate_children (id_type node, id_type parent, id_type after)
 recursively duplicate the node's children (but not the node)
id_type duplicate_children (Tree const *src, id_type node, id_type parent, id_type after)
 recursively duplicate the node's children (but not the node), where the node is from a different tree
id_type duplicate_children_no_rep (id_type node, id_type parent, id_type after)
 duplicate the node's children (but not the node) in a new parent, but omit repetitions where a duplicated node has the same key (in maps) or value (in seqs).
id_type duplicate_children_no_rep (Tree const *src, id_type node, id_type parent, id_type after)
void duplicate_contents (id_type node, id_type where)
void duplicate_contents (Tree const *src, id_type node, id_type where)
void merge_with (Tree const *src, id_type src_node=NONE, id_type dst_root=NONE)
internal string arena
size_t arena_size () const
 get the current size of the tree's internal arena
size_t arena_capacity () const
 get the current capacity of the tree's internal arena
size_t arena_slack () const
 get the current slack of the tree's internal arena
size_t arena_pos () const
csubstr arena () const
 get the current arena
substr arena ()
 get the current arena
csubstr arena_rem () const
 get the free space at the end of the arena
substr arena_rem ()
 get the free space at the end of the arena
bool in_arena (csubstr s) const
 return true if the given substring is part of the tree's string arena
template<class T>
csubstr to_arena (T const &a)
 serialize the given variable to the tree's arena, growing it as needed to accomodate the serialization.
substr copy_to_arena (csubstr s)
 copy the given string to the tree's arena, growing the arena by the required size.
substr alloc_arena (size_t sz)
 grow the tree's string arena by the given size and return a substr of the added portion
void reserve_arena (size_t arena_cap=RYML_DEFAULT_TREE_ARENA_CAPACITY)
 ensure the tree's internal string arena is at least the given capacity
lookup
lookup_result lookup_path (csubstr path, id_type start=NONE) const
 for example foo.bar[0].baz
id_type lookup_path_or_modify (csubstr default_value, csubstr path, id_type start=NONE)
 defaulted lookup: lookup path; if the lookup fails, recursively modify the tree so that the corresponding lookup_path() would return the default value.
id_type lookup_path_or_modify (Tree const *src, id_type src_node, csubstr path, id_type start=NONE)
 defaulted lookup: lookup path; if the lookup fails, recursively modify the tree so that the corresponding lookup_path() would return the branch src_node (from the tree src).

Public Attributes

NodeData * m_buf
id_type m_cap
id_type m_size
id_type m_free_head
id_type m_free_tail
id_type m_first_unused
substr m_arena
size_t m_arena_pos
Callbacks m_callbacks
TagDirectives m_tag_directives

deserialization - checked

These methods raise an error if the deserialization failed or optionally if the node is not readable.

template<class T>
void load (id_type node, T *v, bool check_readable=true) const
 (1) deserialize the node's contents (val or container) to the given variable, forwarding to the user-overrideable read() function (see Read from Tree).
template<class Wrapper>
void load (id_type node, Wrapper const &w, bool check_readable=true) const
 (2) like (1), but for wrapper tag types such as c4::fmt::base64()
template<class T>
void load_key (id_type node, T *k, bool check_readable=true) const
 (1) deserialize the node's key (necessarily a scalar) to the given variable, forwarding to the user-overrideable read_key() function (see Read from ConstNodeRef).
template<class Wrapper>
void load_key (id_type node, Wrapper const &w, bool check_readable=true) const
 (2) like (1), but for wrapper tag types such as c4::fmt::base64()
static ReadResult to_result_ (bool, id_type node) noexcept
static ReadResult to_result_ (ReadResult notlegacy, id_type) noexcept

locations

Location location (Parser const &p, id_type node) const
 Get the location of a node from the parse used to parse this tree.

Detailed Description

Definition at line 310 of file tree.hpp.

Constructor & Destructor Documentation

◆ Tree() [1/6]

c4::yml::Tree::Tree ( )
inline

Definition at line 317 of file tree.hpp.

317: Tree(get_callbacks()) {}
Callbacks const & get_callbacks()
get the global callbacks
Definition common.cpp:94

Referenced by Tree(), Tree(), Tree(), Tree(), Tree(), duplicate(), duplicate_children(), duplicate_children_no_rep(), duplicate_contents(), lookup_path_or_modify(), merge_with(), move(), operator=(), and operator=().

◆ Tree() [2/6]

c4::yml::Tree::Tree ( Callbacks const & cb)

Definition at line 119 of file tree.cpp.

121{
122}
#define RYML_DEFAULT_TREE_CAPACITY
default capacity for the tree when not set explicitly
Definition common.hpp:21
#define RYML_DEFAULT_TREE_ARENA_CAPACITY
default capacity for the tree's arena when not set explicitly
Definition common.hpp:26

◆ Tree() [3/6]

c4::yml::Tree::Tree ( id_type node_capacity,
size_t arena_capacity = RYML_DEFAULT_TREE_ARENA_CAPACITY )
inline

Definition at line 319 of file tree.hpp.

319: Tree(node_capacity, arena_capacity, get_callbacks()) {} // NOLINT
size_t arena_capacity() const
get the current capacity of the tree's internal arena
Definition tree.hpp:1325

◆ Tree() [4/6]

c4::yml::Tree::Tree ( id_type node_capacity,
size_t arena_capacity,
Callbacks const & cb )

Definition at line 124 of file tree.cpp.

125 : m_buf(nullptr)
126 , m_cap(0)
127 , m_size(0)
130 , m_first_unused(0)
131 , m_arena()
132 , m_arena_pos(0)
133 , m_callbacks(cb)
135{
136 if(node_capacity)
137 reserve(node_capacity);
140}
NodeData * m_buf
Definition tree.hpp:1688
id_type m_free_head
Definition tree.hpp:1692
void reserve_arena(size_t arena_cap=RYML_DEFAULT_TREE_ARENA_CAPACITY)
ensure the tree's internal string arena is at least the given capacity
Definition tree.hpp:1423
size_t m_arena_pos
Definition tree.hpp:1697
void reserve(id_type node_capacity=RYML_DEFAULT_TREE_CAPACITY)
Definition tree.cpp:296
TagDirectives m_tag_directives
Definition tree.hpp:1701
id_type m_size
Definition tree.hpp:1690
id_type m_first_unused
Definition tree.hpp:1694
id_type m_cap
Definition tree.hpp:1689
substr m_arena
Definition tree.hpp:1696
id_type m_free_tail
Definition tree.hpp:1693
Callbacks m_callbacks
Definition tree.hpp:1699
@ NONE
an index to none
Definition common.hpp:131

◆ ~Tree()

c4::yml::Tree::~Tree ( )
noexcept

Definition at line 142 of file tree.cpp.

143{
144 _free();
145}

◆ Tree() [5/6]

c4::yml::Tree::Tree ( Tree const & that)

Definition at line 148 of file tree.cpp.

148 : m_callbacks(that.m_callbacks)
149{
150 _clear();
151 _copy(that);
152}

◆ Tree() [6/6]

c4::yml::Tree::Tree ( Tree && that)
noexcept

Definition at line 154 of file tree.cpp.

154 : m_callbacks(that.m_callbacks)
155{
156 _clear();
157 _move(that);
158}

Member Function Documentation

◆ operator=() [1/2]

Tree & c4::yml::Tree::operator= ( Tree const & that)

Definition at line 160 of file tree.cpp.

161{
162 if(&that != this)
163 {
164 _free();
165 m_callbacks = that.m_callbacks;
166 _copy(that);
167 }
168 return *this;
169}

◆ operator=() [2/2]

Tree & c4::yml::Tree::operator= ( Tree && that)
noexcept

Definition at line 171 of file tree.cpp.

172{
173 if(&that != this)
174 {
175 _free();
176 m_callbacks = that.m_callbacks;
177 _move(that);
178 }
179 return *this;
180}

◆ reserve()

void c4::yml::Tree::reserve ( id_type node_capacity = RYML_DEFAULT_TREE_CAPACITY)

Definition at line 296 of file tree.cpp.

297{
298 if(cap > m_cap)
299 {
300 NodeData *buf = RYML_CB_ALLOC_HINT_(m_callbacks, NodeData, (size_t)cap, m_buf);
301 if(m_buf)
302 {
303 memcpy(buf, m_buf, (size_t)m_first_unused * sizeof(NodeData));
304 RYML_CB_FREE_(m_callbacks, m_buf, NodeData, (size_t)m_cap);
305 }
306 m_cap = cap;
307 m_buf = buf;
308 if( ! m_size)
309 _claim_root();
310 }
311}

Referenced by Tree(), sample_global_allocator(), sample_parse_reuse_tree(), and sample_parse_reuse_tree_and_parser().

◆ clear()

void c4::yml::Tree::clear ( )

clear the tree

Note
does NOT clear the arena
See also
clear_arena()

Definition at line 315 of file tree.cpp.

316{
317 m_size = 0;
320 m_first_unused = 0;
321 if(m_buf)
322 {
323 RYML_ASSERT_VISIT_CB_(m_callbacks, m_cap >= 0, this, NONE);
324 _claim_root();
325 }
326 m_tag_directives.clear();
327}

Referenced by sample_empty_null_values(), sample_parse_reuse_tree(), and sample_parse_reuse_tree_and_parser().

◆ clear_arena()

void c4::yml::Tree::clear_arena ( )
inline

Definition at line 343 of file tree.hpp.

343{ m_arena_pos = 0; }

Referenced by clear_arena(), sample_empty_null_values(), and sample_parse_reuse_tree().

◆ empty() [1/2]

bool c4::yml::Tree::empty ( ) const
inline

Query for zero size.

The tree can be empty only when constructed with explicitly zero-capacity.

Definition at line 346 of file tree.hpp.

346{ return m_size == 0; }

Referenced by c4::yml::Emitter< Writer >::emit_as(), normalize_tags(), normalize_tags_long(), c4::yml::operator<<(), c4::yml::operator<<(), and resolve_tags().

◆ size()

id_type c4::yml::Tree::size ( ) const
inline

Get the number of existing nodes.

Definition at line 349 of file tree.hpp.

349{ return m_size; }

Referenced by sample_quick_overview().

◆ capacity()

id_type c4::yml::Tree::capacity ( ) const
inline

Definition at line 350 of file tree.hpp.

350{ return m_cap; }

Referenced by c4::yml::EventHandlerTree::reset().

◆ slack()

id_type c4::yml::Tree::slack ( ) const
inline

Definition at line 351 of file tree.hpp.

351{ RYML_ASSERT_BASIC_(m_cap >= m_size); return m_cap - m_size; }

◆ callbacks() [1/2]

Callbacks const & c4::yml::Tree::callbacks ( ) const
inline

◆ callbacks() [2/2]

void c4::yml::Tree::callbacks ( Callbacks const & cb)
inline

Definition at line 354 of file tree.hpp.

354{ m_callbacks = cb; }

◆ get() [1/2]

NodeData * c4::yml::Tree::get ( id_type node)
inline

get a pointer to a node's NodeData. node can be NONE, in which case a nullptr is returned

Definition at line 365 of file tree.hpp.

366 {
367 if(node == NONE)
368 return nullptr;
369 RYML_ASSERT_VISIT_CB_(m_callbacks, node >= 0 && node < m_cap, this, node);
370 return m_buf + node;
371 }

Referenced by remove_children().

◆ get() [2/2]

NodeData const * c4::yml::Tree::get ( id_type node) const
inline

get a pointer to a node's NodeData. node can be NONE, in which case a nullptr is returned.

Definition at line 374 of file tree.hpp.

375 {
376 if(node == NONE)
377 return nullptr;
378 RYML_ASSERT_VISIT_CB_(m_callbacks, node >= 0 && node < m_cap, this, node);
379 return m_buf + node;
380 }

◆ _p() [1/2]

NodeData * c4::yml::Tree::_p ( id_type node)
inline

An if-less form of get() that demands a valid node index. This function is implementation only; use at your own risk.

Definition at line 384 of file tree.hpp.

384{ RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_first_unused, this, node); return m_buf + node; } // NOLINT(readability-make-member-function-const)

Referenced by _append_child__unprotected(), ancestor_doc(), append_child(), append_sibling(), change_type(), clear_style(), deserialize(), deserialize(), empty(), find_child(), find_sibling(), find_sibling_r(), first_child(), first_sibling(), has_anchor(), has_anchor(), has_child(), has_children(), has_flow_space(), has_key(), has_key_anchor(), has_key_tag(), has_other_siblings(), has_parent(), has_sibling(), has_val(), has_val_anchor(), has_val_tag(), insert_child(), insert_sibling(), is_anchor(), is_anchor_or_ref(), is_block(), is_container(), is_container_styled(), is_doc(), is_flow(), is_flow_ml(), is_flow_ml1(), is_flow_mln(), is_flow_mlx(), is_flow_sl(), is_key_anchor(), is_key_dquo(), is_key_folded(), is_key_literal(), is_key_plain(), is_key_quoted(), is_key_ref(), is_key_squo(), is_key_styled(), is_key_unfiltered(), is_keyval(), is_map(), is_quoted(), is_ref(), is_root(), is_seq(), is_stream(), is_val(), is_val_anchor(), is_val_dquo(), is_val_folded(), is_val_literal(), is_val_plain(), is_val_quoted(), is_val_ref(), is_val_squo(), is_val_styled(), is_val_unfiltered(), key(), key_anchor(), key_is_null(), key_ref(), key_style(), key_tag(), keysc(), last_child(), last_sibling(), load(), load(), load_key(), load_key(), merge_with(), next_sibling(), num_siblings(), parent(), parent_is_map(), parent_is_seq(), prepend_sibling(), prev_sibling(), c4::yml::read(), c4::yml::read(), c4::yml::read_key(), c4::yml::read_key(), rem_anchor_ref(), rem_key_anchor(), rem_key_ref(), rem_val_anchor(), rem_val_ref(), save(), save_key(), set_container_style(), set_doc(), set_key(), set_key(), set_key_anchor(), set_key_ref(), set_key_serialized(), set_key_style(), set_key_tag(), set_map(), set_map(), set_root_as_stream(), set_seq(), set_seq(), set_serialized(), set_stream(), set_style_conditionally(), set_val(), set_val(), set_val_anchor(), set_val_ref(), set_val_style(), set_val_tag(), sibling(), sibling_pos(), sibling_r(), type(), type_has_all(), type_has_any(), type_has_none(), val(), val_anchor(), val_is_null(), val_ref(), val_style(), val_tag(), and valsc().

◆ _p() [2/2]

NodeData const * c4::yml::Tree::_p ( id_type node) const
inline

An if-less form of get() that demands a valid node index. This function is implementation only; use at your own risk.

Definition at line 387 of file tree.hpp.

387{ RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_first_unused, this, node); return m_buf + node; }

◆ root_id()

id_type c4::yml::Tree::root_id ( ) const
inline

Get the id of the root node. The tree must not be empty. The tree can be empty only when constructed with explicitly zero-capacity.

Definition at line 390 of file tree.hpp.

390{ RYML_ASSERT_VISIT_CB_(m_callbacks, m_size > 0, this, id_type(0)); return 0; }
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:124

Referenced by crootref(), doc(), c4::yml::Emitter< Writer >::emit_as(), lookup_path(), merge_with(), normalize_tags(), normalize_tags_long(), c4::yml::operator<<(), c4::yml::operator<<(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_arena(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_in_place(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_arena(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), c4::yml::parse_json_in_place(), reorder(), rootref(), rootref(), sample_docs(), sample_emit_to_container(), sample_emit_to_file(), sample_quick_overview(), sample_user_container_types(), set_root_as_stream(), and sibling_pos().

◆ root_id_maybe()

id_type c4::yml::Tree::root_id_maybe ( ) const
inline

Get the id of the root node, or NONE if the tree is empty.

Definition at line 392 of file tree.hpp.

392{ return m_size ? 0 : id_type(NONE); }

Referenced by c4::yml::emitrs_json(), c4::yml::emitrs_json(), c4::yml::emitrs_yaml(), and c4::yml::emitrs_yaml().

◆ id()

id_type c4::yml::Tree::id ( NodeData const * n) const
inline

get the id of a node belonging to this tree. n can be nullptr, in which case NONE is returned n must belong to this tree

Definition at line 396 of file tree.hpp.

397 {
398 if( ! n)
399 return NONE;
400 RYML_ASSERT_VISIT_CB_(m_callbacks, n >= m_buf && n < m_buf + m_cap, this, NONE);
401 return static_cast<id_type>(n - m_buf);
402 }

Referenced by sample_deserialize_error(), sample_error_visit(), sample_error_visit_location(), sample_serialize_basic(), and set_root_as_stream().

◆ ref() [1/2]

NodeRef c4::yml::Tree::ref ( id_type node)

Get a NodeRef of a node by id.

Definition at line 70 of file tree.cpp.

71{
72 RYML_ASSERT_VISIT_CB_(m_callbacks, id != NONE && id >= 0 && id < m_cap, this, id);
73 return NodeRef(this, id);
74}

Referenced by docref(), ref(), ref(), set_key_ref(), and set_val_ref().

◆ ref() [2/2]

ConstNodeRef c4::yml::Tree::ref ( id_type node) const

Get a NodeRef of a node by id.

Definition at line 75 of file tree.cpp.

76{
77 RYML_ASSERT_VISIT_CB_(m_callbacks, id != NONE && id >= 0 && id < m_cap, this, id);
78 return ConstNodeRef(this, id);
79}

◆ cref()

ConstNodeRef c4::yml::Tree::cref ( id_type node) const

Get a NodeRef of a node by id.

Definition at line 80 of file tree.cpp.

81{
82 RYML_ASSERT_VISIT_CB_(m_callbacks, id != NONE && id >= 0 && id < m_cap, this, id);
83 return ConstNodeRef(this, id);
84}

Referenced by cref().

◆ rootref() [1/2]

NodeRef c4::yml::Tree::rootref ( )

Get the root as a NodeRef . Note that a non-const Tree implicitly converts to NodeRef.

Definition at line 56 of file tree.cpp.

57{
58 return NodeRef(this, root_id());
59}
id_type root_id() const
Get the id of the root node. The tree must not be empty. The tree can be empty only when constructed ...
Definition tree.hpp:390

Referenced by operator[](), operator[](), rootref(), rootref(), sample_anchors_and_aliases_create(), sample_base64(), sample_create_tree(), sample_docs(), sample_empty_null_values(), sample_float_precision(), sample_json(), sample_location_tracking(), sample_parse_reuse_tree(), sample_parse_style(), sample_quick_overview(), sample_std_types(), sample_style(), sample_style_flow_formatting(), sample_style_flow_ml_indent(), sample_tags(), and sample_tree_arena().

◆ rootref() [2/2]

ConstNodeRef c4::yml::Tree::rootref ( ) const

Get the root as a ConstNodeRef . Note that Tree implicitly converts to ConstNodeRef.

Definition at line 60 of file tree.cpp.

61{
62 return ConstNodeRef(this, root_id());
63}

◆ crootref()

ConstNodeRef c4::yml::Tree::crootref ( ) const

Get the root as a ConstNodeRef . Note that Tree implicitly converts to ConstNodeRef.

Definition at line 65 of file tree.cpp.

66{
67 return ConstNodeRef(this, root_id());
68}

Referenced by crootref(), operator[](), operator[](), sample_iterate_tree(), sample_parse_in_arena(), sample_parse_in_place(), and sample_parse_reuse_tree().

◆ docref() [1/2]

NodeRef c4::yml::Tree::docref ( id_type i)

get the i-th document of the stream

Note
i is NOT the node id, but the doc position within the stream

Definition at line 104 of file tree.cpp.

105{
106 return ref(doc(i));
107}
NodeRef ref(id_type node)
Get a NodeRef of a node by id.
Definition tree.cpp:70
id_type doc(id_type i) const
gets the i document node index.
Definition tree.hpp:609

Referenced by docref(), docref(), and sample_docs().

◆ docref() [2/2]

ConstNodeRef c4::yml::Tree::docref ( id_type i) const

get the i-th document of the stream

Note
i is NOT the node id, but the doc position within the stream

Definition at line 108 of file tree.cpp.

109{
110 return ConstNodeRef(this, doc(i));
111}

◆ cdocref()

ConstNodeRef c4::yml::Tree::cdocref ( id_type i) const

get the i-th document of the stream

Note
i is NOT the node id, but the doc position within the stream

Definition at line 112 of file tree.cpp.

113{
114 return ConstNodeRef(this, doc(i));
115}

Referenced by cdocref().

◆ operator[]() [1/4]

NodeRef c4::yml::Tree::operator[] ( csubstr key)

find a root child (ie child of root) by name, return it as a NodeRef

Note
requires the root to be a map.

Definition at line 86 of file tree.cpp.

87{
88 return rootref()[key];
89}
csubstr const & key(id_type node) const
Definition tree.hpp:458
NodeRef rootref()
Get the root as a NodeRef . Note that a non-const Tree implicitly converts to NodeRef.
Definition tree.cpp:56

◆ operator[]() [2/4]

ConstNodeRef c4::yml::Tree::operator[] ( csubstr key) const

find a root child (ie child of root) by name, return it as a NodeRef

Note
requires the root to be a map.

Definition at line 90 of file tree.cpp.

91{
92 return crootref()[key];
93}
ConstNodeRef crootref() const
Get the root as a ConstNodeRef . Note that Tree implicitly converts to ConstNodeRef.
Definition tree.cpp:65

◆ operator[]() [3/4]

NodeRef c4::yml::Tree::operator[] ( id_type i)

find a root child (ie child of root) by index: return the root node's i-th child as a NodeRef

Note
i is NOT the node id, but the child's position within the parent

Definition at line 95 of file tree.cpp.

96{
97 return rootref()[i];
98}

◆ operator[]() [4/4]

ConstNodeRef c4::yml::Tree::operator[] ( id_type i) const

find a root child (ie child of root) by index: return the root node's i-th child as a NodeRef

Note
i is NOT the node id, but the child's position within the parent

Definition at line 99 of file tree.cpp.

100{
101 return crootref()[i];
102}

◆ type()

NodeType c4::yml::Tree::type ( id_type node) const
inline

Definition at line 456 of file tree.hpp.

456{ return _p(node)->m_type; }
NodeData * _p(id_type node)
An if-less form of get() that demands a valid node index. This function is implementation only; use a...
Definition tree.hpp:384
NodeType m_type
Definition tree.hpp:292

Referenced by change_type(), change_type(), duplicate_children_no_rep(), merge_with(), and set_root_as_stream().

◆ key()

csubstr const & c4::yml::Tree::key ( id_type node) const
inline

◆ key_tag()

csubstr const & c4::yml::Tree::key_tag ( id_type node) const
inline

Definition at line 459 of file tree.hpp.

459{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key_tag(node), this, node); return _p(node)->m_key.tag; }
bool has_key_tag(id_type node) const
Definition tree.hpp:490

◆ key_ref()

csubstr const & c4::yml::Tree::key_ref ( id_type node) const
inline

Definition at line 460 of file tree.hpp.

460{ RYML_ASSERT_VISIT_CB_(m_callbacks, is_key_ref(node), this, node); return _p(node)->m_key.anchor; }
bool is_key_ref(id_type node) const
Definition tree.hpp:495

◆ key_anchor()

csubstr const & c4::yml::Tree::key_anchor ( id_type node) const
inline

Definition at line 461 of file tree.hpp.

461{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key_anchor(node), this, node); return _p(node)->m_key.anchor; }
bool has_key_anchor(id_type node) const
Definition tree.hpp:492

◆ keysc()

NodeScalar const & c4::yml::Tree::keysc ( id_type node) const
inline

Definition at line 462 of file tree.hpp.

462{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node); return _p(node)->m_key; }

◆ val()

csubstr const & c4::yml::Tree::val ( id_type node) const
inline

Definition at line 464 of file tree.hpp.

464{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val(node), this, node); return _p(node)->m_val.scalar; }
bool has_val(id_type node) const
Definition tree.hpp:487
NodeScalar m_val
Definition tree.hpp:295

Referenced by c4::yml::read(), sample_base64(), sample_deserialize_error(), sample_docs(), sample_tree_arena(), save(), save(), set_serialized(), set_serialized(), set_val(), and set_val().

◆ val_tag()

csubstr const & c4::yml::Tree::val_tag ( id_type node) const
inline

Definition at line 465 of file tree.hpp.

465{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val_tag(node), this, node); return _p(node)->m_val.tag; }
bool has_val_tag(id_type node) const
Definition tree.hpp:491

◆ val_ref()

csubstr const & c4::yml::Tree::val_ref ( id_type node) const
inline

Definition at line 466 of file tree.hpp.

466{ RYML_ASSERT_VISIT_CB_(m_callbacks, is_val_ref(node), this, node); return _p(node)->m_val.anchor; }
bool is_val_ref(id_type node) const
Definition tree.hpp:496

◆ val_anchor()

csubstr const & c4::yml::Tree::val_anchor ( id_type node) const
inline

Definition at line 467 of file tree.hpp.

467{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val_anchor(node), this, node); return _p(node)->m_val.anchor; }
bool has_val_anchor(id_type node) const
Definition tree.hpp:493

◆ valsc()

NodeScalar const & c4::yml::Tree::valsc ( id_type node) const
inline

Definition at line 468 of file tree.hpp.

468{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val(node), this, node); return _p(node)->m_val; }

◆ type_has_any()

bool c4::yml::Tree::type_has_any ( id_type node,
type_bits bits ) const
inline

Definition at line 477 of file tree.hpp.

477{ return _p(node)->m_type.has_any(bits); }
bool has_any(type_bits t) const noexcept

◆ type_has_all()

bool c4::yml::Tree::type_has_all ( id_type node,
type_bits bits ) const
inline

Definition at line 478 of file tree.hpp.

478{ return _p(node)->m_type.has_all(bits); }
bool has_all(type_bits t) const noexcept

◆ type_has_none()

bool c4::yml::Tree::type_has_none ( id_type node,
type_bits bits ) const
inline

Definition at line 479 of file tree.hpp.

479{ return _p(node)->m_type.has_none(bits); }
bool has_none(type_bits t) const noexcept

◆ is_stream()

bool c4::yml::Tree::is_stream ( id_type node) const
inline

Definition at line 481 of file tree.hpp.

481{ return _p(node)->m_type.is_stream(); }
bool is_stream() const noexcept

Referenced by doc(), sample_docs(), and set_doc().

◆ is_doc()

bool c4::yml::Tree::is_doc ( id_type node) const
inline

Definition at line 482 of file tree.hpp.

482{ return _p(node)->m_type.is_doc(); }
bool is_doc() const noexcept

Referenced by sample_docs().

◆ is_container()

bool c4::yml::Tree::is_container ( id_type node) const
inline

Definition at line 483 of file tree.hpp.

483{ return _p(node)->m_type.is_container(); }
bool is_container() const noexcept

Referenced by deserialize_child(), deserialize_child(), deserialize_child(), insert_child(), set_container_style(), and set_val_tag().

◆ is_map()

bool c4::yml::Tree::is_map ( id_type node) const
inline

Definition at line 484 of file tree.hpp.

484{ return _p(node)->m_type.is_map(); }
bool is_map() const noexcept

Referenced by parent_is_map(), c4::yml::read(), read(), read(), c4::yml::EventHandlerTree::reset(), sample_docs(), and sample_quick_overview().

◆ is_seq()

bool c4::yml::Tree::is_seq ( id_type node) const
inline

Definition at line 485 of file tree.hpp.

485{ return _p(node)->m_type.is_seq(); }
bool is_seq() const noexcept

Referenced by parent_is_seq(), c4::yml::read(), c4::yml::read(), read(), sample_docs(), and sample_quick_overview().

◆ has_key()

bool c4::yml::Tree::has_key ( id_type node) const
inline

◆ has_val()

bool c4::yml::Tree::has_val ( id_type node) const
inline

Definition at line 487 of file tree.hpp.

487{ return _p(node)->m_type.has_val(); }
bool has_val() const noexcept

Referenced by set_val_style(), set_val_tag(), val(), val_is_null(), val_style(), and valsc().

◆ is_val()

bool c4::yml::Tree::is_val ( id_type node) const
inline

Definition at line 488 of file tree.hpp.

488{ return _p(node)->m_type.is_val(); }
bool is_val() const noexcept

◆ is_keyval()

bool c4::yml::Tree::is_keyval ( id_type node) const
inline

Definition at line 489 of file tree.hpp.

489{ return _p(node)->m_type.is_keyval(); }
bool is_keyval() const noexcept

◆ has_key_tag()

bool c4::yml::Tree::has_key_tag ( id_type node) const
inline

Definition at line 490 of file tree.hpp.

490{ return _p(node)->m_type.has_key_tag(); }
bool has_key_tag() const noexcept

Referenced by key_tag().

◆ has_val_tag()

bool c4::yml::Tree::has_val_tag ( id_type node) const
inline

Definition at line 491 of file tree.hpp.

491{ return _p(node)->m_type.has_val_tag(); }
bool has_val_tag() const noexcept

Referenced by val_tag().

◆ has_key_anchor()

bool c4::yml::Tree::has_key_anchor ( id_type node) const
inline

Definition at line 492 of file tree.hpp.

492{ return _p(node)->m_type.has_key_anchor(); }
bool has_key_anchor() const noexcept

Referenced by key_anchor(), and set_key_ref().

◆ has_val_anchor()

bool c4::yml::Tree::has_val_anchor ( id_type node) const
inline

Definition at line 493 of file tree.hpp.

493{ return _p(node)->m_type.has_val_anchor(); }
bool has_val_anchor() const noexcept

Referenced by set_val_ref(), and val_anchor().

◆ has_anchor() [1/2]

bool c4::yml::Tree::has_anchor ( id_type node) const
inline

Definition at line 494 of file tree.hpp.

494{ return _p(node)->m_type.has_anchor(); }
bool has_anchor() const noexcept

◆ is_key_ref()

bool c4::yml::Tree::is_key_ref ( id_type node) const
inline

Definition at line 495 of file tree.hpp.

495{ return _p(node)->m_type.is_key_ref(); }
bool is_key_ref() const noexcept

Referenced by key_ref(), and set_key_anchor().

◆ is_val_ref()

bool c4::yml::Tree::is_val_ref ( id_type node) const
inline

Definition at line 496 of file tree.hpp.

496{ return _p(node)->m_type.is_val_ref(); }
bool is_val_ref() const noexcept

Referenced by set_val_anchor(), and val_ref().

◆ is_ref()

bool c4::yml::Tree::is_ref ( id_type node) const
inline

Definition at line 497 of file tree.hpp.

497{ return _p(node)->m_type.is_ref(); }
bool is_ref() const noexcept

◆ parent_is_seq()

bool c4::yml::Tree::parent_is_seq ( id_type node) const
inline

Definition at line 499 of file tree.hpp.

499{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_parent(node), this, node); return is_seq(_p(node)->m_parent); }
bool is_seq(id_type node) const
Definition tree.hpp:485
bool has_parent(id_type node) const
Definition tree.hpp:535

◆ parent_is_map()

bool c4::yml::Tree::parent_is_map ( id_type node) const
inline

Definition at line 500 of file tree.hpp.

500{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_parent(node), this, node); return is_map(_p(node)->m_parent); }
bool is_map(id_type node) const
Definition tree.hpp:484

◆ has_anchor() [2/2]

bool c4::yml::Tree::has_anchor ( id_type node,
csubstr a ) const
inline

true when the node has an anchor named a

Definition at line 503 of file tree.hpp.

503{ return _p(node)->m_key.anchor == a || _p(node)->m_val.anchor == a; }

◆ key_is_null()

bool c4::yml::Tree::key_is_null ( id_type node) const
inline

true if the node key is empty, or its scalar verifies scalar_is_null().

Warning
the node must verify Tree::has_key() (asserted) (ie must be a member of a map)
See also
https://github.com/biojppm/rapidyaml/issues/413

Definition at line 508 of file tree.hpp.

508{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node); NodeData const* C4_RESTRICT n = _p(node); return !n->m_type.is_key_quoted() && (n->m_type.key_is_null() || scalar_is_null(n->m_key.scalar)); }
bool scalar_is_null(csubstr s) noexcept
YAML-sense query of nullity.

◆ val_is_null()

bool c4::yml::Tree::val_is_null ( id_type node) const
inline

true if the node val is empty, or its scalar verifies scalar_is_null().

Warning
the node must verify Tree::has_val() (asserted) (ie must be a scalar / must not be a container)
See also
https://github.com/biojppm/rapidyaml/issues/413

Definition at line 512 of file tree.hpp.

512{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val(node), this, node); NodeData const* C4_RESTRICT n = _p(node); return !n->m_type.is_val_quoted() && (n->m_type.val_is_null() || scalar_is_null(n->m_val.scalar)); }

◆ is_key_unfiltered()

bool c4::yml::Tree::is_key_unfiltered ( id_type node) const
inline

true if the key was a scalar requiring filtering and was left unfiltered during the parsing (see ParserOptions)

Definition at line 516 of file tree.hpp.

516{ return _p(node)->m_type.is_key_unfiltered(); }
bool is_key_unfiltered() const noexcept

◆ is_val_unfiltered()

bool c4::yml::Tree::is_val_unfiltered ( id_type node) const
inline

true if the val was a scalar requiring filtering and was left unfiltered during the parsing (see ParserOptions)

Definition at line 519 of file tree.hpp.

519{ return _p(node)->m_type.is_val_unfiltered(); }
bool is_val_unfiltered() const noexcept

◆ is_key_anchor()

bool c4::yml::Tree::is_key_anchor ( id_type node) const
inline

Definition at line 521 of file tree.hpp.

521{ return _p(node)->m_type.has_key_anchor(); }

Referenced by is_key_anchor().

◆ is_val_anchor()

bool c4::yml::Tree::is_val_anchor ( id_type node) const
inline

Definition at line 522 of file tree.hpp.

522{ return _p(node)->m_type.has_val_anchor(); }

Referenced by is_val_anchor().

◆ is_anchor()

bool c4::yml::Tree::is_anchor ( id_type node) const
inline

Definition at line 523 of file tree.hpp.

523{ return _p(node)->m_type.has_anchor(); }

Referenced by is_anchor().

◆ is_anchor_or_ref()

bool c4::yml::Tree::is_anchor_or_ref ( id_type node) const
inline

Definition at line 524 of file tree.hpp.

524{ return _p(node)->m_type.has_anchor() || _p(node)->m_type.is_ref(); }

Referenced by is_anchor_or_ref().

◆ is_root()

bool c4::yml::Tree::is_root ( id_type node) const
inline

Definition at line 533 of file tree.hpp.

533{ RYML_ASSERT_VISIT_CB_(m_callbacks, _p(node)->m_parent != NONE || node == 0, this, node); return _p(node)->m_parent == NONE; }
id_type m_parent
Definition tree.hpp:297

Referenced by depth_asc(), duplicate(), first_sibling(), insert_child(), last_sibling(), move(), move(), num_siblings(), c4::yml::EventHandlerTree::reset(), sample_docs(), set_doc(), set_stream(), sibling_pos(), and val_style().

◆ has_parent()

bool c4::yml::Tree::has_parent ( id_type node) const
inline

Definition at line 535 of file tree.hpp.

535{ return _p(node)->m_parent != NONE; }

Referenced by parent_is_map(), and parent_is_seq().

◆ is_ancestor()

bool c4::yml::Tree::is_ancestor ( id_type node,
id_type ancestor ) const

true when ancestor is parent or parent of a parent of node

Definition at line 1273 of file tree.cpp.

1274{
1275 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
1276 id_type p = parent(node);
1277 while(p != NONE)
1278 {
1279 if(p == ancestor)
1280 return true;
1281 p = parent(p);
1282 }
1283 return false;
1284}
id_type parent(id_type node) const
Definition tree.hpp:573

Referenced by duplicate_children_no_rep().

◆ empty() [2/2]

bool c4::yml::Tree::empty ( id_type node) const
inline

true when key and val are empty, and has no children

Definition at line 541 of file tree.hpp.

541{ return ! has_children(node) && _p(node)->m_key.empty() && (( ! (_p(node)->m_type & VAL)) || _p(node)->m_val.empty()); }
bool has_children(id_type node) const
true if node has any children
Definition tree.hpp:548
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition node_type.hpp:34
bool empty() const noexcept
Definition tree.hpp:203

◆ has_child() [1/2]

bool c4::yml::Tree::has_child ( id_type node,
id_type ch ) const
inline

true if node has a child with id ch

Definition at line 544 of file tree.hpp.

544{ return _p(ch)->m_parent == node; }

Referenced by duplicate_children(), and duplicate_children_no_rep().

◆ has_child() [2/2]

bool c4::yml::Tree::has_child ( id_type node,
csubstr key ) const
inline

true if node has a child with key key

Definition at line 546 of file tree.hpp.

546{ return find_child(node, key) != NONE; }
id_type find_child(id_type node, csubstr const &key) const
find child by name, or NONE if no child is found with this key like Tree::child(),...
Definition tree.cpp:1218

◆ has_children()

bool c4::yml::Tree::has_children ( id_type node) const
inline

true if node has any children

Definition at line 548 of file tree.hpp.

548{ return _p(node)->m_first_child != NONE; }
id_type m_first_child
Definition tree.hpp:298

Referenced by empty(), merge_with(), and set_root_as_stream().

◆ has_sibling() [1/2]

bool c4::yml::Tree::has_sibling ( id_type node,
id_type sib ) const
inline

true if node has a sibling with id sib

Definition at line 551 of file tree.hpp.

551{ return _p(node)->m_parent == _p(sib)->m_parent; }

Referenced by move().

◆ has_sibling() [2/2]

bool c4::yml::Tree::has_sibling ( id_type node,
csubstr key ) const
inline

true if one of the node's siblings has the given key

Definition at line 553 of file tree.hpp.

553{ return find_sibling(node, key) != NONE; }
id_type find_sibling(id_type node, csubstr const &key) const
Definition tree.hpp:599

◆ has_other_siblings()

bool c4::yml::Tree::has_other_siblings ( id_type node) const
inline

true if node is not a single child

Definition at line 555 of file tree.hpp.

556 {
557 NodeData const *n = _p(node);
558 if C4_LIKELY(n->m_parent != NONE)
559 {
560 n = _p(n->m_parent);
561 return n->m_first_child != n->m_last_child;
562 }
563 return false;
564 }

◆ parent()

◆ prev_sibling()

id_type c4::yml::Tree::prev_sibling ( id_type node) const
inline

Definition at line 575 of file tree.hpp.

575{ return _p(node)->m_prev_sibling; }
id_type m_prev_sibling
Definition tree.hpp:301

Referenced by duplicate_children_no_rep().

◆ next_sibling()

◆ num_children()

id_type c4::yml::Tree::num_children ( id_type node) const

O(num_children).

Definition at line 1185 of file tree.cpp.

1186{
1187 id_type count = 0;
1188 for(id_type i = first_child(node); i != NONE; i = next_sibling(i))
1189 ++count;
1190 return count;
1191}
id_type first_child(id_type node) const
Definition tree.hpp:581
id_type next_sibling(id_type node) const
Definition tree.hpp:576

Referenced by num_siblings(), sample_docs(), and sample_user_container_types().

◆ child_pos()

id_type c4::yml::Tree::child_pos ( id_type node,
id_type ch ) const

Definition at line 1193 of file tree.cpp.

1194{
1195 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
1196 id_type count = 0;
1197 for(id_type i = first_child(node); i != NONE; i = next_sibling(i))
1198 {
1199 if(i == ch)
1200 return count;
1201 ++count;
1202 }
1203 return NONE;
1204}

Referenced by deserialize_child(), deserialize_child(), deserialize_child(), and sibling_pos().

◆ first_child()

◆ last_child()

id_type c4::yml::Tree::last_child ( id_type node) const
inline

Definition at line 582 of file tree.hpp.

582{ return _p(node)->m_last_child; }
id_type m_last_child
Definition tree.hpp:299

Referenced by duplicate_contents().

◆ child()

id_type c4::yml::Tree::child ( id_type node,
id_type pos ) const

find child by position, or NONE if there are less than pos children posi

Definition at line 1206 of file tree.cpp.

1207{
1208 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
1209 id_type count = 0;
1210 for(id_type i = first_child(node); i != NONE; i = next_sibling(i))
1211 {
1212 if(count++ == pos)
1213 return i;
1214 }
1215 return NONE;
1216}

Referenced by _append_child__unprotected(), child_r(), clear_style(), doc(), insert_child(), sample_docs(), set_style_conditionally(), and sibling().

◆ find_child()

id_type c4::yml::Tree::find_child ( id_type node,
csubstr const & key ) const

find child by name, or NONE if no child is found with this key like Tree::child(), but return a ReadResult with the status

Definition at line 1218 of file tree.cpp.

1219{
1220 C4_SUPPRESS_WARNING_PUSH
1221 #if defined(__clang__)
1222 #elif defined(__GNUC__)
1223 # if __GNUC__ >= 6
1224 C4_SUPPRESS_WARNING_GCC("-Wnull-dereference")
1225 # endif
1226 # if __GNUC__ > 9
1227 C4_SUPPRESS_WARNING_GCC("-Wanalyzer-null-dereference")
1228 # endif
1229 #endif
1230 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
1231 RYML_ASSERT_VISIT_CB_(m_callbacks, _p(node)->m_type.m_bits & MAP, this, node);
1232 for(id_type i = first_child(node); i != NONE; i = next_sibling(i))
1233 {
1234 if(_p(i)->m_key.scalar == name)
1235 return i;
1236 }
1237 return NONE;
1238 C4_SUPPRESS_WARNING_POP
1239}
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition node_type.hpp:35

Referenced by find_child_r(), find_sibling(), has_child(), merge_with(), sample_docs(), and sample_quick_overview().

◆ child_r()

ReadResult c4::yml::Tree::child_r ( id_type node,
id_type pos,
id_type * child_id ) const
inline

Definition at line 586 of file tree.hpp.

586{ return ReadResult(node, *child_id = child(node, pos)); }
id_type child(id_type node, id_type pos) const
find child by position, or NONE if there are less than pos children posi
Definition tree.cpp:1206

Referenced by deserialize_child(), deserialize_child(), deserialize_child(), and sibling_r().

◆ find_child_r()

ReadResult c4::yml::Tree::find_child_r ( id_type node,
csubstr const & key,
id_type * child_id ) const
inline

like Tree::find_child(), but return a ReadResult with the status

Definition at line 588 of file tree.hpp.

588{ return ReadResult(node, *child_id = find_child(node, key)); }

Referenced by deserialize_child(), deserialize_child(), deserialize_child(), and find_sibling_r().

◆ num_siblings()

id_type c4::yml::Tree::num_siblings ( id_type node) const
inline

O(num_siblings).

counts with this

Definition at line 592 of file tree.hpp.

592{ return is_root(node) ? 1 : num_children(_p(node)->m_parent); }
bool is_root(id_type node) const
Definition tree.hpp:533
id_type num_children(id_type node) const
O(num_children).
Definition tree.cpp:1185

Referenced by num_other_siblings().

◆ num_other_siblings()

id_type c4::yml::Tree::num_other_siblings ( id_type node) const
inline

does not count with this

Definition at line 594 of file tree.hpp.

594{ id_type ns = num_siblings(node); RYML_ASSERT_VISIT_CB_(m_callbacks, ns > 0, this, node); return ns-1; }
id_type num_siblings(id_type node) const
O(num_siblings).
Definition tree.hpp:592

◆ sibling_pos()

id_type c4::yml::Tree::sibling_pos ( id_type node,
id_type sib ) const
inline

Definition at line 595 of file tree.hpp.

595{ RYML_ASSERT_VISIT_CB_(m_callbacks, ! is_root(node) || node == root_id(), this, node); return child_pos(_p(node)->m_parent, sib); }
id_type child_pos(id_type node, id_type ch) const
Definition tree.cpp:1193

◆ first_sibling()

id_type c4::yml::Tree::first_sibling ( id_type node) const
inline

Definition at line 596 of file tree.hpp.

596{ return is_root(node) ? node : _p(_p(node)->m_parent)->m_first_child; }

Referenced by sample_quick_overview().

◆ last_sibling()

id_type c4::yml::Tree::last_sibling ( id_type node) const
inline

Definition at line 597 of file tree.hpp.

597{ return is_root(node) ? node : _p(_p(node)->m_parent)->m_last_child; }

◆ sibling()

id_type c4::yml::Tree::sibling ( id_type node,
id_type pos ) const
inline

Definition at line 598 of file tree.hpp.

598{ return child(_p(node)->m_parent, pos); }

◆ find_sibling()

id_type c4::yml::Tree::find_sibling ( id_type node,
csubstr const & key ) const
inline

Definition at line 599 of file tree.hpp.

599{ return find_child(_p(node)->m_parent, key); }

Referenced by has_sibling().

◆ sibling_r()

ReadResult c4::yml::Tree::sibling_r ( id_type node,
id_type pos,
id_type * sibling_id ) const
inline

like Tree::sibling(), but return a ReadResult with the status

Definition at line 601 of file tree.hpp.

601{ return child_r(_p(node)->m_parent, pos, sibling_id); }
ReadResult child_r(id_type node, id_type pos, id_type *child_id) const
Definition tree.hpp:586

◆ find_sibling_r()

ReadResult c4::yml::Tree::find_sibling_r ( id_type node,
csubstr const & key,
id_type * sibling_id ) const
inline

like Tree::find_sibling(), but return a ReadResult if with the status

Definition at line 603 of file tree.hpp.

603{ return find_child_r(_p(node)->m_parent, key, sibling_id); }
ReadResult find_child_r(id_type node, csubstr const &key, id_type *child_id) const
like Tree::find_child(), but return a ReadResult with the status
Definition tree.hpp:588

◆ depth_asc()

id_type c4::yml::Tree::depth_asc ( id_type node) const

O(log(num_tree_nodes)) get the ascending depth of the node: number of levels between root and node.

Definition at line 1261 of file tree.cpp.

1262{
1263 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
1264 id_type depth = 0;
1265 while(!is_root(node))
1266 {
1267 ++depth;
1268 node = parent(node);
1269 }
1270 return depth;
1271}

◆ depth_desc()

id_type c4::yml::Tree::depth_desc ( id_type node) const

O(num_tree_nodes) get the descending depth of the node: number of levels between node and deepest child.

Definition at line 1255 of file tree.cpp.

1256{
1257 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
1258 return depth_desc_(*this, node);
1259}

◆ doc()

id_type c4::yml::Tree::doc ( id_type i) const
inline

gets the i document node index.

requires that the root node is a stream.

Definition at line 609 of file tree.hpp.

609{ id_type rid = root_id(); RYML_ASSERT_VISIT_CB_(m_callbacks, is_stream(rid), this, rid); return child(rid, i); }
bool is_stream(id_type node) const
Definition tree.hpp:481

Referenced by cdocref(), docref(), docref(), and sample_docs().

◆ ancestor_doc()

id_type c4::yml::Tree::ancestor_doc ( id_type node) const
inline

get the document which is a parent document of node i, or the root if the tree is not a stream

Definition at line 612 of file tree.hpp.

613 {
614 NodeData const *nd;
615 do
616 {
617 nd = _p(node);
618 if(nd->m_type.is_doc() || nd->m_parent == NONE)
619 break;
620 node = nd->m_parent;
621 } while(nd->m_parent != NONE);
622 return node;
623 }

Referenced by c4::yml::EventHandlerTree::reset().

◆ is_container_styled()

bool c4::yml::Tree::is_container_styled ( id_type node) const
inline

Definition at line 632 of file tree.hpp.

632{ return _p(node)->m_type.is_container_styled(); }
bool is_container_styled() const noexcept

◆ is_block()

bool c4::yml::Tree::is_block ( id_type node) const
inline

Definition at line 633 of file tree.hpp.

633{ return _p(node)->m_type.is_block(); }
bool is_block() const noexcept

◆ is_flow_sl()

bool c4::yml::Tree::is_flow_sl ( id_type node) const
inline

Definition at line 634 of file tree.hpp.

634{ return _p(node)->m_type.is_flow_sl(); }
bool is_flow_sl() const noexcept

◆ is_flow_ml()

bool c4::yml::Tree::is_flow_ml ( id_type node) const
inline

Definition at line 636 of file tree.hpp.

636{ return _p(node)->m_type.is_flow_ml1(); }
bool is_flow_ml1() const noexcept

Referenced by is_flow_ml().

◆ is_flow_ml1()

bool c4::yml::Tree::is_flow_ml1 ( id_type node) const
inline

Definition at line 637 of file tree.hpp.

637{ return _p(node)->m_type.is_flow_ml1(); }

◆ is_flow_mln()

bool c4::yml::Tree::is_flow_mln ( id_type node) const
inline

Definition at line 638 of file tree.hpp.

638{ return _p(node)->m_type.is_flow_mln(); }
bool is_flow_mln() const noexcept

◆ is_flow_mlx()

bool c4::yml::Tree::is_flow_mlx ( id_type node) const
inline

Definition at line 639 of file tree.hpp.

639{ return _p(node)->m_type.is_flow_mlx(); }
bool is_flow_mlx() const noexcept

◆ is_flow()

bool c4::yml::Tree::is_flow ( id_type node) const
inline

Definition at line 640 of file tree.hpp.

640{ return _p(node)->m_type.is_flow(); }
bool is_flow() const noexcept

◆ has_flow_space()

bool c4::yml::Tree::has_flow_space ( id_type node) const
inline

Definition at line 641 of file tree.hpp.

641{ return _p(node)->m_type.has_flow_space(); }
bool has_flow_space() const noexcept

◆ is_key_styled()

bool c4::yml::Tree::is_key_styled ( id_type node) const
inline

Definition at line 643 of file tree.hpp.

643{ return _p(node)->m_type.is_key_styled(); }
bool is_key_styled() const noexcept

◆ is_val_styled()

bool c4::yml::Tree::is_val_styled ( id_type node) const
inline

Definition at line 644 of file tree.hpp.

644{ return _p(node)->m_type.is_val_styled(); }
bool is_val_styled() const noexcept

◆ is_key_literal()

bool c4::yml::Tree::is_key_literal ( id_type node) const
inline

Definition at line 645 of file tree.hpp.

645{ return _p(node)->m_type.is_key_literal(); }
bool is_key_literal() const noexcept

◆ is_val_literal()

bool c4::yml::Tree::is_val_literal ( id_type node) const
inline

Definition at line 646 of file tree.hpp.

646{ return _p(node)->m_type.is_val_literal(); }
bool is_val_literal() const noexcept

◆ is_key_folded()

bool c4::yml::Tree::is_key_folded ( id_type node) const
inline

Definition at line 647 of file tree.hpp.

647{ return _p(node)->m_type.is_key_folded(); }
bool is_key_folded() const noexcept

◆ is_val_folded()

bool c4::yml::Tree::is_val_folded ( id_type node) const
inline

Definition at line 648 of file tree.hpp.

648{ return _p(node)->m_type.is_val_folded(); }
bool is_val_folded() const noexcept

◆ is_key_squo()

bool c4::yml::Tree::is_key_squo ( id_type node) const
inline

Definition at line 649 of file tree.hpp.

649{ return _p(node)->m_type.is_key_squo(); }
bool is_key_squo() const noexcept

◆ is_val_squo()

bool c4::yml::Tree::is_val_squo ( id_type node) const
inline

Definition at line 650 of file tree.hpp.

650{ return _p(node)->m_type.is_val_squo(); }
bool is_val_squo() const noexcept

◆ is_key_dquo()

bool c4::yml::Tree::is_key_dquo ( id_type node) const
inline

Definition at line 651 of file tree.hpp.

651{ return _p(node)->m_type.is_key_dquo(); }
bool is_key_dquo() const noexcept

◆ is_val_dquo()

bool c4::yml::Tree::is_val_dquo ( id_type node) const
inline

Definition at line 652 of file tree.hpp.

652{ return _p(node)->m_type.is_val_dquo(); }
bool is_val_dquo() const noexcept

◆ is_key_plain()

bool c4::yml::Tree::is_key_plain ( id_type node) const
inline

Definition at line 653 of file tree.hpp.

653{ return _p(node)->m_type.is_key_plain(); }
bool is_key_plain() const noexcept

◆ is_val_plain()

bool c4::yml::Tree::is_val_plain ( id_type node) const
inline

Definition at line 654 of file tree.hpp.

654{ return _p(node)->m_type.is_val_plain(); }
bool is_val_plain() const noexcept

◆ is_key_quoted()

bool c4::yml::Tree::is_key_quoted ( id_type node) const
inline

Definition at line 655 of file tree.hpp.

655{ return _p(node)->m_type.is_key_quoted(); }
bool is_key_quoted() const noexcept

◆ is_val_quoted()

bool c4::yml::Tree::is_val_quoted ( id_type node) const
inline

Definition at line 656 of file tree.hpp.

656{ return _p(node)->m_type.is_val_quoted(); }
bool is_val_quoted() const noexcept

◆ is_quoted()

bool c4::yml::Tree::is_quoted ( id_type node) const
inline

Definition at line 657 of file tree.hpp.

657{ return _p(node)->m_type.is_quoted(); }
bool is_quoted() const noexcept

◆ key_style()

NodeType c4::yml::Tree::key_style ( id_type node) const
inline

Definition at line 659 of file tree.hpp.

659{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node); return _p(node)->m_type.key_style(); }
NodeType key_style() const noexcept

◆ val_style()

NodeType c4::yml::Tree::val_style ( id_type node) const
inline

Definition at line 660 of file tree.hpp.

660{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val(node) || is_root(node), this, node); return _p(node)->m_type.val_style(); }
NodeType val_style() const noexcept

◆ set_container_style()

void c4::yml::Tree::set_container_style ( id_type node,
type_bits style )
inline

Definition at line 662 of file tree.hpp.

662{ RYML_ASSERT_VISIT_CB_(m_callbacks, is_container(node), this, node); _p(node)->m_type.set_container_style(style); }
bool is_container(id_type node) const
Definition tree.hpp:483
void set_container_style(type_bits style) noexcept

Referenced by sample_style_flow_ml_indent().

◆ set_key_style()

void c4::yml::Tree::set_key_style ( id_type node,
type_bits style )
inline

Definition at line 663 of file tree.hpp.

663{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node); _p(node)->m_type.set_key_style(style); }
void set_key_style(type_bits style) noexcept

◆ set_val_style()

void c4::yml::Tree::set_val_style ( id_type node,
type_bits style )
inline

Definition at line 664 of file tree.hpp.

664{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val(node), this, node); _p(node)->m_type.set_val_style(style); }
void set_val_style(type_bits style) noexcept

◆ clear_style()

void c4::yml::Tree::clear_style ( id_type node,
bool recurse = false )

Definition at line 1373 of file tree.cpp.

1374{
1375 NodeData *C4_RESTRICT d = _p(node);
1376 d->m_type.clear_style();
1377 if(!recurse)
1378 return;
1379 for(id_type child = d->m_first_child; child != NONE; child = next_sibling(child))
1380 clear_style(child, recurse);
1381}
void clear_style(id_type node, bool recurse=false)
Definition tree.cpp:1373

Referenced by clear_style(), and sample_style().

◆ set_style_conditionally()

void c4::yml::Tree::set_style_conditionally ( id_type node,
NodeType type_mask,
NodeType rem_style_flags,
NodeType add_style_flags,
bool recurse = false )

Definition at line 1383 of file tree.cpp.

1388{
1389 NodeData *C4_RESTRICT d = _p(node);
1390 if((d->m_type & type_mask) == type_mask)
1391 {
1392 d->m_type &= ~(NodeType)rem_style_flags;
1393 d->m_type |= (NodeType)add_style_flags;
1394 }
1395 if(!recurse)
1396 return;
1397 for(id_type child = d->m_first_child; child != NONE; child = next_sibling(child))
1398 set_style_conditionally(child, type_mask, rem_style_flags, add_style_flags, recurse);
1399}
void set_style_conditionally(id_type node, NodeType type_mask, NodeType rem_style_flags, NodeType add_style_flags, bool recurse=false)
Definition tree.cpp:1383

Referenced by sample_style(), and set_style_conditionally().

◆ set_stream()

void c4::yml::Tree::set_stream ( id_type node)
inline

Definition at line 679 of file tree.hpp.

680 {
681 RYML_ASSERT_VISIT_CB_(m_callbacks, is_root(node), this, node);
682 RYML_ASSERT_VISIT_CB_(m_callbacks, (_p(node)->m_type & (DOC|MAP|VAL)) == 0, this, node);
683 _p(node)->m_type |= STREAM;
684 }
@ STREAM
a stream: a seq of docs
Definition node_type.hpp:38
@ DOC
a document
Definition node_type.hpp:37

◆ set_doc()

void c4::yml::Tree::set_doc ( id_type node)
inline

Definition at line 686 of file tree.hpp.

687 {
688 RYML_ASSERT_VISIT_CB_(m_callbacks, is_root(node) || (is_root(parent(node)) && is_stream(parent(node))), this, node);
689 _p(node)->m_type |= DOC;
690 }

◆ set_val() [1/2]

void c4::yml::Tree::set_val ( id_type node,
csubstr val )
inline

Definition at line 692 of file tree.hpp.

693 {
694 RYML_ASSERT_VISIT_CB_(m_callbacks, (_p(node)->m_type & (SEQ|MAP)) == 0, this, node);
695 RYML_ASSERT_VISIT_CB_(m_callbacks, (parent(node) == NONE || (_p(parent(node))->m_type & (SEQ|MAP))), this, node);
696 NodeData *C4_RESTRICT nd = _p(node);
697 nd->m_type |= VAL;
698 nd->m_val.scalar = val;
699 }
csubstr const & val(id_type node) const
Definition tree.hpp:464
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition node_type.hpp:36

Referenced by lookup_path_or_modify(), sample_anchors_and_aliases_create(), sample_lightning_overview(), sample_tree_arena(), c4::yml::write(), and write().

◆ set_val() [2/2]

void c4::yml::Tree::set_val ( id_type node,
csubstr val,
NodeType more_flags )
inline

Definition at line 700 of file tree.hpp.

701 {
702 RYML_ASSERT_VISIT_CB_(m_callbacks, (_p(node)->m_type & (SEQ|MAP)) == 0, this, node);
703 RYML_ASSERT_VISIT_CB_(m_callbacks, (parent(node) == NONE || (_p(parent(node))->m_type & (SEQ|MAP))), this, node);
704 NodeData *C4_RESTRICT nd = _p(node);
705 nd->m_type |= VAL|more_flags;
706 nd->m_val.scalar = val;
707 }

◆ set_key() [1/2]

void c4::yml::Tree::set_key ( id_type node,
csubstr key )
inline

Definition at line 709 of file tree.hpp.

710 {
711 RYML_ASSERT_VISIT_CB_(m_callbacks, (parent(node) != NONE && (_p(parent(node))->m_type & MAP)), this, node);
712 NodeData *C4_RESTRICT nd = _p(node);
713 nd->m_type |= KEY;
714 nd->m_key.scalar = key;
715 }
@ KEY
the scalar to the left of : in a map's member
Definition node_type.hpp:33

Referenced by merge_with(), write(), and c4::yml::write_key().

◆ set_key() [2/2]

void c4::yml::Tree::set_key ( id_type node,
csubstr key,
NodeType more_flags )
inline

Definition at line 716 of file tree.hpp.

717 {
718 RYML_ASSERT_VISIT_CB_(m_callbacks, (parent(node) != NONE && (_p(parent(node))->m_type & MAP)), this, node);
719 NodeData *C4_RESTRICT nd = _p(node);
720 nd->m_type |= KEY|more_flags;
721 nd->m_key.scalar = key;
722 }

◆ set_seq() [1/2]

void c4::yml::Tree::set_seq ( id_type node)
inline

Definition at line 724 of file tree.hpp.

725 {
726 RYML_ASSERT_VISIT_CB_(m_callbacks, (_p(node)->m_type & (VAL|MAP)) == 0, this, node);
727 _p(node)->m_type |= SEQ;
728 }

Referenced by merge_with(), write(), and write().

◆ set_seq() [2/2]

void c4::yml::Tree::set_seq ( id_type node,
NodeType more_flags )
inline

Definition at line 729 of file tree.hpp.

730 {
731 RYML_ASSERT_VISIT_CB_(m_callbacks, ((_p(node)->m_type|more_flags) & (VAL|MAP)) == 0, this, node);
732 _p(node)->m_type |= SEQ|more_flags;
733 }

◆ set_map() [1/2]

void c4::yml::Tree::set_map ( id_type node)
inline

Definition at line 735 of file tree.hpp.

736 {
737 RYML_ASSERT_VISIT_CB_(m_callbacks, (_p(node)->m_type & (VAL|SEQ)) == 0, this, node);
738 _p(node)->m_type |= MAP;
739 }

Referenced by merge_with(), c4::yml::write(), write(), and write().

◆ set_map() [2/2]

void c4::yml::Tree::set_map ( id_type node,
NodeType more_flags )
inline

Definition at line 740 of file tree.hpp.

741 {
742 RYML_ASSERT_VISIT_CB_(m_callbacks, ((_p(node)->m_type|more_flags) & (VAL|SEQ)) == 0, this, node);
743 _p(node)->m_type |= MAP|more_flags;
744 }

◆ set_key_tag()

void c4::yml::Tree::set_key_tag ( id_type node,
csubstr tag )
inline

Definition at line 746 of file tree.hpp.

746{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node); _p(node)->m_key.tag = tag; _add_flags(node, KEYTAG); }
@ KEYTAG
the key has a tag
Definition node_type.hpp:43

Referenced by sample_serialize_basic().

◆ set_val_tag()

void c4::yml::Tree::set_val_tag ( id_type node,
csubstr tag )
inline

Definition at line 747 of file tree.hpp.

747{ RYML_ASSERT_VISIT_CB_(m_callbacks, has_val(node) || is_container(node), this, node); _p(node)->m_val.tag = tag; _add_flags(node, VALTAG); }
@ VALTAG
the val has a tag
Definition node_type.hpp:44

Referenced by sample_serialize_basic().

◆ set_key_anchor()

void c4::yml::Tree::set_key_anchor ( id_type node,
csubstr anchor )
inline

Definition at line 749 of file tree.hpp.

749{ RYML_ASSERT_VISIT_CB_(m_callbacks, ! is_key_ref(node), this, node); _p(node)->m_key.anchor = anchor.triml('&'); _add_flags(node, KEYANCH); }
@ KEYANCH
the key has an &anchor
Definition node_type.hpp:41
basic_substring triml(const C c) const
trim left
Definition substr.hpp:629

Referenced by sample_anchors_and_aliases_create(), and sample_serialize_basic().

◆ set_val_anchor()

void c4::yml::Tree::set_val_anchor ( id_type node,
csubstr anchor )
inline

Definition at line 750 of file tree.hpp.

750{ RYML_ASSERT_VISIT_CB_(m_callbacks, ! is_val_ref(node), this, node); _p(node)->m_val.anchor = anchor.triml('&'); _add_flags(node, VALANCH); }
@ VALANCH
the val has an &anchor
Definition node_type.hpp:42

Referenced by sample_anchors_and_aliases_create(), and sample_serialize_basic().

◆ set_key_ref()

void c4::yml::Tree::set_key_ref ( id_type node,
csubstr ref )
inline

Definition at line 751 of file tree.hpp.

751{ RYML_ASSERT_VISIT_CB_(m_callbacks, ! has_key_anchor(node), this, node); NodeData* C4_RESTRICT n = _p(node); n->m_key.set_ref_maybe_replacing_scalar(ref, n->m_type.has_key()); _add_flags(node, KEY|KEYREF); }
@ KEYREF
a *reference: the key references an &anchor
Definition node_type.hpp:39

◆ set_val_ref()

void c4::yml::Tree::set_val_ref ( id_type node,
csubstr ref )
inline

Definition at line 752 of file tree.hpp.

752{ RYML_ASSERT_VISIT_CB_(m_callbacks, ! has_val_anchor(node), this, node); NodeData* C4_RESTRICT n = _p(node); n->m_val.set_ref_maybe_replacing_scalar(ref, n->m_type.has_val()); _add_flags(node, VAL|VALREF); }
@ VALREF
a *reference: the val references an &anchor
Definition node_type.hpp:40

Referenced by sample_anchors_and_aliases_create().

◆ rem_key_anchor()

void c4::yml::Tree::rem_key_anchor ( id_type node)
inline

Definition at line 754 of file tree.hpp.

754{ _p(node)->m_key.anchor.clear(); _rem_flags(node, KEYANCH); }
void clear() noexcept
Definition substr.hpp:265

◆ rem_val_anchor()

void c4::yml::Tree::rem_val_anchor ( id_type node)
inline

Definition at line 755 of file tree.hpp.

755{ _p(node)->m_val.anchor.clear(); _rem_flags(node, VALANCH); }

◆ rem_key_ref()

void c4::yml::Tree::rem_key_ref ( id_type node)
inline

Definition at line 756 of file tree.hpp.

756{ _p(node)->m_key.anchor.clear(); _rem_flags(node, KEYREF); }

◆ rem_val_ref()

void c4::yml::Tree::rem_val_ref ( id_type node)
inline

Definition at line 757 of file tree.hpp.

757{ _p(node)->m_val.anchor.clear(); _rem_flags(node, VALREF); }

◆ rem_anchor_ref()

void c4::yml::Tree::rem_anchor_ref ( id_type node)
inline

Definition at line 758 of file tree.hpp.

758{ _p(node)->m_key.anchor.clear(); _p(node)->m_val.anchor.clear(); _rem_flags(node, KEYANCH|VALANCH|KEYREF|VALREF); }

◆ save() [1/2]

template<class T>
void c4::yml::Tree::save ( id_type node,
T const & val )
inline

Definition at line 776 of file tree.hpp.

777 {
778 if C4_LIKELY(node != NONE && node < m_first_unused && node >= 0)
779 {
780 write(this, node, val);
781 return;
782 }
783 err_visit_(node);
784 }
void write(NodeRef *n, T const &v)
Definition node.hpp:2114

Referenced by sample_serialize_basic(), and sample_user_container_types().

◆ save() [2/2]

template<class T>
void c4::yml::Tree::save ( id_type node,
T const & val,
NodeType more_flags )
inline

Definition at line 786 of file tree.hpp.

787 {
788 if C4_LIKELY(node != NONE && node < m_first_unused && node >= 0)
789 {
790 write(this, node, val);
791 _p(node)->m_type |= more_flags;
792 return;
793 }
794 err_visit_(node);
795 }

◆ save_key() [1/2]

template<class T>
void c4::yml::Tree::save_key ( id_type node,
T const & key )
inline

Definition at line 798 of file tree.hpp.

799 {
800 if C4_LIKELY(node != NONE && node < m_first_unused && node >= 0)
801 {
802 write_key(this, node, key);
803 return;
804 }
805 err_visit_(node);
806 }
void write_key(NodeRef *n, T const &v)
Definition node.hpp:2119

Referenced by sample_serialize_basic().

◆ save_key() [2/2]

template<class T>
void c4::yml::Tree::save_key ( id_type node,
T const & key,
NodeType more_flags )
inline

Definition at line 808 of file tree.hpp.

809 {
810 if C4_LIKELY(node != NONE && node < m_first_unused && node >= 0)
811 {
812 write_key(this, node, key);
813 _p(node)->m_type |= more_flags;
814 return;
815 }
816 err_visit_(node);
817 }

◆ set_serialized() [1/2]

template<class T>
void c4::yml::Tree::set_serialized ( id_type node,
T const & val )
inline

Definition at line 827 of file tree.hpp.

828 {
829 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
830 write(this, node, val);
831 }

Referenced by sample_base64(), sample_empty_null_values(), sample_serialize_basic(), c4::yml::write(), c4::yml::write(), write(), write(), and write().

◆ set_serialized() [2/2]

template<class T>
void c4::yml::Tree::set_serialized ( id_type node,
T const & val,
NodeType more_flags )
inline

Definition at line 833 of file tree.hpp.

834 {
835 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
836 write(this, node, val);
837 _p(node)->m_type |= more_flags;
838 }

◆ set_key_serialized() [1/2]

template<class T>
void c4::yml::Tree::set_key_serialized ( id_type node,
T const & key )
inline

Definition at line 841 of file tree.hpp.

842 {
843 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
844 write_key(this, node, key);
845 }

Referenced by sample_serialize_basic(), c4::yml::write(), write(), and c4::yml::write_key().

◆ set_key_serialized() [2/2]

template<class T>
void c4::yml::Tree::set_key_serialized ( id_type node,
T const & key,
NodeType more_flags )
inline

Definition at line 847 of file tree.hpp.

848 {
849 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
850 write_key(this, node, key);
851 _p(node)->m_type |= more_flags;
852 }

◆ to_result_() [1/2]

ReadResult c4::yml::Tree::to_result_ ( bool ,
id_type node )
inlinestaticnoexcept

Definition at line 865 of file tree.hpp.

865{ return ReadResult(node); }

◆ to_result_() [2/2]

ReadResult c4::yml::Tree::to_result_ ( ReadResult notlegacy,
id_type  )
inlinestaticnoexcept

Definition at line 866 of file tree.hpp.

866{ return notlegacy; }

◆ load() [1/2]

template<class T>
void c4::yml::Tree::load ( id_type node,
T * v,
bool check_readable = true ) const
inline

(1) deserialize the node's contents (val or container) to the given variable, forwarding to the user-overrideable read() function (see Read from Tree).

This function differs from Tree::deserialize() in that here the error callback is called if the deserialization failed, or (optionally) the node is not readable.

Definition at line 875 of file tree.hpp.

876 {
877 const bool can_read_val = (node != NONE && node < m_first_unused && node >= 0 && (_p(node)->m_type & (VAL|MAP|SEQ)));
878 RYML_ASSERT_VISIT_CB_(m_callbacks, can_read_val, this, node);
879 if C4_LIKELY(!check_readable || can_read_val)
880 {
881 const ReadResult result(read(this, node, v), node);
882 if C4_LIKELY(result)
883 return;
884 else
885 node = result.node;
886 }
887 err_visit_(node);
888 }
ReadResult read(ConstNodeRef const &n, T *v)
Definition node.hpp:2074

Referenced by sample_base64(), sample_error_visit(), sample_error_visit_location(), sample_fundamental_types(), sample_serialize_basic(), and sample_user_container_types().

◆ load() [2/2]

template<class Wrapper>
void c4::yml::Tree::load ( id_type node,
Wrapper const & w,
bool check_readable = true ) const
inline

(2) like (1), but for wrapper tag types such as c4::fmt::base64()

Definition at line 892 of file tree.hpp.

893 {
894 RYML_CHECK_TYPE_IS_WRAPPER_LIKE_(Wrapper);
895 const bool can_read_val = (node != NONE && node < m_first_unused && node >= 0 && (_p(node)->m_type & (VAL|MAP|SEQ)));
896 RYML_ASSERT_VISIT_CB_(m_callbacks, can_read_val, this, node);
897 if C4_LIKELY(!check_readable || can_read_val)
898 {
899 const ReadResult result(read(this, node, w), node);
900 if C4_LIKELY(result)
901 return;
902 else
903 node = result.node;
904 }
905 err_visit_(node);
906 }

◆ load_key() [1/2]

template<class T>
void c4::yml::Tree::load_key ( id_type node,
T * k,
bool check_readable = true ) const
inline

(1) deserialize the node's key (necessarily a scalar) to the given variable, forwarding to the user-overrideable read_key() function (see Read from ConstNodeRef).

This function differs from Tree::deserialize_key() in that here the error callback is called if the deserialization failed, or (optionally) the node is not readable.

Definition at line 916 of file tree.hpp.

917 {
918 const bool can_read_key = (node != NONE && node < m_first_unused && node >= 0 && (_p(node)->m_type & KEY));
919 RYML_ASSERT_VISIT_CB_(m_callbacks, can_read_key, this, node);
920 if C4_LIKELY(!check_readable || can_read_key)
921 {
922 const ReadResult result(read_key(this, node, k), node);
923 if C4_LIKELY(result)
924 return;
925 else
926 node = result.node;
927 }
928 err_visit_(node);
929 }
ReadResult read_key(ConstNodeRef const &n, T *v)
Definition node.hpp:2088

Referenced by sample_base64(), and sample_serialize_basic().

◆ load_key() [2/2]

template<class Wrapper>
void c4::yml::Tree::load_key ( id_type node,
Wrapper const & w,
bool check_readable = true ) const
inline

(2) like (1), but for wrapper tag types such as c4::fmt::base64()

Definition at line 933 of file tree.hpp.

934 {
935 RYML_CHECK_TYPE_IS_WRAPPER_LIKE_(Wrapper);
936 bool can_read_key = (node != NONE && node < m_first_unused && node >= 0 && (_p(node)->m_type & KEY));
937 RYML_ASSERT_VISIT_CB_(m_callbacks, can_read_key, this, node);
938 if C4_LIKELY(!check_readable || can_read_key)
939 {
940 const ReadResult result(read_key(this, node, w), node);
941 if C4_LIKELY(result)
942 return;
943 else
944 node = result.node;
945 }
946 err_visit_(node);
947 }

◆ deserialize() [1/2]

template<class T>
ReadResult c4::yml::Tree::deserialize ( id_type node,
T * v ) const
inline

(1) deserialize a node's contents to a variable

Definition at line 958 of file tree.hpp.

959 {
960 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
961 RYML_ASSERT_VISIT_CB_(m_callbacks, _p(node)->m_type & (VAL|MAP|SEQ), this, node);
962 // use the adapter ctor to accomodate legacy read() implementations
963 return ReadResult(read(this, node, v), node);
964 }

Referenced by deserialize_child(), deserialize_child(), deserialize_child(), deserialize_child(), deserialize_child(), deserialize_child(), c4::yml::read(), c4::yml::read(), read(), read(), sample_base64(), and sample_serialize_basic().

◆ deserialize() [2/2]

template<class Wrapper>
ReadResult c4::yml::Tree::deserialize ( id_type node,
Wrapper const & w ) const
inline

(2) like (1), but for a wrapper type like those used in tag functions

Definition at line 968 of file tree.hpp.

969 {
970 RYML_CHECK_TYPE_IS_WRAPPER_LIKE_(Wrapper);
971 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
972 RYML_ASSERT_VISIT_CB_(m_callbacks, _p(node)->m_type & (VAL|MAP|SEQ), this, node);
973 // use the adapter ctor to accomodate legacy read() implementations
974 return ReadResult(read(this, node, w), node);
975 }

◆ deserialize_key() [1/2]

template<class T>
ReadResult c4::yml::Tree::deserialize_key ( id_type node,
T * v ) const
inline

(1) deserialize a node's key to a variable

Definition at line 979 of file tree.hpp.

980 {
981 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
982 RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node);
983 // use the adapter ctor to accomodate legacy read_key() implementations
984 return ReadResult(read_key(this, node, v), node);
985 }

Referenced by c4::yml::read(), read(), and sample_serialize_basic().

◆ deserialize_key() [2/2]

template<class Wrapper>
ReadResult c4::yml::Tree::deserialize_key ( id_type node,
Wrapper const & w ) const
inline

(2) like (1), but for a wrapper type like those used in tag functions

Definition at line 989 of file tree.hpp.

990 {
991 RYML_CHECK_TYPE_IS_WRAPPER_LIKE_(Wrapper);
992 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE && node >= 0 && node < m_cap, this, node);
993 RYML_ASSERT_VISIT_CB_(m_callbacks, has_key(node), this, node);
994 // use the adapter ctor to accomodate legacy read_key() implementations
995 return ReadResult(read_key(this, node, w), node);
996 }

◆ deserialize_child() [1/6]

template<class T>
ReadResult c4::yml::Tree::deserialize_child ( id_type node,
csubstr child_key,
T * v ) const
inline

(1) find a child by name and deserialize its contents to the given variable (ie call .deserialize() on the child if it exists).

Otherwise, the variable is kept unchanged.

Returns
a ReadResult set with this node's id if no child exists, or the ReadResult from the deserialization.
See also
see also Tree::find_child_r()

Definition at line 1015 of file tree.hpp.

1016 {
1017 id_type ch;
1018 ReadResult r = find_child_r(node, child_key, &ch);
1019 if(r)
1020 r = deserialize(ch, v);
1021 return r;
1022 }
ReadResult deserialize(id_type node, T *v) const
(1) deserialize a node's contents to a variable
Definition tree.hpp:958

Referenced by read().

◆ deserialize_child() [2/6]

template<class T>
ReadResult c4::yml::Tree::deserialize_child ( id_type node,
csubstr child_key,
T * v,
T const & fallback ) const
inline

(2) like (1), but assign from fallback if no such child exists.

Definition at line 1025 of file tree.hpp.

1026 {
1027 id_type ch;
1028 if(find_child_r(node, child_key, &ch))
1029 return deserialize(ch, v);
1030 *v = fallback;
1031 return ReadResult();
1032 }

◆ deserialize_child() [3/6]

template<class Wrapper>
ReadResult c4::yml::Tree::deserialize_child ( id_type node,
csubstr child_key,
Wrapper const & wrapper ) const
inline

(3) like (1), but for wrapper tag types such as c4::fmt::base64()

Definition at line 1035 of file tree.hpp.

1036 {
1037 id_type ch;
1038 ReadResult r = find_child_r(node, child_key, &ch);
1039 if(r)
1040 r = deserialize(ch, wrapper);
1041 return r;
1042 }

◆ deserialize_child() [4/6]

template<class T>
ReadResult c4::yml::Tree::deserialize_child ( id_type node,
id_type child_pos,
T * v ) const
inline

(1) find a child by position and deserialize its contents to the given variable (ie call .deserialize() on the child if it exists).

Otherwise, the variable is kept unchanged.

Returns
a ReadResult set with this node's id if no child exists, or the ReadResult from the deserialization.
See also
see also Tree::child_r()

Definition at line 1054 of file tree.hpp.

1055 {
1056 RYML_ASSERT_VISIT_CB_(m_callbacks, is_container(node), this, node); // this assertion is needed because child_r() does not assert, contrary to find_child_r()
1057 id_type ch;
1058 ReadResult r = child_r(node, child_pos, &ch);
1059 if(r)
1060 r = deserialize(ch, v);
1061 return r;
1062 }

◆ deserialize_child() [5/6]

template<class T>
ReadResult c4::yml::Tree::deserialize_child ( id_type node,
id_type child_pos,
T * v,
T const & fallback ) const
inline

(2) like (1), but assign from fallback if no such child exists

Definition at line 1065 of file tree.hpp.

1066 {
1067 RYML_ASSERT_VISIT_CB_(m_callbacks, is_container(node), this, node); // this assertion is needed because child_r() does not assert, contrary to find_child_r()
1068 id_type ch;
1069 if(child_r(node, child_pos, &ch))
1070 return deserialize(ch, v);
1071 *v = fallback;
1072 return ReadResult();
1073 }

◆ deserialize_child() [6/6]

template<class Wrapper>
ReadResult c4::yml::Tree::deserialize_child ( id_type node,
id_type child_pos,
Wrapper const & wrapper ) const
inline

(3) like (1), but for wrapper tag types such as c4::fmt::base64()

Definition at line 1077 of file tree.hpp.

1078 {
1079 RYML_ASSERT_VISIT_CB_(m_callbacks, is_container(node), this, node); // this assertion is needed because child_r() does not assert, contrary to find_child_r()
1080 id_type ch;
1081 ReadResult r = child_r(node, child_pos, &ch);
1082 if(r)
1083 r = deserialize(ch, wrapper);
1084 return r;
1085 }

◆ reorder()

void c4::yml::Tree::reorder ( )

reorder the tree in memory so that all the nodes are stored in a linear sequence when visited in depth-first order.

This will invalidate existing ids, since the node id is its position in the tree's node array.

Definition at line 542 of file tree.cpp.

543{
544 id_type r = root_id();
545 _do_reorder(&r, 0);
546}

◆ resolve() [1/2]

void c4::yml::Tree::resolve ( ReferenceResolver * rr,
ResolveOptions const & opts = {} )

Resolve references (aliases <- anchors), by forwarding to ReferenceResolver::resolve().

Definition at line 1175 of file tree.cpp.

1176{
1177 if(m_size == 0)
1178 return;
1179 rr->resolve(this, opts);
1180}

Referenced by resolve(), sample_anchors_and_aliases(), and sample_anchors_and_aliases_create().

◆ resolve() [2/2]

void c4::yml::Tree::resolve ( ResolveOptions const & opts = {})

Resolve references (aliases <- anchors), by forwarding to ReferenceResolver::resolve().

This overload uses a throwaway resolver object.

Definition at line 1167 of file tree.cpp.

1168{
1169 if(m_size == 0)
1170 return;
1171 ReferenceResolver rr;
1172 resolve(&rr, opts);
1173}
void resolve(ReferenceResolver *rr, ResolveOptions const &opts={})
Resolve references (aliases <- anchors), by forwarding to ReferenceResolver::resolve().
Definition tree.cpp:1175

◆ resolve_tags()

void c4::yml::Tree::resolve_tags ( TagCache & cache,
bool all = true )

Resolve tags in the tree such as "!!str" -> "<tag:yaml.org,2002:str>", "!foo" -> "<!foo>" and custom tags as well, ie tags of the form "!handle!tag" for which there is a corresponding "%TAG" directive.

Parameters
cachean object of type TagCache to minimize memory usage by avoiding repeated instantiation of the resolved tags in the tree's arena.
allif true, resolve all tags; if false resolve only custom tags, ie those that have a prefix such as "!m!tag" with a matching "\%TAG" directive

Definition at line 1522 of file tree.cpp.

1523{
1524 if(empty())
1525 return;
1526 // try to resolve. While doing so, get the extra size needed for
1527 // the arena, if the arena is currently too small.
1528 size_t extra_size = _resolve_tags(this, cache, all);
1529 // if the arena requires extra size, grow it and then resolve the
1530 // missing entries
1531 if(extra_size)
1532 {
1533 _c4dbgpf("tag: extrasize={} -- retry! {}->{}", extra_size, m_arena.len, m_arena.len + extra_size);
1534 _grow_arena(extra_size);
1535 extra_size = _resolve_tags(this, cache, all);
1536 RYML_ASSERT_BASIC_CB_(callbacks(), extra_size == 0);
1537 }
1538}
bool empty() const
Query for zero size.
Definition tree.hpp:346
Callbacks const & callbacks() const
Definition tree.hpp:353

Referenced by sample_tag_directives().

◆ normalize_tags()

void c4::yml::Tree::normalize_tags ( )

Definition at line 1540 of file tree.cpp.

1541{
1542 if(empty())
1543 return;
1544 _normalize_tags(this, root_id());
1545}

Referenced by sample_tags().

◆ normalize_tags_long()

void c4::yml::Tree::normalize_tags_long ( )

Definition at line 1547 of file tree.cpp.

1548{
1549 if(empty())
1550 return;
1551 _normalize_tags_long(this, root_id());
1552}

Referenced by sample_tags().

◆ num_tag_directives()

id_type c4::yml::Tree::num_tag_directives ( ) const

Definition at line 1403 of file tree.cpp.

1404{
1405 return m_tag_directives.size();
1406}

◆ add_tag_directive()

void c4::yml::Tree::add_tag_directive ( csubstr handle,
csubstr prefix,
id_type id )

Definition at line 1413 of file tree.cpp.

1414{
1415 RYML_CHECK_BASIC_CB_(m_callbacks,
1416 !handle.empty()
1417 &&
1418 !prefix.empty()
1419 &&
1420 is_valid_tag_handle(handle)
1421 &&
1422 m_tag_directives.add(handle, prefix, id));
1423}
bool is_valid_tag_handle(csubstr handle)
Definition tag.cpp:210

Referenced by sample_error_basic().

◆ clear_tag_directives()

void c4::yml::Tree::clear_tag_directives ( )

Definition at line 1408 of file tree.cpp.

1409{
1410 m_tag_directives.clear();
1411}

◆ resolve_tag()

size_t c4::yml::Tree::resolve_tag ( substr output,
csubstr tag,
id_type node_id ) const

resolve the given tag, appearing at node_id.

Write the result into output.

Returns
the number of characters required for the resolved tag

Definition at line 1425 of file tree.cpp.

1426{
1427 size_t reqsz = 0;
1428 m_tag_directives.resolve(output, &reqsz, tag, node_id, Location{}, callbacks());
1429 return reqsz;
1430}

Referenced by resolve_tag_sub().

◆ resolve_tag_sub()

csubstr c4::yml::Tree::resolve_tag_sub ( substr output,
csubstr tag,
id_type node_id ) const
inline

Wrapper for Tree::resolve_tag(), returning a substring.

Definition at line 1159 of file tree.hpp.

1160 {
1161 size_t needed = resolve_tag(output, tag, node_id);
1162 return needed <= output.len ? output.first(needed) : output;
1163 }
size_t resolve_tag(substr output, csubstr tag, id_type node_id) const
resolve the given tag, appearing at node_id.
Definition tree.cpp:1425

◆ tag_directives()

c4::yml::TagDirectiveRange c4::yml::Tree::tag_directives ( ) const
inline

Definition at line 1165 of file tree.hpp.

1165{ return m_tag_directives.directives(); }

◆ insert_child()

id_type c4::yml::Tree::insert_child ( id_type parent,
id_type after )
inline

create and insert a new child of parent.

insert after the (to-be) sibling after, which must be a child of parent. To insert as the first child, set after to NONE

Definition at line 1182 of file tree.hpp.

1183 {
1184 RYML_ASSERT_VISIT_CB_(m_callbacks, parent != NONE, this, parent);
1185 RYML_ASSERT_VISIT_CB_(m_callbacks, is_container(parent) || is_root(parent), this, parent);
1186 RYML_ASSERT_VISIT_CB_(m_callbacks, after == NONE || (_p(after)->m_parent == parent), this, parent);
1187 id_type child = _claim();
1188 _set_hierarchy(child, parent, after);
1189 return child;
1190 }

Referenced by append_child(), insert_child(), insert_sibling(), and prepend_child().

◆ prepend_child()

id_type c4::yml::Tree::prepend_child ( id_type parent)
inline

create and insert a node as the first child of parent

Definition at line 1192 of file tree.hpp.

1192{ return insert_child(parent, NONE); }
id_type insert_child(id_type parent, id_type after)
create and insert a new child of parent.
Definition tree.hpp:1182

Referenced by prepend_sibling().

◆ append_child()

id_type c4::yml::Tree::append_child ( id_type parent)
inline

create and insert a node as the last child of parent

Definition at line 1194 of file tree.hpp.

1194{ return insert_child(parent, _p(parent)->m_last_child); }

Referenced by append_sibling(), merge_with(), set_root_as_stream(), c4::yml::write(), write(), write(), write(), and write().

◆ _append_child__unprotected()

id_type c4::yml::Tree::_append_child__unprotected ( id_type parent)
inline

Definition at line 1195 of file tree.hpp.

1196 {
1197 id_type child = _claim();
1198 _set_hierarchy(child, parent, _p(parent)->m_last_child);
1199 return child;
1200 }

◆ insert_sibling()

id_type c4::yml::Tree::insert_sibling ( id_type node,
id_type after )
inline

create and insert a new sibling of n. insert after "after"

Definition at line 1205 of file tree.hpp.

1206 {
1207 return insert_child(_p(node)->m_parent, after);
1208 }

◆ prepend_sibling()

id_type c4::yml::Tree::prepend_sibling ( id_type node)
inline

create and insert a node as the first node of parent

Definition at line 1210 of file tree.hpp.

1210{ return prepend_child(_p(node)->m_parent); }
id_type prepend_child(id_type parent)
create and insert a node as the first child of parent
Definition tree.hpp:1192

◆ append_sibling()

id_type c4::yml::Tree::append_sibling ( id_type node)
inline

Definition at line 1211 of file tree.hpp.

1211{ return append_child(_p(node)->m_parent); }
id_type append_child(id_type parent)
create and insert a node as the last child of parent
Definition tree.hpp:1194

◆ remove()

void c4::yml::Tree::remove ( id_type node)
inline

remove an entire branch at once: ie remove the children and the node itself

Definition at line 1216 of file tree.hpp.

1217 {
1218 remove_children(node);
1219 _release(node);
1220 }
void remove_children(id_type node)
remove all the node's children, but keep the node itself
Definition tree.cpp:886

Referenced by duplicate_children_no_rep(), and move().

◆ remove_children()

void c4::yml::Tree::remove_children ( id_type node)

remove all the node's children, but keep the node itself

Definition at line 886 of file tree.cpp.

887{
888 RYML_ASSERT_VISIT_CB_(m_callbacks, get(node) != nullptr, this, node);
889 C4_SUPPRESS_WARNING_GCC_PUSH
890 #if defined(__GNUC__) && __GNUC__ >= 6
891 C4_SUPPRESS_WARNING_GCC("-Wnull-dereference")
892 #endif
893 id_type ich = get(node)->m_first_child;
894 while(ich != NONE)
895 {
896 remove_children(ich);
897 RYML_ASSERT_VISIT_CB_(m_callbacks, get(ich) != nullptr, this, node);
898 id_type next = get(ich)->m_next_sibling;
899 _release(ich);
900 if(ich == get(node)->m_last_child)
901 break;
902 ich = next;
903 }
904 C4_SUPPRESS_WARNING_GCC_POP
905}
NodeData * get(id_type node)
get a pointer to a node's NodeData. node can be NONE, in which case a nullptr is returned
Definition tree.hpp:365

Referenced by change_type(), merge_with(), remove(), and remove_children().

◆ move() [1/3]

void c4::yml::Tree::move ( id_type node,
id_type after )

change the node's position in the parent

Definition at line 786 of file tree.cpp.

787{
788 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
789 RYML_ASSERT_VISIT_CB_(m_callbacks, node != after, this, node);
790 RYML_ASSERT_VISIT_CB_(m_callbacks, ! is_root(node), this, node);
791 RYML_ASSERT_VISIT_CB_(m_callbacks, (after == NONE) || (has_sibling(node, after) && has_sibling(after, node)), this, node);
792
793 _rem_hierarchy(node);
794 _set_hierarchy(node, parent(node), after);
795}
bool has_sibling(id_type node, id_type sib) const
true if node has a sibling with id sib
Definition tree.hpp:551

Referenced by duplicate_children_no_rep(), and set_root_as_stream().

◆ move() [2/3]

void c4::yml::Tree::move ( id_type node,
id_type new_parent,
id_type after )

change the node's parent and position

Definition at line 799 of file tree.cpp.

800{
801 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, node);
802 RYML_ASSERT_VISIT_CB_(m_callbacks, node != after, this, node);
803 RYML_ASSERT_VISIT_CB_(m_callbacks, new_parent != NONE, this, new_parent);
804 RYML_ASSERT_VISIT_CB_(m_callbacks, new_parent != node, this, new_parent);
805 RYML_ASSERT_VISIT_CB_(m_callbacks, new_parent != after, this, new_parent);
806 RYML_ASSERT_VISIT_CB_(m_callbacks, ! is_root(node), this, node);
807
808 _rem_hierarchy(node);
809 _set_hierarchy(node, new_parent, after);
810}

◆ move() [3/3]

id_type c4::yml::Tree::move ( Tree * src,
id_type node,
id_type new_parent,
id_type after )

change the node's parent and position to a different tree

Returns
the index of the new node in the destination tree

Definition at line 812 of file tree.cpp.

813{
814 RYML_ASSERT_VISIT_CB_(m_callbacks, src != nullptr, this, new_parent);
815 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, this, new_parent);
816 RYML_ASSERT_VISIT_CB_(m_callbacks, new_parent != NONE, this, new_parent);
817 RYML_ASSERT_VISIT_CB_(m_callbacks, new_parent != after, this, new_parent);
818
819 id_type dup = duplicate(src, node, new_parent, after);
820 src->remove(node);
821 return dup;
822}
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:929

◆ set_root_as_stream()

void c4::yml::Tree::set_root_as_stream ( )

ensure the first node is a stream.

Eg, change this tree

DOCMAP MAP KEYVAL KEYVAL SEQ VAL

to

STREAM DOCMAP MAP KEYVAL KEYVAL SEQ VAL

If the root is already a stream, this is a no-op.

Definition at line 824 of file tree.cpp.

825{
826 id_type root = root_id();
827 NodeType ty = type(root);
828 if(ty.is_stream())
829 return;
830 _c4dbgpf("set_root_as_stream. rootty={}", type(root).m_bits);
831 bool empty_root = ((type(root) & (SEQ|MAP|VAL)) == 0);
832 for(TagDirective &C4_RESTRICT td : m_tag_directives)
833 {
834 if(td.doc_id >= m_first_unused || _p(td.doc_id)->m_parent == NONE)
835 {
836 _c4dbgpf("tagd[{}]: id={}->NONE", &td-m_tag_directives.m_directives, td.doc_id);
837 td.doc_id = NONE;
838 }
839 }
840 // don't use _add_flags() because it's checked and will fail
841 id_type next_doc;
842 if(!has_children(root))
843 {
844 if(ty.is_container())
845 {
846 next_doc = append_child(root);
847 _copy_props_wo_key(next_doc, root);
848 _p(next_doc)->m_type.add(DOC);
849 }
850 else
851 {
852 _p(root)->m_type.add(SEQ);
853 next_doc = append_child(root);
854 _copy_props_wo_key(next_doc, root);
855 _p(next_doc)->m_type.add(DOC);
856 _p(next_doc)->m_type.rem(SEQ);
857 }
858 }
859 else
860 {
861 RYML_ASSERT_VISIT_CB_(m_callbacks, !ty.has_key(), this, root);
862 next_doc = append_child(root);
863 _copy_props_wo_key(next_doc, root);
864 _add_flags(next_doc, DOC);
865 for(id_type prev = NONE, ch = first_child(root), next = next_sibling(ch); ch != NONE; )
866 {
867 if(ch == next_doc)
868 break;
869 move(ch, next_doc, prev);
870 prev = ch;
871 ch = next;
872 next = next_sibling(next);
873 }
874 }
875 _p(root)->m_type = STREAM;
876 for(TagDirective &C4_RESTRICT td : m_tag_directives)
877 {
878 id_type id = (td.doc_id != NONE) ? next_doc : (empty_root ? first_child(root) : (m_free_head != NONE ? m_free_head : m_first_unused));
879 _c4dbgpf("tagd[{}]: id={}->{}", &td-m_tag_directives.m_directives, td.doc_id, id);
880 td.doc_id = id;
881 }
882}
void move(id_type node, id_type after)
change the node's position in the parent
Definition tree.cpp:786
NodeType type(id_type node) const
Definition tree.hpp:456
id_type id(NodeData const *n) const
get the id of a node belonging to this tree. n can be nullptr, in which case NONE is returned n must ...
Definition tree.hpp:396
void rem(type_bits t) noexcept
void add(type_bits t) noexcept

◆ change_type() [1/2]

bool c4::yml::Tree::change_type ( id_type node,
NodeType type )

Definition at line 909 of file tree.cpp.

910{
911 NodeType curr = this->type(node);
912 RYML_ASSERT_VISIT_CB_(m_callbacks, next.is_val() || next.is_map() || next.is_seq(), this, node);
913 RYML_ASSERT_VISIT_CB_(m_callbacks, next.is_val() + next.is_map() + next.is_seq() == 1, this, node);
914 RYML_ASSERT_VISIT_CB_(m_callbacks, next.has_key() == curr.has_key() || (curr.has_key() && !next.has_key()), this, node);
915 NodeData *d = _p(node);
916 if(next.is_map() && curr.is_map())
917 return false;
918 else if(next.is_seq() && curr.is_seq())
919 return false;
920 else if(next.is_val() && curr.is_val())
921 return false;
922 d->m_type.m_bits = (d->m_type.m_bits & (~(MAP|SEQ|VAL|CONTAINER_STYLE|KEY_STYLE|VAL_STYLE))) | next;
923 remove_children(node);
924 return true;
925}
@ VAL_STYLE
mask of VALQUO|VAL_PLAIN : all the val scalar styles for val (not container styles!...
@ KEY_STYLE
mask of KEYQUO|KEY_PLAIN : all the key scalar styles for key (not container styles!...
@ CONTAINER_STYLE
mask of CONTAINER_STYLE_FLOW|CONTAINER_STYLE_BLOCK : all container style flags

Referenced by change_type().

◆ change_type() [2/2]

bool c4::yml::Tree::change_type ( id_type node,
type_bits type )
inline

Definition at line 1261 of file tree.hpp.

1262 {
1263 return change_type(node, (NodeType)type);
1264 }
bool change_type(id_type node, NodeType type)
Definition tree.cpp:909

◆ duplicate() [1/2]

id_type c4::yml::Tree::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

Returns
the index of the copy

Definition at line 929 of file tree.cpp.

930{
931 return duplicate(this, node, parent, after);
932}

Referenced by duplicate(), duplicate_children(), duplicate_children_no_rep(), and move().

◆ duplicate() [2/2]

id_type c4::yml::Tree::duplicate ( Tree const * src,
id_type node,
id_type new_parent,
id_type after )

recursively duplicate a node from a different tree into a new parent, placing it after one of its children

Returns
the index of the copy

Definition at line 934 of file tree.cpp.

935{
936 RYML_ASSERT_VISIT_CB_(m_callbacks, src != nullptr, src, node);
937 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, src, node);
938 RYML_ASSERT_VISIT_CB_(m_callbacks, parent != NONE, this, parent);
939 RYML_ASSERT_VISIT_CB_(m_callbacks, ! src->is_root(node), src, node);
940
941 id_type copy = _claim();
942
943 _copy_props(copy, src, node);
944 _set_hierarchy(copy, parent, after);
945 duplicate_children(src, node, copy, NONE);
946
947 return copy;
948}
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:952

◆ duplicate_children() [1/2]

id_type c4::yml::Tree::duplicate_children ( id_type node,
id_type parent,
id_type after )

recursively duplicate the node's children (but not the node)

Returns
the index of the last duplicated child

Definition at line 952 of file tree.cpp.

953{
954 return duplicate_children(this, node, parent, after);
955}

Referenced by duplicate(), duplicate_children(), and duplicate_contents().

◆ duplicate_children() [2/2]

id_type c4::yml::Tree::duplicate_children ( Tree const * src,
id_type node,
id_type parent,
id_type after )

recursively duplicate the node's children (but not the node), where the node is from a different tree

Returns
the index of the last duplicated child

Definition at line 957 of file tree.cpp.

958{
959 RYML_ASSERT_VISIT_CB_(m_callbacks, src != nullptr, src, node);
960 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, src, node);
961 RYML_ASSERT_VISIT_CB_(m_callbacks, parent != NONE, this, parent);
962 RYML_ASSERT_VISIT_CB_(m_callbacks, after == NONE || has_child(parent, after), this, parent);
963
964 id_type prev = after;
965 for(id_type i = src->first_child(node); i != NONE; i = src->next_sibling(i))
966 {
967 prev = duplicate(src, i, parent, prev);
968 }
969
970 return prev;
971}
bool has_child(id_type node, id_type ch) const
true if node has a child with id ch
Definition tree.hpp:544

◆ duplicate_children_no_rep() [1/2]

id_type c4::yml::Tree::duplicate_children_no_rep ( id_type node,
id_type parent,
id_type after )

duplicate the node's children (but not the node) in a new parent, but omit repetitions where a duplicated node has the same key (in maps) or value (in seqs).

If one of the duplicated children has the same key (in maps) or value (in seqs) as one of the parent's children, the one that is placed closest to the end will prevail.

Definition at line 989 of file tree.cpp.

990{
991 return duplicate_children_no_rep(this, node, parent, after);
992}
id_type duplicate_children_no_rep(id_type node, id_type parent, id_type after)
duplicate the node's children (but not the node) in a new parent, but omit repetitions where a duplic...
Definition tree.cpp:989

Referenced by duplicate_children_no_rep().

◆ duplicate_children_no_rep() [2/2]

id_type c4::yml::Tree::duplicate_children_no_rep ( Tree const * src,
id_type node,
id_type parent,
id_type after )

Definition at line 994 of file tree.cpp.

995{
996 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, src, node);
997 RYML_ASSERT_VISIT_CB_(m_callbacks, parent != NONE, this, parent);
998 RYML_ASSERT_VISIT_CB_(m_callbacks, after == NONE || has_child(parent, after), this, parent);
999
1000 // don't loop using pointers as there may be a relocation
1001
1002 // find the position where "after" is
1003 id_type after_pos = NONE;
1004 if(after != NONE)
1005 {
1006 for(id_type i = first_child(parent), icount = 0; i != NONE; ++icount, i = next_sibling(i))
1007 {
1008 if(i == after)
1009 {
1010 after_pos = icount;
1011 break;
1012 }
1013 }
1014 RYML_ASSERT_VISIT_CB_(m_callbacks, after_pos != NONE, this, node);
1015 }
1016
1017 // for each child to be duplicated...
1018 id_type prev = after;
1019 NodeType pty = type(parent);
1020 for(id_type i = src->first_child(node); i != NONE; i = src->next_sibling(i))
1021 {
1022 _c4dbgpf("duplicate_no_rep: {} -> {}/{}", i, parent, prev);
1023 RYML_CHECK_VISIT_CB_(m_callbacks, this != src || (parent != i && !is_ancestor(parent, i)), this, parent);
1024 if(pty.is_seq())
1025 {
1026 _c4dbgpf("duplicate_no_rep: {} is seq", parent);
1027 prev = duplicate(src, i, parent, prev);
1028 }
1029 else
1030 {
1031 _c4dbgpf("duplicate_no_rep: {} is map", parent);
1032 RYML_ASSERT_VISIT_CB_(m_callbacks, pty.is_map(), this, parent);
1033 // does the parent already have a node with key equal to that of the current duplicate?
1034 id_type dstnode_dup = NONE, dstnode_dup_pos = NONE;
1035 {
1036 csubstr srckey = src->key(i);
1037 for(id_type j = first_child(parent), jcount = 0; j != NONE; ++jcount, j = next_sibling(j))
1038 {
1039 if(key(j) == srckey)
1040 {
1041 _c4dbgpf("duplicate_no_rep: found matching key '{}' src={}/{} dst={}/{}", srckey, node, i, parent, j);
1042 dstnode_dup = j;
1043 dstnode_dup_pos = jcount;
1044 break;
1045 }
1046 }
1047 }
1048 _c4dbgpf("duplicate_no_rep: dstnode_dup={} dstnode_dup_pos={} after_pos={}", dstnode_dup, dstnode_dup_pos, after_pos);
1049 if(dstnode_dup == NONE) // there is no repetition; just duplicate
1050 {
1051 _c4dbgpf("duplicate_no_rep: no repetition, just duplicate i={} parent={} prev={}", i, parent, prev);
1052 prev = duplicate(src, i, parent, prev);
1053 }
1054 else // yes, there is a repetition
1055 {
1056 if(after_pos != NONE && dstnode_dup_pos <= after_pos)
1057 {
1058 // the dst duplicate is located before the node which will be inserted,
1059 // and will be overridden by the duplicate. So replace it.
1060 _c4dbgpf("duplicate_no_dstnode_dup: replace {}/{} with {}/{}", parent, dstnode_dup, node, i);
1061 if(prev == dstnode_dup)
1062 prev = prev_sibling(dstnode_dup);
1063 remove(dstnode_dup);
1064 prev = duplicate(src, i, parent, prev);
1065 }
1066 else if(prev == NONE)
1067 {
1068 _c4dbgpf("duplicate_no_dstnode_dup: {}=prev <- {}", prev, dstnode_dup);
1069 // first iteration with prev = after = NONE and dstnode_dupetition
1070 prev = dstnode_dup;
1071 }
1072 else if(dstnode_dup != prev)
1073 {
1074 // dstnode_dup is located after the node which will be inserted
1075 // and overrides it. So move the dstnode_dup into this node's place.
1076 _c4dbgpf("duplicate_no_dstnode_dup: move({}, {})", dstnode_dup, prev);
1077 move(dstnode_dup, prev);
1078 prev = dstnode_dup;
1079 }
1080 } // there's a dstnode_dupetition
1081 }
1082 }
1083
1084 return prev;
1085}
id_type prev_sibling(id_type node) const
Definition tree.hpp:575
bool is_ancestor(id_type node, id_type ancestor) const
true when ancestor is parent or parent of a parent of node
Definition tree.cpp:1273
void remove(id_type node)
remove an entire branch at once: ie remove the children and the node itself
Definition tree.hpp:1216
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2356

◆ duplicate_contents() [1/2]

void c4::yml::Tree::duplicate_contents ( id_type node,
id_type where )

Definition at line 974 of file tree.cpp.

975{
976 duplicate_contents(this, node, where);
977}
void duplicate_contents(id_type node, id_type where)
Definition tree.cpp:974

Referenced by duplicate_contents().

◆ duplicate_contents() [2/2]

void c4::yml::Tree::duplicate_contents ( Tree const * src,
id_type node,
id_type where )

Definition at line 979 of file tree.cpp.

980{
981 RYML_ASSERT_VISIT_CB_(m_callbacks, src != nullptr, src, node);
982 RYML_ASSERT_VISIT_CB_(m_callbacks, node != NONE, src, node);
983 RYML_ASSERT_VISIT_CB_(m_callbacks, where != NONE, this, where);
984 _copy_props_wo_key(where, src, node);
985 duplicate_children(src, node, where, last_child(where));
986}
id_type last_child(id_type node) const
Definition tree.hpp:582

◆ merge_with()

void c4::yml::Tree::merge_with ( Tree const * src,
id_type src_node = NONE,
id_type dst_root = NONE )

Definition at line 1090 of file tree.cpp.

1091{
1092 RYML_ASSERT_VISIT_CB_(m_callbacks, src != nullptr, src, src_node);
1093 if(src_node == NONE)
1094 src_node = src->root_id();
1095 if(dst_node == NONE)
1096 dst_node = root_id();
1097 NodeType srcty = src->type(src_node);
1098 NodeType dstty = type(dst_node);
1099 RYML_ASSERT_VISIT_CB_(m_callbacks, srcty.has_val() || srcty.is_seq() || srcty.is_map(), src, src_node);
1100 if(srcty.has_val())
1101 {
1102 type_bits mask_src = ~STYLE; // keep the existing style if it is already a val
1103 if( ! dstty.has_val())
1104 {
1105 if(has_children(dst_node))
1106 remove_children(dst_node);
1107 mask_src |= VAL_STYLE; // copy the src style
1108 }
1109 if(srcty.is_keyval())
1110 {
1111 _copy_props(dst_node, src, src_node, mask_src);
1112 }
1113 else
1114 {
1115 RYML_ASSERT_VISIT_CB_(m_callbacks, srcty.is_val(), src, src_node);
1116 _copy_props_wo_key(dst_node, src, src_node, mask_src);
1117 }
1118 }
1119 else if(srcty.is_seq())
1120 {
1121 if( ! dstty.is_seq())
1122 {
1123 if(has_children(dst_node))
1124 remove_children(dst_node);
1125 _clear_type(dst_node);
1126 if(src->has_key(src_node))
1127 set_key(dst_node, src->key(src_node));
1128 set_seq(dst_node);
1129 _p(dst_node)->m_type = src->_p(src_node)->m_type;
1130 }
1131 for(id_type sch = src->first_child(src_node); sch != NONE; sch = src->next_sibling(sch))
1132 {
1133 id_type dch = append_child(dst_node);
1134 _copy_props_wo_key(dch, src, sch);
1135 merge_with(src, sch, dch);
1136 }
1137 }
1138 else
1139 {
1140 RYML_ASSERT_VISIT_CB_(m_callbacks, srcty.is_map(), src, src_node);
1141 if( ! dstty.is_map())
1142 {
1143 if(has_children(dst_node))
1144 remove_children(dst_node);
1145 _clear_type(dst_node);
1146 if(src->has_key(src_node))
1147 set_key(dst_node, src->key(src_node));
1148 set_map(dst_node);
1149 _p(dst_node)->m_type = src->_p(src_node)->m_type;
1150 }
1151 for(id_type sch = src->first_child(src_node); sch != NONE; sch = src->next_sibling(sch))
1152 {
1153 id_type dch = find_child(dst_node, src->key(sch));
1154 if(dch == NONE)
1155 {
1156 dch = append_child(dst_node);
1157 _copy_props(dch, src, sch);
1158 }
1159 merge_with(src, sch, dch);
1160 }
1161 }
1162}
void set_seq(id_type node) RYML_NOEXCEPT
Definition tree.hpp:724
void set_map(id_type node) RYML_NOEXCEPT
Definition tree.hpp:735
void set_key(id_type node, csubstr key) RYML_NOEXCEPT
Definition tree.hpp:709
void merge_with(Tree const *src, id_type src_node=NONE, id_type dst_root=NONE)
Definition tree.cpp:1090
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition node_type.hpp:26

Referenced by lookup_path_or_modify(), and merge_with().

◆ location()

Location c4::yml::Tree::location ( Parser const & p,
id_type node ) const

Get the location of a node from the parse used to parse this tree.

Definition at line 1882 of file tree.cpp.

1883{
1884 // try hard to avoid getting the location from a null string.
1885 Location loc;
1886 if(_location_from_node(parser, node, &loc, 0))
1887 return loc;
1888 return parser.val_location(parser.source().str);
1889}

Referenced by sample_deserialize_error(), sample_error_visit_location(), and sample_location_tracking().

◆ arena_size()

size_t c4::yml::Tree::arena_size ( ) const
inline

get the current size of the tree's internal arena

Definition at line 1323 of file tree.hpp.

1323{ return m_arena_pos; }

◆ arena_capacity()

size_t c4::yml::Tree::arena_capacity ( ) const
inline

get the current capacity of the tree's internal arena

Definition at line 1325 of file tree.hpp.

1325{ return m_arena.len; }

Referenced by Tree(), Tree(), and sample_tree_arena().

◆ arena_slack()

size_t c4::yml::Tree::arena_slack ( ) const
inline

get the current slack of the tree's internal arena

Definition at line 1327 of file tree.hpp.

1327{ RYML_ASSERT_VISIT_CB_(m_callbacks, m_arena.len >= m_arena_pos, this, NONE); return m_arena.len - m_arena_pos; }

Referenced by alloc_arena().

◆ arena_pos()

size_t c4::yml::Tree::arena_pos ( ) const
inline

Definition at line 1328 of file tree.hpp.

1328{ return m_arena_pos; }

Referenced by arena_pos().

◆ arena() [1/2]

csubstr c4::yml::Tree::arena ( ) const
inline

get the current arena

Definition at line 1331 of file tree.hpp.

1331{ return m_arena.first(m_arena_pos); }

Referenced by sample_empty_null_values(), sample_fundamental_types(), sample_quick_overview(), sample_tree_arena(), and sample_user_container_types().

◆ arena() [2/2]

substr c4::yml::Tree::arena ( )
inline

get the current arena

Definition at line 1333 of file tree.hpp.

1333{ return m_arena.first(m_arena_pos); } // NOLINT(readability-make-member-function-const)

◆ arena_rem() [1/2]

csubstr c4::yml::Tree::arena_rem ( ) const
inline

get the free space at the end of the arena

Definition at line 1336 of file tree.hpp.

1336{ return m_arena.sub(m_arena_pos); }

Referenced by c4::yml::serialize_to_arena_scalar().

◆ arena_rem() [2/2]

substr c4::yml::Tree::arena_rem ( )
inline

get the free space at the end of the arena

Definition at line 1338 of file tree.hpp.

1338{ return m_arena.sub(m_arena_pos); } // NOLINT(readability-make-member-function-const)

◆ in_arena()

bool c4::yml::Tree::in_arena ( csubstr s) const
inline

return true if the given substring is part of the tree's string arena

Definition at line 1341 of file tree.hpp.

1342 {
1343 return m_arena.is_super(s);
1344 }

Referenced by sample_quick_overview().

◆ to_arena()

template<class T>
csubstr c4::yml::Tree::to_arena ( T const & a)
inline

serialize the given variable to the tree's arena, growing it as needed to accomodate the serialization.

Note
To customize how the type gets serialized to a string, you can overload c4::to_chars(substr, T const&)
To customize how the type gets serialized to the arena, you can overload scalar_serialize()
Growing the arena may cause relocation of the entire existing arena, and thus change the contents of individual nodes, and thus cost O(numnodes)+O(arenasize). To avoid this cost, ensure that the arena is reserved to an appropriate size using Tree::reserve_arena().
See also
alloc_arena()

Definition at line 1363 of file tree.hpp.

1364 {
1365 return serialize_to_arena(this, a);
1366 }
csubstr serialize_to_arena(Tree *tree, T const &scalar)
Serialize a scalar to a tree's arena, dispatching to either serialize_to_arena_scalar() or serialize_...
Definition tree.hpp:112

Referenced by sample_fundamental_types(), and sample_tree_arena().

◆ copy_to_arena()

substr c4::yml::Tree::copy_to_arena ( csubstr s)
inline

copy the given string to the tree's arena, growing the arena by the required size.

Note
this method differs from to_arena() in that it returns a mutable substr, and further it does not deal with some corner cases for null/empty strings
Growing the arena may cause relocation of the entire existing arena, and thus change the contents of individual nodes, and thus cost O(numnodes)+O(arenasize). To avoid this cost, ensure that the arena is reserved to an appropriate size before using Tree::reserve_arena()
See also
reserve_arena()
alloc_arena()

Definition at line 1384 of file tree.hpp.

1385 {
1386 RYML_ASSERT_VISIT_CB_(m_callbacks, !s.overlaps(m_arena), this, NONE);
1387 substr cp = alloc_arena(s.len);
1388 RYML_ASSERT_VISIT_CB_(m_callbacks, cp.len == s.len, this, NONE);
1389 RYML_ASSERT_VISIT_CB_(m_callbacks, !s.overlaps(cp), this, NONE);
1390 C4_SUPPRESS_WARNING_GCC_PUSH
1391 #if (!defined(__clang__)) && (defined(__GNUC__) && __GNUC__ >= 10)
1392 C4_SUPPRESS_WARNING_GCC("-Wstringop-overflow=") // no need for terminating \0
1393 C4_SUPPRESS_WARNING_GCC("-Wrestrict") // there's an assert to ensure no violation of restrict behavior
1394 #endif
1395 if(s.len)
1396 memcpy(cp.str, s.str, s.len);
1397 C4_SUPPRESS_WARNING_GCC_POP
1398 return cp;
1399 }
substr alloc_arena(size_t sz)
grow the tree's string arena by the given size and return a substr of the added portion
Definition tree.hpp:1411
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2355

Referenced by sample_tree_arena().

◆ alloc_arena()

substr c4::yml::Tree::alloc_arena ( size_t sz)
inline

grow the tree's string arena by the given size and return a substr of the added portion

Note
Growing the arena may cause relocation of the entire existing arena, and thus change the contents of individual nodes, and thus cost O(numnodes)+O(arenasize). To avoid this cost, ensure that the arena is reserved to an appropriate size using Tree::reserve_arena().
See also
reserve_arena()

Definition at line 1411 of file tree.hpp.

1412 {
1413 if(sz > arena_slack())
1414 _grow_arena(sz - arena_slack());
1415 substr s = _request_span(sz);
1416 return s;
1417 }
size_t arena_slack() const
get the current slack of the tree's internal arena
Definition tree.hpp:1327

Referenced by copy_to_arena(), and sample_tree_arena().

◆ reserve_arena()

void c4::yml::Tree::reserve_arena ( size_t arena_cap = RYML_DEFAULT_TREE_ARENA_CAPACITY)
inline

ensure the tree's internal string arena is at least the given capacity

Warning
This operation may be expensive, with a potential complexity of O(numNodes)+O(arenasize).
Growing the arena may cause relocation of the entire existing arena, and thus change the contents of individual nodes.

Definition at line 1423 of file tree.hpp.

1424 {
1425 if(arena_cap > m_arena.len)
1426 {
1427 substr buf;
1428 buf.str = RYML_CB_ALLOC_(m_callbacks, char, arena_cap);
1429 buf.len = arena_cap;
1430 if(m_arena.str)
1431 {
1432 RYML_ASSERT_VISIT_CB_(m_callbacks, m_arena.len >= 0, this, NONE);
1433 _relocate(buf); // does a memcpy and changes nodes using the arena
1434 RYML_CB_FREE_(m_callbacks, m_arena.str, char, m_arena.len);
1435 }
1436 m_arena = buf;
1437 }
1438 }
C * str
a restricted pointer to the first character of the substring
Definition substr.hpp:216

Referenced by Tree(), sample_global_allocator(), sample_parse_reuse_tree(), and sample_tree_arena().

◆ lookup_path()

Tree::lookup_result c4::yml::Tree::lookup_path ( csubstr path,
id_type start = NONE ) const

for example foo.bar[0].baz

Definition at line 1577 of file tree.cpp.

1578{
1579 if(start == NONE)
1580 start = root_id();
1581 lookup_result r(path, start);
1582 if(path.empty())
1583 return r;
1584 _lookup_path(&r);
1585 if(r.target == NONE && r.closest == start)
1586 r.closest = NONE;
1587 return r;
1588}

◆ lookup_path_or_modify() [1/2]

id_type c4::yml::Tree::lookup_path_or_modify ( csubstr default_value,
csubstr path,
id_type start = NONE )

defaulted lookup: lookup path; if the lookup fails, recursively modify the tree so that the corresponding lookup_path() would return the default value.

See also
lookup_path()

Definition at line 1590 of file tree.cpp.

1591{
1592 id_type target = _lookup_path_or_create(path, start);
1593 set_val(target, default_value);
1594 return target;
1595}
void set_val(id_type node, csubstr val) RYML_NOEXCEPT
Definition tree.hpp:692

◆ lookup_path_or_modify() [2/2]

id_type c4::yml::Tree::lookup_path_or_modify ( Tree const * src,
id_type src_node,
csubstr path,
id_type start = NONE )

defaulted lookup: lookup path; if the lookup fails, recursively modify the tree so that the corresponding lookup_path() would return the branch src_node (from the tree src).

See also
lookup_path()

Definition at line 1597 of file tree.cpp.

1598{
1599 id_type target = _lookup_path_or_create(path, start);
1600 merge_with(src, src_node, target);
1601 return target;
1602}

Member Data Documentation

◆ m_buf

NodeData* c4::yml::Tree::m_buf

Definition at line 1688 of file tree.hpp.

Referenced by Tree(), _p(), _p(), clear(), get(), get(), id(), and reserve().

◆ m_cap

◆ m_size

id_type c4::yml::Tree::m_size

Definition at line 1690 of file tree.hpp.

Referenced by Tree(), clear(), empty(), reserve(), resolve(), resolve(), root_id(), root_id_maybe(), size(), and slack().

◆ m_free_head

id_type c4::yml::Tree::m_free_head

Definition at line 1692 of file tree.hpp.

Referenced by Tree(), clear(), and set_root_as_stream().

◆ m_free_tail

id_type c4::yml::Tree::m_free_tail

Definition at line 1693 of file tree.hpp.

Referenced by Tree(), and clear().

◆ m_first_unused

id_type c4::yml::Tree::m_first_unused

Definition at line 1694 of file tree.hpp.

Referenced by Tree(), _p(), _p(), clear(), reserve(), and set_root_as_stream().

◆ m_arena

◆ m_arena_pos

size_t c4::yml::Tree::m_arena_pos

◆ m_callbacks

◆ m_tag_directives


The documentation for this class was generated from the following files:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/tree.hpp
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/tree.cpp