Otawa  0.10
GenDrawer.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * GenDrawer class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007, 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 OTAWA_DISPLAY_GENDRAWER_H
23 #define OTAWA_DISPLAY_GENDRAWER_H
24 
26 
27 namespace otawa { namespace display {
28 
29 // GenDrawer class
30 template <class G, class D>
31 class GenDrawer: public AbstractDrawer {
32 public:
33  inline GenDrawer(const G& graph);
34 
35 private:
36 
38  public:
39  inline Vertex(AbstractDrawer& drawer, const G& graph, typename G::Vertex vertex)
40  : AbstractDrawer::Vertex(drawer), _(vertex), _graph(graph) { }
41  virtual void configure(Output& content, ShapeStyle& shape)
42  { D::decorate(_graph, _, content, shape); }
43  private:
44  typename G::Vertex _;
45  const G& _graph;
46  };
47 
48  class Edge: public AbstractDrawer::Edge {
49  public:
50  inline Edge(AbstractDrawer& drawer, const G& graph, Vertex *source, Vertex *sink,
51  typename G::Edge edge)
52  : AbstractDrawer::Edge(drawer, source, sink), _(edge), _graph(graph) { }
53  virtual void configure(Output& label, TextStyle& text, LineStyle& line)
54  { D::decorate(_graph, _, label, text, line); }
55  private:
56  typename G::Edge _;
57  const G& _graph;
58  };
59 
60  const G& _graph;
61  virtual void configure(Output& caption, TextStyle& text, FillStyle& fill)
62  { D::decorate(_graph, caption, text, fill); }
63 };
64 
65 // GenDrawer::GenDrawer constructor
66 template <class G, class D>
67 GenDrawer<G, D>::GenDrawer(const G& graph): _graph(graph) {
68  typename G::template VertexMap<Vertex *> map(graph);
69 
70  // Process the vertices
71  for(typename G::Iterator vertex(graph); vertex; vertex++)
72  map.put(vertex, new Vertex(*this, _graph, vertex));
73 
74  // Process the edges
75  for(typename G::Iterator vertex(graph); vertex; vertex++)
76  for(typename G::Successor edge(_graph, vertex); edge; edge++)
77  new Edge(*this, _graph, map.get(vertex), map.get((*edge).sink()), *edge);
78 }
79 
80 
81 // DefaultDecorator class
82 template <class G>
84 public:
85  static inline void decorate(
86  const G& graph,
87  Output& caption,
88  TextStyle& text,
89  FillStyle& fill) { }
90 
91  static inline void decorate(
92  const G& graph,
93  const typename G::Vertex vertex,
94  Output& content,
95  ShapeStyle& style) { content << vertex; }
96 
97  static inline void decorate(
98  const G& graph,
99  const typename G::Edge edge,
100  Output& label,
101  TextStyle& text,
102  LineStyle& line) { label << edge; }
103 };
104 
105 } } // otawa::display
106 
107 #endif /* OTAWA_DISPLAY_GENDRAWER_H */
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
An edge in a AbstractDrawer.
Definition: AbstractDrawer.h:55
dtd::Element edge(dtd::make("edge", _EDGE).attr(source).attr(target).attr(called))
TextStyle text
Style of the text publicly accessible for customization.
Definition: AbstractDrawer.h:59
display::Edge * edge
Definition: AbstractDrawer.h:66
LineStyle line
Style of the line publicly accessible for customization.
Definition: AbstractDrawer.h:60
The style of a filled area.
Definition: display.h:83
Definition: GenDrawer.h:37
const G & _graph
Definition: GenDrawer.h:60
Description of the style of text.
Definition: display.h:48
This class represents vertices in the AbstractDrawer.
Definition: AbstractDrawer.h:40
const G & _graph
Definition: GenDrawer.h:45
Shape style.
Definition: display.h:98
static void decorate(const G &graph, const typename G::Edge edge, Output &label, TextStyle &text, LineStyle &line)
Definition: GenDrawer.h:97
ShapeStyle shape
Shape of the vertex publicly accessible for customization.
Definition: AbstractDrawer.h:44
Edge(AbstractDrawer &drawer, const G &graph, Vertex *source, Vertex *sink, typename G::Edge edge)
Definition: GenDrawer.h:50
static void decorate(const G &graph, const typename G::Vertex vertex, Output &content, ShapeStyle &style)
Definition: GenDrawer.h:91
static void decorate(const G &graph, Output &caption, TextStyle &text, FillStyle &fill)
Definition: GenDrawer.h:85
G::Vertex _
Definition: GenDrawer.h:44
virtual void configure(Output &label, TextStyle &text, LineStyle &line)
This method may be overriden to provide a customized displayed text.
Definition: GenDrawer.h:53
A simple engine to draw graphs.
Definition: GenDrawer.h:31
Provides facilities to draw a graph.
Definition: AbstractDrawer.h:35
const G & _graph
Definition: GenDrawer.h:57
Graph * graph
Definition: AbstractDrawer.h:88
virtual void configure(Output &content, ShapeStyle &shape)
This method may be overriden to provide a customized displayed text.
Definition: GenDrawer.h:41
GenDrawer(const G &graph)
Build the drawer.
Definition: GenDrawer.h:67
G::Edge _
Definition: GenDrawer.h:56
virtual void configure(Output &caption, TextStyle &text, FillStyle &fill)
This method may be overriden to provide a customized graph ledend.
Definition: GenDrawer.h:61
Default decorator that just output the given edges and vertices.
Definition: GenDrawer.h:83
Definition: GenDrawer.h:48
Vertex(AbstractDrawer &drawer, const G &graph, typename G::Vertex vertex)
Definition: GenDrawer.h:39
Definition: display.h:65