Adding a Tree to its Parent

Beta documentation : This document has not received a full technical review and therefore might contain inaccuracies.

To be of any use, a CFTree object must be inserted into the tree structure; it must be placed in a hierarchical relationship to other CFTree objects. To do this, you must use of the follow CFTree functions to make the object a child or sibling tree in relation to some other tree:

  • CFTreeAppendChild
  • CFTreePrependChild
  • CFTreeInsertSibling
  • Listing 13 shows a child tree being appended to its parent's list of children.

    Listing 13 Adding a child CFTree to its parent
    {/* assume anAddress and curTree already exist */ CFTreeRef child = FindTreeChildWithAddress(curTree, anAddress); if (NULL == child) { CFTreeContext ctx; child = CreateMyTree(CFGetAllocator(curTree)); CFTreeGetContext(child, &ctx); ((MyTreeInfo *)ctx.info)->address = anAddress]; CFTreeAppendChild(curTree, child); CFRelease(child); }

    The code example also illustrates another aspect of the CFTree programming interface. Sometimes you may need to modify the program-defined data associated with a CFTree object that is already created. To do this, call the CFTreeGetContext function on that object to get the tree's context. Once you have this structure, you can access the program-defined data through the info pointer.


    © 1999 Apple Computer, Inc. – (Last Updated 07 September 99)