next up previous contents
Next: References: Up: The New Run Time Previous: Construct Graph G2:

Construct the Complex Graph:

Finally, we construct a graph of 2 nodes and one edge using graph G1 and graph G2 as the node data.

  //construct complex graph of G1, G2 
  if(T->T==NULL){
    printf("Building the XGraph object.\n");
    T->T = new Graph(DataFloat,A,
                     T->radius,T->center,        //node circle
                     T->foreground,              //fg
                     T->background,              //bg
                     graph_colors,               //graph colors
                     T->display,                 //graphics
                     T->drawable,
                     T->pixmap,
                     T->pixmap2,
                     T->gc);          
    }
  float myedge = 5.0;
  cout << "Construct node G1 " << endl;
  Gnode *n1 = T->T->addNode("Graph1",40.0,200.0,G1);
  cout << "construct node G2 " << endl;
  Gnode *n2 = T->T->addNode("Graph2",120.0,100.0,G2);
  cout << "construct edge from G1 to G2 " << endl;
  T->T->addEdge(n1,n2,450.0,&myedge);

This constructs a graph in the usual way using the ACCESS_GRAPH *A class object pointer in the constructor.

We output this graph as usual:

  cout << T->T << endl;

and what is really gratifying about all of our hard work is that all of the proper display methods are called and we see

Building the Graph object.
Construct node G1 
Cast incoming data to proper type
Construct a new Graph
In Graph copy constructor
construct node G2 
Cast incoming data to proper type
Construct a new Graph
In Graph copy constructor
construct edge from G1 to G2 
Graph Object Constructed.

Number of Nodes in the Graph is 2
Number of Edges in the Graph is 1

Graph: 
Nodes:    <===now we display each node using each node's show method
entering node loop 
node 1    <===here we should print out G2 using the show method for G2
  Graph2
  Graph:
...  
...usual G2 display appears here just as we listed it above... 
...
End Graph

node 2
  Graph1  <===here we should print out G2 using the show method for G2
Graph
...  
...usual G1 display appears here just as we listed it above... 
...
End Graph

Edges:
entering edge loop 
edge 1
    Graph1-----(450)---> Graph2 5 <===here we display the complex graph
End Graph

This is a really neat example of how nice the payoff from the object oriented design can be!


Jim Peterson
1999-05-17