Changeset 15187
- Timestamp:
- Oct 3, 2007, 12:53:47 PM (19 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pxtree.c
r14589 r15187 34 34 } 35 35 36 pxNode *pxNodeAlloc(const char *name , pxNode *parent)36 pxNode *pxNodeAlloc(const char *name) 37 37 { 38 38 PS_ASSERT_PTR_NON_NULL(name, NULL); … … 41 41 42 42 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; 53 44 node->children = psListAlloc(NULL); 54 45 … … 58 49 } 59 50 51 pxNode *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 61 pxNode *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 } 60 74 61 75 void pxNodePrint(FILE *stream, pxNode *node) … … 145 159 continue; 146 160 } 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 150 184 psFree(node); 151 185 } -
trunk/ippTools/src/pxtree.h
r14589 r15187 36 36 37 37 pxNode *pxNodeAlloc( 38 const char *name, 39 pxNode *parent 38 const char *name 40 39 ) PS_ATTR_MALLOC; 40 41 pxNode *pxNodeAddParent(pxNode *node, pxNode *parent); 42 pxNode *pxNodeAddChild(pxNode *node, pxNode *child); 41 43 42 44 void pxNodePrint( … … 59 61 pxNode *pxTreeFromMetadata(psMetadata *md); 60 62 61 62 /*63 bool pxNodeAddChild(64 pxNode *parent,65 pxNode *child66 );67 */68 69 63 #endif // PXTREE_H
Note:
See TracChangeset
for help on using the changeset viewer.
