71a1780f78585a02f7a7a4b04dbb18b79f7c2370
[occt.git] / src / PCollection / PCollection_HDirectedGraph.cdl
1 -- Created on: 1991-04-24
2 -- Created by: Denis PASCAL
3 -- Copyright (c) 1991-1999 Matra Datavision
4 -- Copyright (c) 1999-2014 OPEN CASCADE SAS
5 --
6 -- This file is part of Open CASCADE Technology software library.
7 --
8 -- This library is free software; you can redistribute it and/or modify it under
9 -- the terms of the GNU Lesser General Public License version 2.1 as published
10 -- by the Free Software Foundation, with special exception defined in the file
11 -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 -- distribution for complete text of the license and disclaimer of any warranty.
13 --
14 -- Alternatively, this file may be used under the terms of Open CASCADE
15 -- commercial license or contractual agreement.
16
17 -- Revised:      Mireille MERCIEN
18
19
20 generic class HDirectedGraph from PCollection (
21                Item as Storable ; 
22                Attribute as Storable)
23
24      ---Purpose: Definition of a generic  directed graph for a type of
25      -- Item associated to a vertex, and  a type of Attribute
26      -- associated to an   Edge.    A Directed   Graph   is a
27      -- collection that includes a set of Vertices  and a set
28      -- of Edges.  A vertex, also called a  "Node", forms the
29      -- basic  structural element  of  the graph.  Each edge,
30      -- also called an "Arc" defines an oriented link between
31      -- two vertices.  In the scheme A->B, vertex A is called
32      -- the SOURCE  of the link, B  its DESTINATION, and B is
33      -- ADJACENT to A.  If there is no edge  which destinates
34      -- to a vertex, this vertex is a ROOT of the graph.   If
35      -- there is no edge which originates from a vertex, this
36      -- vertex is a LEAF of the graph.
37
38     ---Keywords: SOURCE vertex,  DESTINATION Vertex, ROOT vertex, LEAF
39     --  vertex, ADJACENT vertex. Depth-first search, breadth, first Search.
40
41     ---References: Software Components with ADA (The Benjamin/Cummings
42     --    Company, Inc.  1986).
43
44
45
46 inherits Persistent 
47 raises NoSuchObject from Standard,
48        NoMoreObject from Standard
49
50
51     class Edge inherits Persistent
52     
53         ---Purpose: Defines nested class Edge of a Directed Graph.
54         -- An Edge is an oriented link between  two vertices.
55
56     raises NoMoreObject from Standard ,
57            NoSuchObject from Standard
58     is
59
60         Create (Source,Destination : Vertex; Value : Attribute) 
61             ---Purpose: Creates an oriented link  between <source> and
62             -- <destination> with an associated attribute. To
63             -- be  used only   by  DirectedGraph  methods  to
64             -- create and add an edge to a given graph.
65         returns mutable Edge; 
66
67         GetAttribute (me) 
68             ---Level: Public
69             ---Purpose: Returns attribute associated to <me>.
70             returns Attribute;
71
72         SetAttribute (me : mutable; Value : Attribute)
73             ---Level: Internal
74             ---Purpose: To associate an attribute to <me>.
75         is private;
76
77         Source (me) 
78             ---Level: Public
79             ---Purpose: Returns the vertex which originates from <me>.
80             returns mutable Vertex;
81             
82         SetSource (me :mutable; V: Vertex) 
83             ---Level: Internal
84             ---Purpose: Sets the vertex which originates from <me>.
85         is private;
86
87         Destination (me) 
88             ---Level: Public
89             ---Purpose: Returns the vertex which destinates to <me>.
90             returns mutable Vertex;
91
92         SetDestination (me :mutable ; V: Vertex) 
93             ---Level: Internal
94             ---Purpose: Sets the vertex which destinates to <me>.
95             is private;
96
97         Reverse (me : mutable);
98             ---Level: Public
99             ---Purpose: Reverse  the orientation of   <me>.
100             -- The source vertex becomes the  destination vertex, and
101             -- the destination becomes the source.
102
103         IsLoop (me) returns Boolean from Standard;
104             ---Level: Public
105             ---Purpose: Returns True if the fields <MyDestination> and 
106             -- <Mysource> are equal.
107  
108     fields
109         MyAttribute   : Attribute;
110         MySource      : Vertex;
111         MyDestination : Vertex;
112
113     friends class HDirectedGraph from PCollection,
114             class Vertex        from PCollection 
115     
116     end;
117
118     class SetOfEdge instantiates HSet from PCollection(Edge);
119         ---Purpose: Defines nested class SetOfEdge used  as  field of
120         -- Vertex and DirectedGraph.
121
122     class SetOfVertex instantiates HSet from PCollection(Vertex);
123         ---Purpose: Defines nested class SetOfVertex used as field of a
124         -- DirectedGraph.
125
126     class StackOfVertex instantiates HStack from PCollection(Vertex);
127         ---Purpose: Defines nested class StackOfVertex used  as  field of
128         -- DepthFirstIterator class.
129
130
131     class QueueOfVertex instantiates HQueue from PCollection(Vertex);
132         ---Purpose: Defines nested class QueueOfVertex used  as  field of
133         -- BreadthFirstIterator.
134
135     class FrontEdgesIterator    
136         ---Purpose: Defines nested class  FrontEdgesIterator, to  visit
137         -- every edge that originates from a given vertex.
138
139     raises NoMoreObject from Standard ,
140            NoSuchObject from Standard
141     is
142
143         Create (aVertex : Vertex) returns FrontEdgesIterator;
144
145         More (me) 
146             ---Level: Public
147             ---Purpose: Returns TRUE if there are other edges.
148         returns Boolean from Standard; 
149
150         Next (me : in out) raises NoMoreObject from Standard;  
151             ---Level: Public
152             ---Purpose: Set the iterator to the next Edge.
153
154         Value (me) 
155             ---Level: Public
156             ---Purpose: Returns the edge value for the current
157             -- position of the iterator.
158         returns any Edge
159         raises NoSuchObject from Standard;
160
161         Clear (me : in out);
162             ---Level: Public
163             ---Purpose: To clear the iterator before having visiting all edges.
164
165     fields
166         MyEdgeIterator : SetIteratorOfSetOfEdge;
167         HasMore        : Boolean from Standard;    
168     end;
169         
170     class BackEdgesIterator 
171         ---Purpose: Defines  nested class BackEdgesIterator, to  visit
172         -- every edge that destinates to a given vertex.
173
174     raises NoMoreObject from Standard ,
175            NoSuchObject from Standard
176     is
177         Create (aVertex : Vertex) returns BackEdgesIterator;
178
179         More (me) 
180             ---Level: Public
181             ---Purpose: Returns TRUE if there are other edges.
182         returns Boolean from Standard;
183         
184         Next (me : in out) raises NoMoreObject from Standard; 
185             ---Level: Public
186             ---Purpose: Sets the iterator to the next edge.
187         
188         Value (me) 
189             ---Level: Public
190             ---Purpose: Returns   the  edge value   for   the  current
191             -- position of the iterator.
192         returns any Edge
193         raises NoSuchObject from Standard;     
194         
195         Clear (me : in out);
196             ---Level: Public
197             ---Purpose: To  clear the  iterator before having visiting all edges.
198
199     fields
200         MyEdgeIterator : SetIteratorOfSetOfEdge;
201         HasMore        : Boolean from Standard;
202     end;
203
204     class DepthFirstIterator
205         ---Purpose: Defines nested class  DepthFirstIterator, to  visit
206         -- every vertex that depends  of a given  one.  Depth
207         -- First Search  is functionnally the equivalent of a
208         -- preorder tree   traversal.  We start  at  a  given
209         -- Vertex  V  and   recursively  visit  all  adjacent
210         -- unvisited Vertices.
211
212     raises NoMoreObject from Standard ,
213            NoSuchObject from Standard
214     is
215     
216         Create (aVertex : Vertex) returns DepthFirstIterator;
217
218         More (me) 
219             ---Level: Public
220             ---Purpose: Returns TRUE if there are other vertices.
221         returns Boolean from Standard;
222
223         Next (me : in out) raises NoMoreObject from Standard; 
224             ---Level: Public
225             ---Purpose: Sets the iterator to the next vertex.
226
227         Value (me)  
228             ---Level: Public
229             ---Purpose: Returns  the vertex  value  for  the   current
230             -- position of the iterator.
231         returns any Vertex
232         raises NoSuchObject from Standard;
233         
234         Clear (me : in out);
235             ---Level: Public
236             ---Purpose: To  clear the  iterator before having visiting
237             -- all vertices.
238
239     fields
240         Visited : SetOfVertex;
241         Ready   : StackOfVertex;
242         HasMore : Boolean from Standard;
243     end;
244
245     class BreadthFirstIterator
246         ---Purpose: Defines nested class BreadthFirstIterator, to visit
247         -- every vertex that depends of a given one. We start
248         -- at    a  given vertex  V,  visit  all its adjacent
249         -- vertices, and then recursively visit the unvisited
250         -- adjacent vertices of these previous ones.
251
252     raises NoMoreObject from Standard ,
253            NoSuchObject from Standard
254     is
255
256         Create (aVertex : Vertex) returns BreadthFirstIterator;
257
258         More (me) 
259             ---Level: Public
260             ---Purpose: Returns TRUE if there are other vertices.
261         returns Boolean from Standard;
262         
263         Next (me : in out) raises NoMoreObject from Standard; 
264             ---Level: Public
265             ---Purpose: Sets the iterator to the next vertex.
266
267         Value (me) 
268             ---Level: Public
269             ---Purpose: Returns  the  vertex  value for  the   current
270             -- position of the iterator.
271         returns any Vertex
272         raises NoSuchObject from Standard;
273
274         Clear (me : in out);
275             ---Level: Public
276             ---Purpose: To  clear the  iterator before having visiting
277             -- all vertices.
278
279     fields
280         Visited : SetOfVertex;
281         Ready   : QueueOfVertex;
282         HasMore : Boolean from Standard;
283     end;
284
285     class AdjacentVerticesIterator 
286
287         ---Purpose: Defines nested class AdjacentVerticesIterator, to
288         -- visit  every  adjacent vertex    of a   given  one
289         -- (Destination vertices of its front edges).
290
291     raises NoMoreObject from Standard ,
292            NoSuchObject from Standard
293     is
294         Create (aVertex : Vertex) returns AdjacentVerticesIterator;
295
296         More (me) 
297             ---Level: Public
298             ---Purpose: Returns TRUE if there are other vertices.
299         returns Boolean from Standard;
300
301         Next (me : in out) raises NoMoreObject from Standard; 
302             ---Level: Public
303             ---Purpose: Sets the iterator to the next vertex.
304
305         Value (me) 
306             ---Level: Public
307             ---Purpose: Returns the  vertex  value for the current
308             -- position of the iterator.
309         returns any Vertex
310         raises NoSuchObject from Standard;
311
312         Clear (me : in out);
313             ---Level: Public
314             ---Purpose: To clear the iterator before having visiting all vertices.
315
316     fields
317         MyEdgeIterator : SetIteratorOfSetOfEdge;
318         HasMore        : Boolean from Standard;
319     end;
320
321 ----------------------- Class Vertex ----------------------------------
322
323     class Vertex inherits Persistent
324         ---Purpose: Defines nested class vertex of a DirectedGraph. The
325         -- Vertex is the basic element of a graph.
326   
327     raises NoMoreObject from Standard ,
328            NoSuchObject from Standard
329     is
330
331         Create (Value : Item ; InGraph : HDirectedGraph) 
332             ---Purpose: Creates a vertex  with an  associated item. To
333             -- be  used  only  by   DirectedGraph methods  to
334             -- create and add a vertex to a given  graph.
335         returns mutable Vertex;
336
337         GetItem (me) 
338             ---Level: Public
339             ---Purpose: Returns item associated to <me>.
340             returns any Item;
341
342         SetItem (me : mutable; value : Item)
343             ---Level: Internal
344             ---Purpose: Associates an item to <me>.
345             is private;
346
347         GetGraph (me) 
348             ---Level: Public
349             ---Purpose: Returns the HDirectedGraph which owns <me>.
350             returns HDirectedGraph;
351
352         AddFrontEdge (me : mutable; anEdge : Edge) 
353             ---Level: Internal
354             ---Purpose: To add an edge that destinates to <me>. 
355             -- To be used only by editing methods of a DirectedGraph. 
356             -- Returns  False  if  the edge already exists.
357         returns Boolean from Standard
358         is private;
359
360         RemoveFrontEdge (me : mutable; anEdge : Edge)
361             ---Level: Internal
362             ---Purpose: To remove  an edge that  originates from <me>.
363             -- To be   used  only  by  editing  methods  of a DirectedGraph. 
364             -- An  exception is  raised  if <anEdge> doesn't belong to 
365             -- myFrontEdges field.
366         raises NoSuchObject from Standard
367         is private;
368     
369         NbFrontEdges (me) returns Integer;
370             ---Level: Public
371             ---Purpose: Returns the number of edges which originates from <me>.
372
373         GetFrontEdges (me) 
374             ---Level: Public
375             ---Purpose: Returns "myFrontEdges" Field for Iterator.
376         returns SetOfEdge 
377         is private;
378     
379         AddBackEdge (me : mutable; anEdge : Edge) 
380             ---Level: Internal
381             ---Purpose: To add an edge that destinates  to <me>. To be
382             -- used     only   by   editing    methods  of  a
383             -- DirectedGraph,  to    update     it      after
384             -- modifications.   Returns   False if the   edge already exists.
385         returns Boolean from Standard
386         is private;
387
388         RemoveBackEdge (me : mutable; anEdge : Edge)
389             ---Level: Internal
390             ---Purpose: To remove an edge  that destinates to <me>. To
391             -- be   used   only by   editing   methods   of a
392             -- DirectedGraph,      to     update    it  after
393             -- modifications.   An   exception  is raised  if
394             -- <anEdge> doesn't belong to myBackEdges field.
395         raises NoSuchObject from Standard
396         is private;
397
398         NbBackEdges (me) 
399             ---Level: Public
400             ---Purpose: Returns the number   of  edge which  destinates to <me>.
401             returns Integer from Standard;
402
403         GetBackEdges (me)
404             ---Level: Internal
405             ---Purpose: Returns "myBackEdges" field for Iterator.
406         returns SetOfEdge
407         is private;
408
409         IsRoot (me) 
410             ---Level: Public
411             ---Purpose: Returns TRUE if NbBackEdges = 0.
412         returns Boolean from Standard;
413
414         IsLeaf (me) 
415             ---Level: Public
416             ---Purpose: Returns TRUE if NbFrontEdges = 0.
417         returns Boolean from Standard;
418
419         IsDestination (me; aVertex : Vertex) 
420             ---Level: Public
421             ---Purpose: Returns   TRUE if   it  exists  an  edge which
422             -- originates     from <me>   and  destinates  to <aVertex>.
423         returns Boolean from Standard;
424
425         IsSource (me; aVertex : Vertex) 
426             ---Level: Public
427             ---Purpose: Returns  TRUE  if  it   exists an  edge  which
428             -- originates  from  <aVertex>  and destinates to <me>.
429         returns Boolean from Standard;
430         
431     fields
432         MyItem       : Item;
433         MyGraph      : HDirectedGraph;
434         MyFrontEdges : SetOfEdge;
435         MyBackEdges  : SetOfEdge;
436
437     friends class HDirectedGraph            from PCollection,
438             class Edge                     from PCollection,
439             class BackEdgesIterator        from PCollection,
440             class FrontEdgesIterator       from PCollection,
441             class DepthFirstIterator       from PCollection,
442             class BreadthFirstIterator     from PCollection,
443             class AdjacentVerticesIterator from PCollection                   
444     end;
445  
446
447     class VerticesIterator  
448         ---Purpose: Defines nested  class  VerticesIterator,   to visit
449         -- every vertex of a given directed graph.
450
451     raises NoMoreObject from Standard ,
452            NoSuchObject from Standard
453     is
454         Create (aGraph : HDirectedGraph) returns VerticesIterator;
455
456         More (me) 
457             ---Level: Public
458             ---Purpose: Returns  TRUE  if  there are other vertices.
459         returns Boolean from Standard;
460
461         Next (me : in out) raises NoMoreObject from Standard; 
462             ---Level: Public
463             ---Purpose: Sets the iterator to the next vertex.
464
465         Value (me) 
466             ---Level: Public
467             ---Purpose: Returns the vertex  value  for   the current
468             -- position of the iterator.
469         returns any Vertex 
470         raises NoSuchObject from Standard;
471
472         Clear (me : in out);
473             ---Level: Public
474             ---Purpose: To clear the  iterator before having visiting
475             -- all vertices.
476
477     fields
478         MyVertexIterator : SetIteratorOfSetOfVertex;
479         HasMore          : Boolean from Standard;
480     end;
481
482     class RootsIterator 
483         ---Purpose: Defines  nested class RootsIterator, to visit every
484         -- "root" vertex of a directed graph.
485
486     raises NoMoreObject from Standard ,
487            NoSuchObject from Standard
488     is
489         Create (aGraph : HDirectedGraph) returns RootsIterator;
490
491         More (me)
492             ---Level: Public
493             ---Purpose: Returns TRUE if there are other vertices.
494         returns Boolean from Standard;
495
496         Next (me : in out) raises NoMoreObject from Standard; 
497             ---Level: Public
498             ---Purpose: Sets the iterator to the next vertex.
499
500         Value (me) 
501             ---Level: Public
502             ---Purpose: Returns  the  vertex  value  for the   current
503             -- position of the iterator.
504         returns any Vertex 
505         raises NoSuchObject from Standard;
506
507         Clear (me : in out);
508             ---Level: Public
509             ---Purpose: To  clear the  iterator before having visiting
510             -- all vertices.
511
512     fields
513         MyVertexIterator : SetIteratorOfSetOfVertex;
514         HasMore          : Boolean from Standard;
515     end;
516
517     class LeavesIterator
518         ---Purpose: Defines nested class LeavesIterator, to visit every
519         -- "leaf" vertex of a directed graph.
520
521     raises NoMoreObject from Standard ,
522            NoSuchObject from Standard
523     is
524         Create (aGraph : HDirectedGraph) returns LeavesIterator;
525
526         More (me) 
527             ---Level: Public
528             ---Purpose: Returns TRUE if  there are other vertices.
529         returns Boolean from Standard;
530
531         Next (me : in out) raises NoMoreObject from Standard; 
532             ---Level: Public
533             ---Purpose: Set the iterator to the next vertex.
534
535         Value (me) 
536             ---Level: Public
537             ---Purpose: Returns  the  vertex  value for   the  current
538             -- position of the iterator.
539         returns any Vertex 
540         raises NoSuchObject from Standard;
541         
542         Clear (me : in out);
543             ---Level: Public
544             ---Purpose: To  clear the  iterator before having visiting
545             -- all vertices.
546
547     fields
548         MyVertexIterator : SetIteratorOfSetOfVertex;
549         HasMore          : Boolean from Standard;
550     end;
551
552     class EdgesIterator
553         ---Purpose: Defines nested class  EdgesIterator, to visit every
554         -- edge of a directed graph.
555
556     raises NoMoreObject from Standard ,
557            NoSuchObject from Standard
558     is
559         Create (aGraph : HDirectedGraph) returns EdgesIterator;
560
561         More (me) returns Boolean from Standard;
562             ---Level: Public
563             ---Purpose: Returns TRUE if there are other edges.
564
565         Next (me : in out) raises NoMoreObject from Standard; 
566             ---Level: Public
567             ---Purpose: Sets the iterator to the next edge.
568
569         Value (me)  
570             ---Level: Public
571             ---Purpose: Returns  the  edge    value  for  the  current
572             -- position of the iterator.
573         returns any Edge
574         raises NoSuchObject from Standard;
575
576         Clear (me : in out);
577             ---Level: Public
578             ---Purpose: To  clear the  iterator before having visiting all edges.
579
580     fields
581         MyEdgeIterator : SetIteratorOfSetOfEdge;
582         HasMore        : Boolean from Standard;
583     end;
584
585 --------------------- class HDirectedGraph -----------------------------
586
587 is
588
589     Create returns mutable HDirectedGraph;
590         ---Purpose: Creates an empty Directed Graph.
591
592     NumberOfVertices (me) returns Integer from Standard;
593         ---Level: Public
594
595     NumberOfEdges (me) returns Integer from Standard;
596         ---Level: Public
597
598     NumberOfLeaves (me) returns Integer from Standard;
599         ---Level: Public
600         ---Purpose: Returns the number   of "leaf" vertices  of  <me>.
601
602     NumberOfRoots (me) returns Integer from Standard;
603         ---Level: Public
604         ---Purpose: Returns  the number of  "root"  vertices  of <me>.
605
606     IsEmpty (me) returns Boolean from Standard;
607         ---Level: Public
608     
609     Clear (me : mutable);
610         ---Level: Public
611         ---Purpose: Removes all edges and vertices of <me>.
612     
613     IsMember (me; aVertex : Vertex) returns Boolean from Standard;
614         ---Level: Public
615
616     IsMember (me; anEdge : Edge) returns Boolean from Standard;    
617         ---Level: Public
618
619     Add (me : mutable; Value : Item)
620         ---Level: Public
621         ---Purpose: Creates and  Adds  a vertex,   with a given  value
622         -- <value>, to <me>. Of  course this new  Vertex is a
623         -- "root" and "leaf" vertex of <me> because it has no
624         -- connexion  with other  vertices of  the   directed graph.
625     returns mutable Vertex;
626
627     Remove (me : mutable; aVertex : mutable Vertex)
628         ---Level: Public
629         ---Purpose: Removes <aVertex> from <me>.  Removes also all the
630         -- edges of  <me>  which reference <aVertex>; Updates
631         -- Source and Destination  vertices of each  of these
632         -- edges  . Raises an exception  if  <aVertex> is not
633         -- member of <me>.
634     raises NoSuchObject from Standard;
635
636     Add (me : mutable; Source : mutable Vertex; 
637          Destination : mutable Vertex; Value : Attribute)
638         ---Level: Public
639         ---Purpose: Creates and   adds  an  edge   from    <source> to
640         -- <destination>, with   the  attribute  <value>,  to
641         -- <me>.  Updates Source and Destination  Vertices of
642         -- this new edge.  Raises an exception if <source> or
643         -- <destination> are not members of <me>.
644     returns mutable Edge
645     raises NoSuchObject from Standard;
646
647     Remove (me : mutable; AnEdge : mutable Edge)
648         ---Level: Public
649         ---Purpose: Removes  <anEdge>  from <me>.  And  Updates Source
650         -- and Destination  Vertices  of  <anEdge>. Raises an
651         -- exception if <Edge> is not member of <me>.
652     raises NoSuchObject from Standard;
653
654     GetVertices (me) 
655         ---Level: Internal
656         ---Purpose: Returns "myVertices" field for Iterator.
657     returns SetOfVertex 
658     is private;
659     
660     GetEdges (me) 
661         ---Level: Internal
662         ---Purpose: Returns "myEdges" field for Iterator.
663     returns SetOfEdge
664     is private;
665
666     ShallowCopy(me) returns mutable like me 
667        is redefined;
668         ---Level: Advanced
669         ---C++: function call
670
671
672     ShallowDump (me; s: in out OStream) 
673         is redefined;
674         ---Level: Advanced
675         ---C++: function call
676
677
678 fields
679     MyVertices : SetOfVertex;
680     MyEdges    : SetOfEdge;
681
682     friends class VerticesIterator from PCollection,
683             class RootsIterator from PCollection,
684             class LeavesIterator from PCollection,
685             class EdgesIterator from PCollection    
686 end;
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704