comparison src/docgen/graphutils/writer.d @ 806:bcb74c9b895c

Moved out files in the trunk folder to the root.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 09 Mar 2008 00:12:19 +0100
parents trunk/src/docgen/graphutils/writer.d@ec8dd7b8bf0c
children
comparison
equal deleted inserted replaced
805:a3fab8b74a7d 806:bcb74c9b895c
1 /**
2 * Author: Jari-Matti Mäkelä
3 * License: GPL3
4 */
5 module docgen.graphutils.writer;
6
7 public import docgen.misc.misc;
8 public import docgen.graphutils.primitives;
9 public import docgen.page.writer;
10 debug import tango.io.Stdout;
11
12 interface GraphWriter {
13 void generateDepGraph(DepGraph depGraph, OutputStream imageFile);
14 }
15
16 interface GraphWriterFactory : WriterFactory {
17 GraphWriter createGraphWriter(PageWriter writer, GraphFormat outputFormat);
18 }
19
20 interface CachingGraphWriterFactory : GraphWriterFactory {
21 GraphCache graphCache();
22 }
23 /+
24 /**
25 * Marks all cycles in the graph.
26 *
27 * May have bugs, but is a bit simpler than the previous version.
28 */
29 void findCycles(Vertex[] vertices, Edge[] edges) {
30 debug void p() {
31 foreach(e; edges) Stderr(e.type)(" "c);
32 Stderr.newline;
33 }
34
35 bool visit(Edge edge) {
36 if (edge.cycleType == CycleType.Reserved) {
37 edge.cycleType = CycleType.Cyclic;
38 version(VerboseDebug) p();
39 return true;
40 }
41
42 bool wasCyclic = edge.isCyclic();
43 edge.cycleType = CycleType.Reserved;
44 version(VerboseDebug) p();
45
46 foreach(edge2; edge.incoming.outgoingEdges)
47 if (visit(edge2)) {
48 if (edge.isCyclic()) {
49 edge.cycleType = CycleType.Reserved;
50 wasCyclic = true;
51 version(VerboseDebug) p();
52 continue;
53 }
54 edge.cycleType = CycleType.Cyclic;
55 return true;
56 }
57
58 edge.cycleType = wasCyclic ? CycleType.Cyclic : CycleType.Cyclefree;
59 version(VerboseDebug) p();
60 return false;
61 }
62
63 foreach(vertex; vertices)
64 foreach(edge; vertex.outgoingEdges)
65 if (edge.cycleType == CycleType.Unspecified) {
66 visit(edge);
67 debug Stderr("*\n");
68 }
69 }
70 +/
71
72 abstract class AbstractGraphWriter : AbstractWriter!(GraphWriterFactory), GraphWriter {
73 protected:
74
75 PageWriter writer;
76
77 public:
78
79 this(GraphWriterFactory factory, PageWriter writer) {
80 super(factory);
81 this.writer = writer;
82 }
83 }
84
85 class DefaultGraphCache : GraphCache {
86 private:
87
88 char[][Object][GraphFormat] m_graphCache;
89
90 public:
91
92 char[] getCachedGraph(Object graph, GraphFormat format) {
93 debug Stdout("Starting graph lookup\n");
94 debug Stdout(&graph, format).newline;
95 debug Stdout(&m_graphCache).newline;
96
97 auto lookup1 = format in m_graphCache;
98 if (lookup1) {
99 auto lookup2 = graph in *lookup1;
100 if (lookup2) {
101 return *lookup2;
102 }
103 }
104 debug Stdout("Graph cache miss!\n");
105 return null;
106 }
107
108 void setCachedGraph(Object graph, GraphFormat format, char[]
109 contents) {
110 m_graphCache[format][graph] = contents;
111 debug Stdout("Graph cache updated!\n");
112 }
113 }