next up previous contents
Next: GnodePtrBagIter Constructor: Up: The Graph Class: Previous: GedgePtrBagLink Constructor

Find a Node:

The following code defines the agent which will find a node based on the node's name.

Gnode *Graph::findNode(const char *nodeName)
{
  for(GnodePtrBagIter it(d_nodes); it; ++it){
    if(0==strcmp(it()->name(),nodeName)){
      return it();
      }
    }
  return 0;
}

The function uses the node iterator, GnodePtrBagIter. The nodes are traversed and each node's name is compared to the argument given to the agent. If a match is found, a pointer to that node is returned. Otherwise, 0 (NULL) is returned. The iterator is set up using the constructor from the GnodePtrBagIter class.



 

Jim Peterson
1999-05-17