LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
graph.hh
Go to the documentation of this file.
1 
6 #ifndef MISC_GRAPH_HH
7 # define MISC_GRAPH_HH
8 
9 # include <iosfwd>
10 # include <list>
11 # include <set>
12 # include <string>
13 # include <vector>
14 
15 /* Forward declarations to help the compiler not to mix up the
16  namespace `target' with `boost::target'. This happens in the
17  instantiation of graph concepts in boost/graph/graph_concepts.hpp
18  if this forward declaration is omitted. */
19 #include <boost/graph/detail/edge.hpp>
20 namespace boost
21 {
22  template <class OutEdgeListS, class VertexListS, class DirectedS,
23  class VertexProperty, class EdgeProperty, class GraphProperty,
24  class EdgeListS>
25  class adjacency_list;
26 
27  template <class Directed, class Vertex, class OutEdgeListS,
28  class VertexListS, class DirectedS, class VertexProperty,
29  class EdgeProperty, class GraphProperty, class EdgeListS>
30  inline Vertex
31  target(const detail::edge_base<Directed, Vertex>& e,
32  const adjacency_list<OutEdgeListS, VertexListS, DirectedS,
33  VertexProperty, EdgeProperty, GraphProperty, EdgeListS>&);
34 } // namespace boost
35 
36 # include <boost/graph/adjacency_list.hpp>
37 
38 # include <misc/set.hh>
39 
41 namespace misc
42 {
43 
44  /*--------.
45  | Graph. |
46  `--------*/
47 
49  typedef boost::property<boost::graph_name_t, std::string> name_prop_type;
50 
51  template <typename Orientation, typename VertexLabel, typename EdgeLabel>
52  class graph
53  : public boost::adjacency_list<boost::setS, boost::vecS, Orientation,
54  VertexLabel, EdgeLabel,
55  name_prop_type>
56  {
57  public:
58  virtual ~graph();
59 
60  public:
62  typedef boost::adjacency_list<boost::setS, boost::vecS, Orientation,
63  VertexLabel, EdgeLabel,
65  typedef typename super_type::vertex_descriptor vertex_descriptor;
66 
68  public:
71  typedef typename boost::graph_traits<self_type>::vertex_iterator
74  typedef typename boost::graph_traits<self_type>::edge_iterator
77 
80  public:
84  vertex_descriptor vertex_add(const VertexLabel& l);
86  virtual void
87  edge_add(const vertex_descriptor& v1, const vertex_descriptor& v2) = 0;
89 
92  public:
93  virtual std::ostream& print(std::ostream& ostr) const;
94  virtual std::ostream& epilogue_print(std::ostream& ostr) const;
95  virtual void print(std::string file) const;
96 
97  private:
99  virtual std::ostream&
100  vertex_print(vertex_descriptor v, std::ostream& ostr) const = 0;
102 
105  public:
106  const std::string& name_get() const;
107  void name_set(const std::string& name);
109  };
110 
111  template <typename Orientation, typename VertexLabel, typename EdgeLabel>
112  std::ostream&
113  operator<<(std::ostream& ostr,
115 
116  // An helper class when we do not want any data attached to vertex
117  // or an edge.
118  struct empty {};
119  inline std::ostream& operator<<(std::ostream& ostr, empty);
120 
121 
122  /*----------------------------------------------------.
123  | Specialization for directed (bidirectional) graph. |
124  `----------------------------------------------------*/
125 
126  /* Note that boost::bidirectionalS is like boost::directedS, except
127  that it provides access to both in-edges and out-edges, whereas
128  boost::directedS gives us only out-edges. The consequence is
129  that a bidirectional graph is twice as large as its directed
130  version. */
131  template <typename VertexLabel = empty, typename EdgeLabel = empty>
133  : public graph<boost::bidirectionalS, VertexLabel, EdgeLabel>
134  {
135  public:
136  virtual ~directed_graph();
137 
138  public:
142 
143  public:
145  typedef typename boost::graph_traits<self_type>::vertex_iterator
148  typedef typename boost::graph_traits<self_type>::adjacency_iterator
150 
153  public:
157  virtual void
158  edge_add(const vertex_descriptor& v1,
159  const vertex_descriptor& v2) override;
161 
170  public:
171  std::list<vertex_descriptor> topological_sort() const;
172  // FIXME: Some code was deleted here (You might want additional methods (this needs to be done in TC-8)).
174  };
175 
176 
177  /*--------------------------------------.
178  | Specialization for undirected graph. |
179  `--------------------------------------*/
180 
181  template <typename VertexLabel = empty, typename EdgeLabel = empty>
183  : public graph<boost::undirectedS, VertexLabel, EdgeLabel>
184  {
185  public:
186  virtual ~undirected_graph();
187 
188  public:
191 
192  public:
197  virtual void
198  edge_add(const vertex_descriptor& v1, const
199  vertex_descriptor& v2) override;
200  };
201 
202 } // namespace misc
203 
204 # include <misc/graph.hxx>
205 
206 #endif // !MISC_GRAPH_HH