IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 14, 2007, 2:38:13 PM (19 years ago)
Author:
jhoblitt
Message:

add pxNodePrint()
add pxTreeCrawl()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pxtree.c

    r14489 r14494  
    5757    return node;
    5858}
     59
     60
     61void pxNodePrint(FILE *stream, pxNode *node)
     62{
     63    fprintf(stream, "node name: %s\n", node->name);
     64    fprintf(stream, "node parent's name: %s\n", node->parent
     65                                              ?  node->parent->name
     66                                              : NULL);
     67    psListIterator *iter = psListIteratorAlloc(node->children, 0, false);                                         
     68    pxNode *child = NULL;
     69    while ((child = psListGetAndIncrement(iter))) {
     70        fprintf(stream, "node child's name: %s\n", child->name);
     71    }
     72    psFree(iter);
     73}
     74
     75
     76bool pxTreeCrawl(pxNode *node, pxNodeFunc func)
     77{
     78    // if func() returns false, stop
     79    if (!func(node)) {
     80        return false;
     81    }
     82
     83    psListIterator *iter = psListIteratorAlloc(node->children, 0, false);                                         
     84    pxNode *child = NULL;
     85    while ((child = psListGetAndIncrement(iter))) {
     86        // if func() returns false, pxTreeCrawl() well return false, and we
     87        // should stop
     88        if (!pxTreeCrawl(child, func)) {
     89            return false;
     90        }
     91    }
     92    psFree(iter);
     93
     94    return true;
     95}
Note: See TracChangeset for help on using the changeset viewer.