|
rapidyaml
0.10.0
parse and emit YAML, and do it fast
|
Reusable object to resolve references/aliases in a Tree. More...
#include <reference_resolver.hpp>
Public Member Functions | |
| ReferenceResolver ()=default | |
| void | resolve (Tree *tree, bool clear_anchors=true) |
| Resolve references: for each reference, look for a matching anchor, and copy its contents to the ref node. More... | |
Reusable object to resolve references/aliases in a Tree.
Definition at line 16 of file reference_resolver.hpp.
|
default |
| void c4::yml::ReferenceResolver::resolve | ( | Tree * | tree, |
| bool | clear_anchors = true |
||
| ) |
Resolve references: for each reference, look for a matching anchor, and copy its contents to the ref node.
tree the subject tree
clear_anchors whether to clear existing anchors after resolving
This method first does a full traversal of the tree to gather all anchors and references in a separate collection, then it goes through that collection to locate the names, which it does by obeying the YAML standard diktat that "an alias node refers to the most recent node in the serialization having the specified anchor"
So, depending on the number of anchor/alias nodes, this is a potentially expensive operation, with a best-case linear complexity (from the initial traversal). This potential cost is one of the reasons for requiring an explicit call.
The Tree has an Tree::resolve() overload set forwarding here. Previously this operation was done there, using a discarded object; using this separate class offers opportunity for reuse of the object.