Mercurial > projects > dil
annotate trunk/src/docgen/graphutils/writer.d @ 729:ec8dd7b8bf0c
Updated graph type.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Sun, 03 Feb 2008 19:43:53 +0200 |
parents | db7e27b5c180 |
children |
rev | line source |
---|---|
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
1 /** |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
2 * Author: Jari-Matti Mäkelä |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
3 * License: GPL3 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
4 */ |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
5 module docgen.graphutils.writer; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
6 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
7 public import docgen.misc.misc; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
8 public import docgen.graphutils.primitives; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
9 public import docgen.page.writer; |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
10 debug import tango.io.Stdout; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
11 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
12 interface GraphWriter { |
729 | 13 void generateDepGraph(DepGraph depGraph, OutputStream imageFile); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
14 } |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
15 |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
16 interface GraphWriterFactory : WriterFactory { |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
17 GraphWriter createGraphWriter(PageWriter writer, GraphFormat outputFormat); |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
18 } |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
19 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
20 interface CachingGraphWriterFactory : GraphWriterFactory { |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
21 GraphCache graphCache(); |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
22 } |
729 | 23 /+ |
448 | 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) { | |
458
bac1d75f87f8
small fix to make it compile
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
30 debug void p() { |
448 | 31 foreach(e; edges) Stderr(e.type)(" "c); |
32 Stderr.newline; | |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
33 } |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
34 |
448 | 35 bool visit(Edge edge) { |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
36 if (edge.cycleType == CycleType.Reserved) { |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
37 edge.cycleType = CycleType.Cyclic; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
38 version(VerboseDebug) p(); |
448 | 39 return true; |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
40 } |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
41 |
448 | 42 bool wasCyclic = edge.isCyclic(); |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
43 edge.cycleType = CycleType.Reserved; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
44 version(VerboseDebug) p(); |
448 | 45 |
46 foreach(edge2; edge.incoming.outgoingEdges) | |
47 if (visit(edge2)) { | |
48 if (edge.isCyclic()) { | |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
49 edge.cycleType = CycleType.Reserved; |
448 | 50 wasCyclic = true; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
51 version(VerboseDebug) p(); |
448 | 52 continue; |
53 } | |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
54 edge.cycleType = CycleType.Cyclic; |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
55 return true; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
56 } |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
57 |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
58 edge.cycleType = wasCyclic ? CycleType.Cyclic : CycleType.Cyclefree; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
59 version(VerboseDebug) p(); |
448 | 60 return false; |
61 } | |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
62 |
448 | 63 foreach(vertex; vertices) |
64 foreach(edge; vertex.outgoingEdges) | |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
65 if (edge.cycleType == CycleType.Unspecified) { |
448 | 66 visit(edge); |
67 debug Stderr("*\n"); | |
68 } | |
69 } | |
729 | 70 +/ |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
71 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
72 abstract class AbstractGraphWriter : AbstractWriter!(GraphWriterFactory), GraphWriter { |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
73 protected: |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
74 |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
75 PageWriter writer; |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
76 |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
77 public: |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
78 |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
79 this(GraphWriterFactory factory, PageWriter writer) { |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
80 super(factory); |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
81 this.writer = writer; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
82 } |
454
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
83 } |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
84 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
85 class DefaultGraphCache : GraphCache { |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
86 private: |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
87 |
729 | 88 char[][Object][GraphFormat] m_graphCache; |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
89 |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
90 public: |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
91 |
729 | 92 char[] getCachedGraph(Object graph, GraphFormat format) { |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
93 debug Stdout("Starting graph lookup\n"); |
729 | 94 debug Stdout(&graph, format).newline; |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
95 debug Stdout(&m_graphCache).newline; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
96 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
97 auto lookup1 = format in m_graphCache; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
98 if (lookup1) { |
729 | 99 auto lookup2 = graph in *lookup1; |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
100 if (lookup2) { |
729 | 101 return *lookup2; |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
102 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
103 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
104 debug Stdout("Graph cache miss!\n"); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
105 return null; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
106 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
107 |
729 | 108 void setCachedGraph(Object graph, GraphFormat format, char[] |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
109 contents) { |
729 | 110 m_graphCache[format][graph] = contents; |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
111 debug Stdout("Graph cache updated!\n"); |
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
112 } |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
458
diff
changeset
|
113 } |