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.).

Types 1

private structTraverser

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.

Lifetime Warning: This traverser stores pointers to nodes in the tree.

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 scope

Unsafe 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 BEHAVIOR

Fields
CdmNode *[] stackStack of node pointers for depth-first iteration
Methods
CdmNode * front() pure nothrow @nogc @trustedReturns the current front element of the traversal.
void popFront() @trustedAdvances the traversal to the next node.
bool empty() const pure nothrow @nogc @safeChecks whether the traversal has been exhausted.
Constructors
this(ref CdmNode root)Initializes the traverser with a root node.

Functions 5

fnauto traverse(ref CdmNode node) @trustedReturns a depth-first traversal range over a CDM tree.
fnauto findAll(ref CdmNode root, bool delegate(ref CdmNode) @safe pred) @safeFinds all nodes in a CDM tree matching a predicate.
fnCdmNode * findFirst(ref CdmNode root, bool delegate(ref CdmNode) @safe pred) @safeFinds the first node in a CDM tree matching a predicate.
fnauto findByType(ref CdmNode root, CdmNode.Type type) @safeFinds all nodes of a specific type in a CDM tree.
fnauto findByKey(ref CdmNode root, string key) @safeFinds all object-like nodes that contain a specific key.