Otawa  0.10
graphviz.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * graphviz plugin interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2006-07, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef PRIVATE_GRAPHVIZ_H
23 #define PRIVATE_GRAPHVIZ_H
24 #include <otawa/display/Driver.h>
25 #include <otawa/display/Graph.h>
26 #include <otawa/display/graphviz.h>
27 #include <elm/genstruct/FragTable.h>
28 #include <elm/genstruct/HashTable.h>
29 #include <otawa/display/Plugin.h>
30 
31 namespace otawa { namespace display {
32 
33 /********************************* Driver *************************************/
34 class GraphVizDriver: public Plugin {
35 public:
36  GraphVizDriver(void);
37  virtual Graph *newGraph(
38  const PropList& defaultGraphStyle = PropList::EMPTY,
39  const PropList& defaultNodeStyle = PropList::EMPTY,
40  const PropList& defaultEdgeStyle = PropList::EMPTY) const;
41 };
42 
43 /*********************************** Item *************************************/
45 protected:
54 
55  virtual String getPropertiesString();
57  virtual String attributes(const PropList& props);
58  virtual bool printAttribute(elm::io::Output &out, const PropList::Iter& prop);
59 public:
60  GraphVizItem();
61  virtual ~GraphVizItem(void) { }
62  virtual void setProps(const PropList& props);
63  virtual String attributes() = 0;
64 };
65 
66 /******************************** Graph Element *******************************/
67 // Nodes and Edges
69 protected:
70  virtual ~GraphVizGraphElement(void) { }
71  virtual bool printAttribute(elm::io::Output &out, const PropList::Iter& prop);
72 };
73 
74 /******************************** Node ****************************************/
75 class GraphVizNode: public Node, public GraphVizGraphElement {
76 private:
80  bool _hasTitle;
84  bool _hasBody;
88  int _number;
89 protected:
91  virtual bool printAttribute(elm::io::Output &out, const PropList::Iter& prop);
92 public:
93  GraphVizNode(int number);
94  inline virtual int number(){return _number;}
95 
96  // inherited from GraphVizItem
97  virtual String attributes();
98 
99  // inherited from Item:
100  virtual void setProps(const PropList& props);
101 };
102 
103 /********************************** Edge **************************************/
104 class GraphVizEdge: public Edge, public GraphVizGraphElement {
105 protected:
107  bool _hasLabel;
115  virtual bool printAttribute(elm::io::Output &out, const PropList::Iter& prop);
116 public:
118  inline virtual GraphVizNode* source(){return _src;}
119  inline virtual GraphVizNode* target(){return _dest;}
120 
121  // inherited from GraphVizItem
122  virtual String attributes();
123 
124  // inherited from Item:
125  virtual void setProps(const PropList& props);
126 };
127 
128 /********************************* Graph **************************************/
129 class GraphVizGraph: public Graph, public GraphVizItem {
130 protected:
142  virtual void printGraphData(elm::io::Output& out);
143 public:
145  const PropList& defaultGraphStyle = PropList::EMPTY,
146  const PropList& defaultNodeStyle = PropList::EMPTY,
147  const PropList& defaultEdgeStyle = PropList::EMPTY);
148 
149  // inherited from GraphVizItem
150  virtual String attributes();
151 
152  // inherited from Item:
153  virtual void setProps(const PropList& props);
154 
155  // inherited from Graph:
156  virtual Node *newNode(
157  const PropList& style = PropList::EMPTY,
158  const PropList& props = PropList::EMPTY);
159  virtual Edge *newEdge(
160  Node *source,
161  Node *target,
162  const PropList& style = PropList::EMPTY,
163  const PropList& props = PropList::EMPTY);
164  virtual void display(void) throw(DisplayException);
165 };
166 
167 /******************************************************************************/
168 
169 extern String quoteSpecials(String str);
170 extern String quoteNewlines(String str);
171 
172 } }
173 
174 #endif /*PRIVATE_GRAPHVIZ_H*/
virtual int number()
This function returns the number of this node.
Definition: graphviz.h:94
virtual bool printAttribute(elm::io::Output &out, const PropList::Iter &prop)
Process the Property given by the iterator pointing to it.
Definition: graphviz_Node.cpp:111
virtual Edge * newEdge(Node *source, Node *target, const PropList &style=PropList::EMPTY, const PropList &props=PropList::EMPTY)
This function creates a new edge between the two given nodes, in the graph.
Definition: graphviz_Graph.cpp:96
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
elm::genstruct::FragTable< GraphVizEdge * > _edges
list of edges in the graph
Definition: graphviz.h:134
bool _hasBody
true if the body have been set, even if it is an empty string
Definition: graphviz.h:84
virtual void printOthersAttributes(elm::io::Output &out)
Prints attributes after all the style PropList have been iterated.
Definition: graphviz_Graph.cpp:64
String _body
node body
Definition: graphviz.h:82
This exception is thrown during the display of a graph if there is an error.
Definition: Graph.h:68
static const PropList EMPTY
This is an empty proplist for convenience.
Definition: PropList.h:66
virtual void setProps(const PropList &props)
Set the object properties that have to be printed.
Definition: graphviz_Edge.cpp:87
virtual void setProps(const PropList &props)
Set the object properties that have to be printed.
Definition: graphviz_Node.cpp:47
virtual void printOthersAttributes(elm::io::Output &out)
Prints attributes after all the style PropList have been iterated.
Definition: graphviz_Edge.cpp:56
virtual void printGraphData(elm::io::Output &out)
Prints to the given output all the data DOT needs to create the graph information.
Definition: graphviz_Graph.cpp:126
virtual void setProps(const PropList &props)
Definition: graphviz_Item.cpp:132
Definition: graphviz.h:75
elm::genstruct::FragTable< GraphVizNode * > _nodes
list of nodes in the graph
Definition: graphviz.h:132
String quoteSpecials(String str)
This function escapes all the special characters, and replaces the newlines by \l (left-align in dot)...
Definition: graphviz_quote.cpp:36
virtual String attributes()
calls attributes(const PropList& style) with the PropList containing the style of the item...
Definition: graphviz_Graph.cpp:72
Definition: graphviz.h:34
GraphVizGraph(const PropList &defaultGraphStyle=PropList::EMPTY, const PropList &defaultNodeStyle=PropList::EMPTY, const PropList &defaultEdgeStyle=PropList::EMPTY)
Constructs a new GraphVizGraph.
Definition: graphviz_Graph.cpp:52
GraphVizDriver(void)
Build the driver.
Definition: display_graphviz.cpp:46
virtual String getPropertiesString()
Makes a string containing the values of all properties in _props separated by newlines.
Definition: graphviz_Item.cpp:34
This iterator is used for reading all properties of a property list.
Definition: PropList.h:92
virtual bool printAttribute(elm::io::Output &out, const PropList::Iter &prop)
Process the Property given by the iterator pointing to it.
Definition: graphviz_Edge.cpp:72
virtual Graph * newGraph(const PropList &defaultGraphStyle=PropList::EMPTY, const PropList &defaultNodeStyle=PropList::EMPTY, const PropList &defaultEdgeStyle=PropList::EMPTY) const
Creates a new graph with default styles given.
Definition: display_graphviz.cpp:53
Definition: graphviz.h:129
String _label
label of the edge
Definition: graphviz.h:109
String _title
node title
Definition: graphviz.h:78
PropList _props
Properties of the attached object.
Definition: graphviz.h:47
GraphVizItem()
Used to set the default behaviour of properties listing to "INCLUDE".
Definition: graphviz_Item.cpp:24
bool _shapeAcceptsBody
true if the shape selected can be cutted into sub-boxes
Definition: graphviz.h:86
GraphVizNode * _src
source of the edge
Definition: graphviz.h:111
virtual void display(void)
This functions displays the graph.
Definition: graphviz_Graph.cpp:151
Definition: graphviz.h:44
virtual void printOthersAttributes(elm::io::Output &out)
Prints attributes after all the style PropList have been iterated.
Definition: graphviz_Item.cpp:55
virtual String attributes()
calls attributes(const PropList& style) with the PropList containing the style of the item...
Definition: graphviz_Edge.cpp:50
int _node_count
node count for giving a different number for each new node
Definition: graphviz.h:140
GraphVizEdge(GraphVizNode *src, GraphVizNode *dest)
Creates a new edge with the first node given as source node, and the second node as target node...
Definition: graphviz_Edge.cpp:27
int _number
number of the node
Definition: graphviz.h:88
A plugin to provide driver to display graphs.
Definition: Plugin.h:38
virtual String attributes()
calls attributes(const PropList& style) with the PropList containing the style of the item...
Definition: graphviz_Node.cpp:41
String quoteNewlines(String str)
This function escapes the newlines in order to avoid giving the newline to DOT input.
Definition: graphviz_quote.cpp:18
Definition: graphviz.h:104
PropList _default_edge_style
default style for the edges
Definition: graphviz.h:138
bool _hasLabel
true if the label have been set, even if it is an empty string
Definition: graphviz.h:107
virtual String attributes()=0
calls attributes(const PropList& style) with the PropList containing the style of the item...
GraphVizNode(int number)
Creates a new node with the given number.
Definition: graphviz_Node.cpp:27
sys::SystemOutStream & out
bool _hasTitle
true if the title have been set, even if it is an empty string
Definition: graphviz.h:80
dtd::RefAttr< BasicBlock * > target("target", dtd::STRICT|dtd::REQUIRED)
Definition: Graph.h:60
elm::genstruct::HashTable< const AbstractIdentifier *, int > _include
List of properties to print.
Definition: graphviz.h:49
PropList _default_node_style
default style for the nodes
Definition: graphviz.h:136
GraphVizNode * _dest
target of the edge
Definition: graphviz.h:113
virtual ~GraphVizItem(void)
Definition: graphviz.h:61
This a list of properties.
Definition: PropList.h:63
virtual bool printAttribute(elm::io::Output &out, const PropList::Iter &prop)
Process the Property given by the iterator pointing to it.
Definition: graphviz_Item.cpp:69
bool _defaultInclude
true if the default is to include all properties
Definition: graphviz.h:53
A graph provides facilities to display a graph.
Definition: Graph.h:76
virtual bool printAttribute(elm::io::Output &out, const PropList::Iter &prop)
Process the Property given by the iterator pointing to it.
Definition: graphviz_GraphElement.cpp:20
virtual Node * newNode(const PropList &style=PropList::EMPTY, const PropList &props=PropList::EMPTY)
This function creates a new node in the graph.
Definition: graphviz_Graph.cpp:83
virtual ~GraphVizGraphElement(void)
Definition: graphviz.h:70
Definition: graphviz.h:68
virtual GraphVizNode * target()
This function returns the target of this edge.
Definition: graphviz.h:119
virtual void setProps(const PropList &props)
Definition: graphviz_Graph.cpp:77
elm::genstruct::HashTable< const AbstractIdentifier *, int > _exclude
List of properties to hide.
Definition: graphviz.h:51
virtual void printOthersAttributes(elm::io::Output &out)
Prints attributes after all the style PropList have been iterated.
Definition: graphviz_Node.cpp:80
Definition: Graph.h:50
virtual GraphVizNode * source()
This function returns the source of this edge.
Definition: graphviz.h:118