The CFTree type has several functions that obtain child trees. Because sibling trees are in sequential order, you typically use only two of these methods to traverse the child trees of one parent,
CFTreeGetFirstChild
and
CFTreeGetNextSibling
. Listing 14 shows how you do this.
Listing 14 Traversing the child trees of a parent tree
static CFTreeRef FindTreeChildWithAddress(CFTreeRef tree, UInt32 addr) { CFTreeRef curChild = CFTreeGetFirstChild(tree); for (; curChild; curChild = CFTreeGetNextSibling(curChild)) { CFTreeContext ctx; CFTreeGetContext(tree, &ctx); if (((MyTreeInfo *)ctx.info)->address == addr) { return curChild; } } return NULL; }
Not all CFTree functions act on or return child trees. The
CFTreeGetParent
function, for example, obtains the parent tree of a given tree. The
CFTreeFindRoot
function obtains the root CFTree object of the current tree structure--that is, the tree of the structure that has no parent tree.