This example function illustrates how to count the number of  node types  with in pfNode and its sub tree

  • How to test if a pfNode is of a specific pfIsOfType using
  • How to get the number of pfGeoSets in a pfGeode
  • How to get the number of children for a pfNode using pfGetNumChildren
  • Show how to traverse a pfNode tree using recursion
  • How to test if a pfNode is a pfGeode node type
  • How to test if a pfNode is a pfGroup node type
  • How to test if a pfNode is a pfDCS node type
  • How to test if a pfNode is a pfSCS node type
  • How to test if a pfNode is a pfSeq node type
  • How to test if a pfNode is a pfLod  node type
  • How to test if a pfNode is a pfBoard node type

 

 
   
 

 

 
 
 
 

 

#include "pf.h"          // Required for the standard Performer classes
#include "pfutil.h"      // Required for pfFindNode

 

void

getpfNodeCountsInSubtree( pfNode *node ) {

// ########################################################

// #

// # Public Function

// #

// #    Example funcion to show how to get the number of

// # of different pfNode types

// #

// ########################################################

 

    //

    // Sanity check we need an node

    //

    if( node == NULL )

       return;

 

    int numNodes = 0;

    numNodes = getNumberPfNodeTypes( node, pfGetNodeClassType(), numNodes );

 

    int numGeodes = 0;

    numGeodes = getNumberPfNodeTypes( node, pfGetGeodeClassType(), numGeodes );

 

    int numGroups = 0;

    numGroups = getNumberPfNodeTypes( node, pfGetGroupClassType(), numGroups );

 

    int numDCS = 0;

    numDCS = getNumberPfNodeTypes( node, pfGetDCSClassType(), numDCS );

 

    int numSCS = 0;

    numSCS = getNumberPfNodeTypes( node, pfGetSCSClassType(), numSCS );

 

    int numSeq = 0;

    numSeq = getNumberPfNodeTypes( node, pfGetSeqClassType(), numSeq );

 

    int numLods = 0;

    numLods = getNumberPfNodeTypes( node, pfGetLODClassType(), numLods );

 

    int numBboard = 0;

    numBboard = getNumberPfNodeTypes( node, pfGetBboardClassType(), numBboard );

 

 

} // getpfNodeCountsInSubtree

 

int

getNumberPfNodeTypes( pfNode *node, pfType *nodeType, int nodeTotal ) {

// ##################################################################

// #

// # Public Function

// #

// #    A simple Recursive function that will traverse the given

// # nodes tree and count all the pfNodeTypes requested

// #

// # Note this does not supported pfGeoSet see specic example

// #      counting pfGeoSets

// #

// ##################################################################

 

    

    //

    //  Sanity check we need a Node

    //

    if( node == NULL )

        return nodeTotal;

 

    //  

    //  

    //

    if( pfIsOfType( node, nodeType )) {

            nodeTotal++;

        }

    

        //

        // Cycle through the children for this node

        //

        int numChildren = 0;

        

        

        //

        // Need to catch pfGeodes as they have no children and

        // will cause a crash if pfGetNumChildren is called

        //

        if( !pfIsOfType( node,  pfGetGeodeClassType()) )

            numChildren = pfGetNumChildren ( node );

 

 

        for ( int idx = 0; idx < numChildren; idx++ ) {

        

            //

            // Get the child node and recurse in to them

            //

            pfNode* childNode = pfGetChild( node, idx );

 

            nodeTotal = getNumberPfNodeTypes( childNode,nodeType, nodeTotal );

            

            }

        }

    

return nodeTotal;

 

} // getNumberPfNodeType

 

 

 

 
 

 

 

Copyright 2004 Gordon Tomlinson  All Rights Reserved.

All logos, trademarks and copyrights in this site are property of their respective owner.