ddn.data.cdm.traversal
CDM Traversal Utilities
This module provides utilities for traversing and querying CDM trees. These functions work with the CDM structures created by any format parser (JSON5, SDL, etc.).
Copyright
Types 1
Depth-first traversal range for CDM trees.
Iterates over all nodes in a CDM tree starting from a root node. For OBJECT nodes, member values are traversed via CdmMember.value pointers. For ARRAY and TAG nodes, children are traversed directly. Leaf nodes (NULL, BOOL, INTEGER, FLOAT, STRING, etc.) are visited but produce no further descent.
The root node and all its descendants must remain valid (not moved, resized, or deallocated) for the entire duration of the traversal. Using the traverser after the root node goes out of scope results in undefined behavior.
Safe usage pattern:
auto root = CdmNode.emptyObject();
// ... populate root ...
foreach (node; traverse(root)) {
// Process node - root must stay in scope here
}
// root can now go out of scopeUnsafe usage (DO NOT DO THIS):
Traverser t;
{
auto root = CdmNode.emptyObject();
t = Traverser(root); // stores pointer to root
} // root goes out of scope - t now has dangling pointer!
foreach (node; t) { ... } // UNDEFINED BEHAVIORCdmNode *[] stackStack of node pointers for depth-first iterationFunctions 5
auto findAll(ref CdmNode root, bool delegate(ref CdmNode) @safe pred) @safeFinds all nodes in a CDM tree matching a predicate.CdmNode * findFirst(ref CdmNode root, bool delegate(ref CdmNode) @safe pred) @safeFinds the first node in a CDM tree matching a predicate.auto findByType(ref CdmNode root, CdmNode.Type type) @safeFinds all nodes of a specific type in a CDM tree.