Mercurial > projects > dil
diff trunk/src/docgen/graphutils/primitives.d @ 395:ac9cd48151b6
Added couple of docgen modules.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Wed, 19 Sep 2007 23:12:20 +0300 |
parents | |
children | 4e5b35df3060 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/graphutils/primitives.d Wed Sep 19 23:12:20 2007 +0300 @@ -0,0 +1,94 @@ +/** + * Author: Aziz Köksal & Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.graphutils.primitives; + +enum EdgeType { + Unspecified, + Aggregation, + Association, + Composition, + CyclicDependency, + Dependency, + Generalization, + Inheritance, + Reserved // for the cycle algorithm +} + +class Edge { + Vertex outgoing; + Vertex incoming; + EdgeType type; + + this(Vertex o, Vertex i, EdgeType type = EdgeType.Unspecified) { + this.outgoing = o; + this.incoming = i; + this.type = type; + } + + bool isCyclic() { + return type == EdgeType.CyclicDependency; + } +} + +enum VertexType { + Module, + Package, + Class, + Interface, + Trait +} + +class Vertex { + char[] name; + char[] location; + uint id; + + Edge[] incomingEdges; + Edge[] outgoingEdges; + VertexType type; + + this(char[] name, char[] location, uint id = 0) { + this.name = name; + this.location = location; + this.id = id; + } + + Edge addChild(Vertex v, EdgeType type = EdgeType.Unspecified) { + auto edge = new Edge(v, this, type); + incomingEdges ~= edge; + v.outgoingEdges ~= edge; + return edge; + } + + Edge addParent(Vertex v, EdgeType type = EdgeType.Unspecified) { + return v.addChild(this, type); + } + + Vertex[] incoming() { + Vertex[] tmp; + + foreach(edge; incomingEdges) + tmp ~= edge.outgoing; + + return tmp; + } + + Vertex[] outgoing() { + Vertex[] tmp; + + foreach(edge; outgoingEdges) + tmp ~= edge.incoming; + + return tmp; + } + + bool isCyclic() { + foreach(edge; outgoingEdges) + if (edge.isCyclic) + return true; + + return false; + } +} \ No newline at end of file