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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
23 /+
448
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
24 /**
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
25 * Marks all cycles in the graph.
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
26 *
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
27 * May have bugs, but is a bit simpler than the previous version.
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
28 */
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
31 foreach(e; edges) Stderr(e.type)(" "c);
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
45
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
46 foreach(edge2; edge.incoming.outgoingEdges)
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
47 if (visit(edge2)) {
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
52 continue;
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
60 return false;
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
61 }
395
ac9cd48151b6 Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
62
448
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
63 foreach(vertex; vertices)
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
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
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
66 visit(edge);
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
67 debug Stderr("*\n");
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
68 }
c82b36b9cadf Simpler writer hierarchy.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 446
diff changeset
69 }
729
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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
ec8dd7b8bf0c Updated graph type.
Jari-Matti M?kel? <jmjm@iki.fi>
parents: 466
diff changeset
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 }