1 //===-- Support/DotGraphTraits.h - Customize .dot output -------*- C++ -*--===//
3 // This file defines a template class that can be used to customize dot output
4 // graphs generated by the GraphWriter.h file. The default implementation of
5 // this file will produce a simple, but not very polished graph. By
6 // specializing this template, lots of customization opportunities are possible.
8 //===----------------------------------------------------------------------===//
10 #ifndef SUPPORT_DOTGRAPHTRAITS_H
11 #define SUPPORT_DOTGRAPHTRAITS_H
15 /// DefaultDOTGraphTraits - This class provides the default implementations of
16 /// all of the DOTGraphTraits methods. If a specialization does not need to
17 /// override all methods here it should inherit so that it can get the default
20 struct DefaultDOTGraphTraits {
21 /// getGraphName - Return the label for the graph as a whole. Printed at the
24 static std::string getGraphName(void *Graph) { return ""; }
26 /// getGraphProperties - Return any custom properties that should be included
27 /// in the top level graph structure for dot. By default, we resize the graph
28 /// to fit on a letter size page.
30 static std::string getGraphProperties(void *Graph) {
31 return "\tsize=\"7.5,10\";\n"; // Size to fit on a page
34 /// getNodeLabel - Given a node and a pointer to the top level graph, return
35 /// the label to print in the node.
36 static std::string getNodeLabel(void *Node, void *Graph) { return ""; }
38 /// If you want to specify custom node attributes, this is the place to do so
40 static std::string getNodeAttributes(void *Node) { return ""; }
42 /// If you want to override the dot attributes printed for a particular edge,
43 /// override this method.
44 template<typename EdgeIter>
45 static std::string getEdgeAttributes(void *Node, EdgeIter EI) { return ""; }
47 /// getEdgeSourceLabel - If you want to label the edge source itself,
48 /// implement this method.
49 template<typename EdgeIter>
50 static std::string getEdgeSourceLabel(void *Node, EdgeIter I) { return ""; }
52 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
53 /// should actually target another edge source, not a node. If this method is
54 /// implemented, getEdgeTarget should be implemented.
55 template<typename EdgeIter>
56 static bool edgeTargetsEdgeSource(void *Node, EdgeIter I) { return false; }
58 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
59 /// called to determine which outgoing edge of Node is the target of this
61 template<typename EdgeIter>
62 static EdgeIter getEdgeTarget(void *Node, EdgeIter I) { return I; }
64 /// addCustomGraphFeatures - If a graph is made up of more than just
65 /// straight-forward nodes and edges, this is the place to put all of the
66 /// custom stuff neccesary. The GraphWriter object, instantiated with your
67 /// GraphType is passed in as an argument. You may call arbitrary methods on
68 /// it to add things to the output graph.
70 template<typename GraphWriter>
71 static void addCustomGraphFeatures(void *Graph, GraphWriter &GW) {}
75 /// DOTGraphTraits - Template class that can be specialized to customize how
76 /// graphs are converted to 'dot' graphs. When specializing, you may inherit
77 /// from DefaultDOTGraphTraits if you don't need to override everything.
79 template <typename Ty>
80 class DOTGraphTraits : public DefaultDOTGraphTraits {};