DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
The C++ Graph Classes: A Tutorial - Graph(C++) and Graph_alg(C++)

Vertex Constructors and Destructors

The following Vertex constructor is defined for both the generic and user-derived Vertex types:

       Vertex();

which allows, for a Graph g, declarations such as:

       Vertex v;
       g.insert(new Vertex());

When a Vertex is destroyed, it is removed from any Graphs that still contain it and from any Edges that use it for a source or destination (such Edges are also removed from any Graphs containing them). Note that when a Vertex is removed from an Edge, that Edge becomes ill-defined but is not destroyed: it should not be passed to any Graph package function (although this condition is not checked).

Again, the parameterless constructor can be enhanced with user data that needs to be initialized, such as we did in the section, ``Using the Graph Classes to Create Objects'', in the definition of Module.

In our manufacturing example, where the Vertex constructor took a String argument for the identifier, we could avoid creating a (tediously long) list of variable names m1, m2, etc. by dynamically declaring the Modules:

       .
       .
       .
       w.insert(new Module("A"));
       etc.
       .
       .
       .

Our only problem here is that we've currently left ourselves no handle with which to access a given Module (except through iteration). We can enhance this approach by creating a Map entry for each Module as part of the Module constructor. The following code accomplishes this:

       .
       .
       .
       typedef Module* Mptr;
       #define mod(s) (Module::m[s])
   

// replace the former definition of // class Module with this text: class Module: public Vertex { public: static Map<String,Mptr> m; // new Map String id; Module(String s) : Vertex(), id(s) { m[s] = this; } // added Map info derivedVertex(Product,Module,Transport_Time) }; Map<String,Mptr> Module::m; . . .

Then, when we dynamically declare Module ``B'', for instance, we will automatically create mod("B"):

       .
       .
       .
       widget.insert(new Module("B"));
       widget.remove(mod("B"));
       .
       .
       .

A last point about Vertex constructors: a Vertex ``copy'' constructor is not defined, since it is debatable whether the semantics of such a copy should include a copy of the attached Edges.


Next topic: Vertex Operators
Previous topic: Graph Subgraph Creation

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005