Otawa  0.10
GenGraphAdapter.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * CFGAdapter 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_GENGRAPHADAPTER_H_
23 #define OTAWA_DISPLAY_GENGRAPHADAPTER_H_
24 
25 #include <otawa/util/GenGraph.h>
26 
27 namespace otawa { namespace display {
28 
29 // GenGraphAdapter class
30 template <class G>
32 public:
33 
34  class Vertex {
35  public:
36  inline Vertex(typename G::_Node *_node): node(_node) { }
37  inline int index(void) { return node->index(); }
38  inline typename G::_Node *operator->(void) const { return node; }
39  typename G::_Node *node;
40  };
41 
42  class Edge {
43  public:
44  inline Edge(typename G::_Edge *_edge): edge(_edge) { }
45  inline Vertex source(void) const { return Vertex(edge->source()); }
46  inline Vertex sink(void) const { return Vertex(edge->target()); }
47  inline typename G::_Edge *operator->(void) const { return edge; }
48  typename G::_Edge *edge;
49  };
50 
51  class Successor: public PreIterator<Successor, Edge> {
52  public:
54  : iter(source.node) { }
55  inline Successor(const Successor& succ): iter(succ.iter) { }
56  inline bool ended(void) const { return iter.ended(); }
57  inline Edge item(void) const { return Edge(iter.edge()); }
58  inline void next(void) { iter.next(); }
59  private:
60  typename G::Successor iter;
61  };
62 
63  class Iterator: public PreIterator<Iterator, Vertex> {
64  public:
65  inline Iterator(const GenGraphAdapter& adapter): iter(adapter.graph) { }
66  inline Iterator(const Iterator& _iter): iter(_iter.iter) { }
67  inline bool ended(void) const { return iter.ended(); }
68  inline Vertex item(void) const { return Vertex(iter); }
69  inline void next(void) { iter.next(); }
70  private:
71  typename G::NodeIterator iter;
72  };
73 
74  template <class T>
75  class VertexMap {
76  public:
77  inline VertexMap(const GenGraphAdapter& adapter)
78  : vals(new T[adapter.graph->count()]) { }
79  inline const T& get(const Vertex& vertex) const
80  { return vals[vertex.node->index()]; }
81  inline void put(const Vertex& vertex, const T& val)
82  { vals[vertex.node->index()] = val; }
83  private:
84  T *vals;
85  };
86 
87  inline GenGraphAdapter(G *_graph): graph(_graph) { }
88  inline int count(void) const { return graph->count(); }
89  inline G *operator->(void) const { return graph; }
90 
91  G *graph;
92 };
93 
94 } } // otawa::display
95 
96 #endif // OTAWA_DISPLAY_GENGRAPHADAPTER_H_
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
T * vals
Definition: GenGraphAdapter.h:84
Definition: GenGraphAdapter.h:75
Definition: GenGraphAdapter.h:31
int count(void) const
Definition: GenGraphAdapter.h:88
Vertex source(void) const
Definition: GenGraphAdapter.h:45
G::_Edge * operator->(void) const
Definition: GenGraphAdapter.h:47
bool ended(void) const
Definition: GenGraphAdapter.h:56
G * operator->(void) const
Definition: GenGraphAdapter.h:89
Definition: GenGraphAdapter.h:51
Definition: GenGraphAdapter.h:42
G::_Edge * edge
Definition: GenGraphAdapter.h:48
void put(const Vertex &vertex, const T &val)
Definition: GenGraphAdapter.h:81
G::NodeIterator iter
Definition: GenGraphAdapter.h:71
Edge(typename G::_Edge *_edge)
Definition: GenGraphAdapter.h:44
Definition: GenGraphAdapter.h:34
Vertex item(void) const
Definition: GenGraphAdapter.h:68
Vertex sink(void) const
Definition: GenGraphAdapter.h:46
Edge item(void) const
Definition: GenGraphAdapter.h:57
Successor(const GenGraphAdapter &graph, Vertex source)
Definition: GenGraphAdapter.h:53
G::_Node * operator->(void) const
Definition: GenGraphAdapter.h:38
Iterator(const Iterator &_iter)
Definition: GenGraphAdapter.h:66
Successor(const Successor &succ)
Definition: GenGraphAdapter.h:55
Definition: GenGraphAdapter.h:63
Vertex(typename G::_Node *_node)
Definition: GenGraphAdapter.h:36
G * graph
Definition: GenGraphAdapter.h:91
VertexMap(const GenGraphAdapter &adapter)
Definition: GenGraphAdapter.h:77
void next(void)
Definition: GenGraphAdapter.h:58
void next(void)
Definition: GenGraphAdapter.h:69
G::Successor iter
Definition: GenGraphAdapter.h:60
GenGraphAdapter(G *_graph)
Definition: GenGraphAdapter.h:87
int index(void)
Definition: GenGraphAdapter.h:37
bool ended(void) const
Definition: GenGraphAdapter.h:67
Iterator(const GenGraphAdapter &adapter)
Definition: GenGraphAdapter.h:65
G::_Node * node
Definition: GenGraphAdapter.h:39