IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15187


Ignore:
Timestamp:
Oct 3, 2007, 12:53:47 PM (19 years ago)
Author:
jhoblitt
Message:

change pxNodeAlloc() to only create nodes and not try to link them
add pxNodeAddChild() and pxNodeAddParent()

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

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

    r14589 r15187  
    3434}
    3535
    36 pxNode *pxNodeAlloc(const char *name, pxNode *parent)
     36pxNode *pxNodeAlloc(const char *name)
    3737{
    3838    PS_ASSERT_PTR_NON_NULL(name, NULL);
     
    4141
    4242    node->name = psStringCopy(name);
    43 
    44     // parent == NULL basically means that this is the root node
    45     if (!parent) {
    46         node->parent = NULL;
    47     } else {
    48         // add this node to it's parent's children list
    49         psListAdd(parent->children, PS_LIST_TAIL, node);
    50         node->parent = psMemIncrRefCounter(parent);
    51     }
    52 
     43    node->parent = NULL;
    5344    node->children = psListAlloc(NULL);
    5445
     
    5849}
    5950
     51pxNode *pxNodeAddParent(pxNode *node, pxNode *parent)
     52{
     53    // add this node to it's parent's children list
     54    psListAdd(parent->children, PS_LIST_TAIL, node);
     55    // and set the parent pointer
     56    node->parent = psMemIncrRefCounter(parent);
     57
     58    return node;
     59}
     60
     61pxNode *pxNodeAddChild(pxNode *node, pxNode *child)
     62{
     63    // add the child node to this nodes list of children
     64    psListAdd(node->children, PS_LIST_TAIL, child);
     65    // if the child already has a parent, release the ref count
     66    if (child->parent) {
     67        psMemDecrRefCounter(child->parent);
     68    }
     69    // [re]parent the child
     70    child->parent = psMemIncrRefCounter(node);
     71
     72    return node;
     73}
    6074
    6175void pxNodePrint(FILE *stream, pxNode *node)
     
    145159            continue;
    146160        }
    147         pxNode *parent = psHashLookup(nodeNames, item->data.str);
    148         pxNode *node = pxNodeAlloc(item->name, parent);
    149         psHashAdd(nodeNames, item->name, node);
     161
     162        // try to find a node with this name
     163        pxNode *node = psHashLookup(nodeNames, item->name);
     164        if (!node) {
     165            // create a new node with this name
     166            node = pxNodeAlloc(item->name);
     167            // add it to the hash of nodes
     168            psHashAdd(nodeNames, item->name, node);
     169        }
     170
     171        // does this node declare a child?
     172        if (item->data.str) {
     173            // try to find a node with this name
     174            pxNode *child = psHashLookup(nodeNames, item->data.str);
     175            if (!child ) {
     176                // create a new node with this name
     177                child = pxNodeAlloc(item->data.str);
     178                // add it to the hash of nodes
     179                psHashAdd(nodeNames, item->data.str, child);
     180            }
     181            pxNodeAddChild(node, child);
     182        }
     183
    150184        psFree(node);
    151185    }
  • trunk/ippTools/src/pxtree.h

    r14589 r15187  
    3636
    3737pxNode *pxNodeAlloc(
    38     const char *name,
    39     pxNode  *parent
     38    const char *name
    4039) PS_ATTR_MALLOC;
     40
     41pxNode *pxNodeAddParent(pxNode *node, pxNode *parent);
     42pxNode *pxNodeAddChild(pxNode *node, pxNode *child);
    4143
    4244void pxNodePrint(
     
    5961pxNode *pxTreeFromMetadata(psMetadata *md);
    6062
    61 
    62 /*
    63 bool pxNodeAddChild(
    64     pxNode  *parent,
    65     pxNode  *child
    66 );
    67 */
    68 
    6963#endif // PXTREE_H
Note: See TracChangeset for help on using the changeset viewer.