Chris@16
|
1 //=======================================================================
|
Chris@16
|
2 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
|
Chris@16
|
3 // Copyright 2004 The Trustees of Indiana University.
|
Chris@16
|
4 // Copyright 2007 University of Karlsruhe
|
Chris@16
|
5 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Douglas Gregor,
|
Chris@16
|
6 // Jens Mueller
|
Chris@16
|
7 //
|
Chris@16
|
8 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
9 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
10 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
11 //=======================================================================
|
Chris@16
|
12 #ifndef BOOST_GRAPH_LEDA_HPP
|
Chris@16
|
13 #define BOOST_GRAPH_LEDA_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/config.hpp>
|
Chris@16
|
16 #include <boost/iterator/iterator_facade.hpp>
|
Chris@16
|
17 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
18 #include <boost/graph/properties.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #include <LEDA/graph/graph.h>
|
Chris@16
|
21 #include <LEDA/graph/node_array.h>
|
Chris@16
|
22 #include <LEDA/graph/node_map.h>
|
Chris@16
|
23
|
Chris@16
|
24 // The functions and classes in this file allows the user to
|
Chris@16
|
25 // treat a LEDA GRAPH object as a boost graph "as is". No
|
Chris@16
|
26 // wrapper is needed for the GRAPH object.
|
Chris@16
|
27
|
Chris@16
|
28 // Warning: this implementation relies on partial specialization
|
Chris@16
|
29 // for the graph_traits class (so it won't compile with Visual C++)
|
Chris@16
|
30
|
Chris@16
|
31 // Warning: this implementation is in alpha and has not been tested
|
Chris@16
|
32
|
Chris@16
|
33 namespace boost {
|
Chris@16
|
34
|
Chris@16
|
35 struct leda_graph_traversal_category :
|
Chris@16
|
36 public virtual bidirectional_graph_tag,
|
Chris@16
|
37 public virtual adjacency_graph_tag,
|
Chris@16
|
38 public virtual vertex_list_graph_tag { };
|
Chris@16
|
39
|
Chris@16
|
40 template <class vtype, class etype>
|
Chris@16
|
41 struct graph_traits< leda::GRAPH<vtype,etype> > {
|
Chris@16
|
42 typedef leda::node vertex_descriptor;
|
Chris@16
|
43 typedef leda::edge edge_descriptor;
|
Chris@16
|
44
|
Chris@16
|
45 class adjacency_iterator
|
Chris@16
|
46 : public iterator_facade<adjacency_iterator,
|
Chris@16
|
47 leda::node,
|
Chris@16
|
48 bidirectional_traversal_tag,
|
Chris@16
|
49 leda::node,
|
Chris@16
|
50 const leda::node*>
|
Chris@16
|
51 {
|
Chris@16
|
52 public:
|
Chris@16
|
53 adjacency_iterator(leda::node node = 0,
|
Chris@16
|
54 const leda::GRAPH<vtype, etype>* g = 0)
|
Chris@16
|
55 : base(node), g(g) {}
|
Chris@16
|
56 private:
|
Chris@16
|
57 leda::node dereference() const { return leda::target(base); }
|
Chris@16
|
58
|
Chris@16
|
59 bool equal(const adjacency_iterator& other) const
|
Chris@16
|
60 { return base == other.base; }
|
Chris@16
|
61
|
Chris@16
|
62 void increment() { base = g->adj_succ(base); }
|
Chris@16
|
63 void decrement() { base = g->adj_pred(base); }
|
Chris@16
|
64
|
Chris@16
|
65 leda::edge base;
|
Chris@16
|
66 const leda::GRAPH<vtype, etype>* g;
|
Chris@16
|
67
|
Chris@16
|
68 friend class iterator_core_access;
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71 class out_edge_iterator
|
Chris@16
|
72 : public iterator_facade<out_edge_iterator,
|
Chris@16
|
73 leda::edge,
|
Chris@16
|
74 bidirectional_traversal_tag,
|
Chris@16
|
75 const leda::edge&,
|
Chris@16
|
76 const leda::edge*>
|
Chris@16
|
77 {
|
Chris@16
|
78 public:
|
Chris@16
|
79 out_edge_iterator(leda::node node = 0,
|
Chris@16
|
80 const leda::GRAPH<vtype, etype>* g = 0)
|
Chris@16
|
81 : base(node), g(g) {}
|
Chris@16
|
82
|
Chris@16
|
83 private:
|
Chris@16
|
84 const leda::edge& dereference() const { return base; }
|
Chris@16
|
85
|
Chris@16
|
86 bool equal(const out_edge_iterator& other) const
|
Chris@16
|
87 { return base == other.base; }
|
Chris@16
|
88
|
Chris@16
|
89 void increment() { base = g->adj_succ(base); }
|
Chris@16
|
90 void decrement() { base = g->adj_pred(base); }
|
Chris@16
|
91
|
Chris@16
|
92 leda::edge base;
|
Chris@16
|
93 const leda::GRAPH<vtype, etype>* g;
|
Chris@16
|
94
|
Chris@16
|
95 friend class iterator_core_access;
|
Chris@16
|
96 };
|
Chris@16
|
97
|
Chris@16
|
98 class in_edge_iterator
|
Chris@16
|
99 : public iterator_facade<in_edge_iterator,
|
Chris@16
|
100 leda::edge,
|
Chris@16
|
101 bidirectional_traversal_tag,
|
Chris@16
|
102 const leda::edge&,
|
Chris@16
|
103 const leda::edge*>
|
Chris@16
|
104 {
|
Chris@16
|
105 public:
|
Chris@16
|
106 in_edge_iterator(leda::node node = 0,
|
Chris@16
|
107 const leda::GRAPH<vtype, etype>* g = 0)
|
Chris@16
|
108 : base(node), g(g) {}
|
Chris@16
|
109
|
Chris@16
|
110 private:
|
Chris@16
|
111 const leda::edge& dereference() const { return base; }
|
Chris@16
|
112
|
Chris@16
|
113 bool equal(const in_edge_iterator& other) const
|
Chris@16
|
114 { return base == other.base; }
|
Chris@16
|
115
|
Chris@16
|
116 void increment() { base = g->in_succ(base); }
|
Chris@16
|
117 void decrement() { base = g->in_pred(base); }
|
Chris@16
|
118
|
Chris@16
|
119 leda::edge base;
|
Chris@16
|
120 const leda::GRAPH<vtype, etype>* g;
|
Chris@16
|
121
|
Chris@16
|
122 friend class iterator_core_access;
|
Chris@16
|
123 };
|
Chris@16
|
124
|
Chris@16
|
125 class vertex_iterator
|
Chris@16
|
126 : public iterator_facade<vertex_iterator,
|
Chris@16
|
127 leda::node,
|
Chris@16
|
128 bidirectional_traversal_tag,
|
Chris@16
|
129 const leda::node&,
|
Chris@16
|
130 const leda::node*>
|
Chris@16
|
131 {
|
Chris@16
|
132 public:
|
Chris@16
|
133 vertex_iterator(leda::node node = 0,
|
Chris@16
|
134 const leda::GRAPH<vtype, etype>* g = 0)
|
Chris@16
|
135 : base(node), g(g) {}
|
Chris@16
|
136
|
Chris@16
|
137 private:
|
Chris@16
|
138 const leda::node& dereference() const { return base; }
|
Chris@16
|
139
|
Chris@16
|
140 bool equal(const vertex_iterator& other) const
|
Chris@16
|
141 { return base == other.base; }
|
Chris@16
|
142
|
Chris@16
|
143 void increment() { base = g->succ_node(base); }
|
Chris@16
|
144 void decrement() { base = g->pred_node(base); }
|
Chris@16
|
145
|
Chris@16
|
146 leda::node base;
|
Chris@16
|
147 const leda::GRAPH<vtype, etype>* g;
|
Chris@16
|
148
|
Chris@16
|
149 friend class iterator_core_access;
|
Chris@16
|
150 };
|
Chris@16
|
151
|
Chris@16
|
152 class edge_iterator
|
Chris@16
|
153 : public iterator_facade<edge_iterator,
|
Chris@16
|
154 leda::edge,
|
Chris@16
|
155 bidirectional_traversal_tag,
|
Chris@16
|
156 const leda::edge&,
|
Chris@16
|
157 const leda::edge*>
|
Chris@16
|
158 {
|
Chris@16
|
159 public:
|
Chris@16
|
160 edge_iterator(leda::edge edge = 0,
|
Chris@16
|
161 const leda::GRAPH<vtype, etype>* g = 0)
|
Chris@16
|
162 : base(edge), g(g) {}
|
Chris@16
|
163
|
Chris@16
|
164 private:
|
Chris@16
|
165 const leda::edge& dereference() const { return base; }
|
Chris@16
|
166
|
Chris@16
|
167 bool equal(const edge_iterator& other) const
|
Chris@16
|
168 { return base == other.base; }
|
Chris@16
|
169
|
Chris@16
|
170 void increment() { base = g->succ_edge(base); }
|
Chris@16
|
171 void decrement() { base = g->pred_edge(base); }
|
Chris@16
|
172
|
Chris@16
|
173 leda::node base;
|
Chris@16
|
174 const leda::GRAPH<vtype, etype>* g;
|
Chris@16
|
175
|
Chris@16
|
176 friend class iterator_core_access;
|
Chris@16
|
177 };
|
Chris@16
|
178
|
Chris@16
|
179 typedef directed_tag directed_category;
|
Chris@16
|
180 typedef allow_parallel_edge_tag edge_parallel_category; // not sure here
|
Chris@16
|
181 typedef leda_graph_traversal_category traversal_category;
|
Chris@16
|
182 typedef int vertices_size_type;
|
Chris@16
|
183 typedef int edges_size_type;
|
Chris@16
|
184 typedef int degree_size_type;
|
Chris@16
|
185 };
|
Chris@16
|
186
|
Chris@16
|
187
|
Chris@16
|
188
|
Chris@16
|
189 template<>
|
Chris@16
|
190 struct graph_traits<leda::graph> {
|
Chris@16
|
191 typedef leda::node vertex_descriptor;
|
Chris@16
|
192 typedef leda::edge edge_descriptor;
|
Chris@16
|
193
|
Chris@16
|
194 class adjacency_iterator
|
Chris@16
|
195 : public iterator_facade<adjacency_iterator,
|
Chris@16
|
196 leda::node,
|
Chris@16
|
197 bidirectional_traversal_tag,
|
Chris@16
|
198 leda::node,
|
Chris@16
|
199 const leda::node*>
|
Chris@16
|
200 {
|
Chris@16
|
201 public:
|
Chris@16
|
202 adjacency_iterator(leda::edge edge = 0,
|
Chris@16
|
203 const leda::graph* g = 0)
|
Chris@16
|
204 : base(edge), g(g) {}
|
Chris@16
|
205
|
Chris@16
|
206 private:
|
Chris@16
|
207 leda::node dereference() const { return leda::target(base); }
|
Chris@16
|
208
|
Chris@16
|
209 bool equal(const adjacency_iterator& other) const
|
Chris@16
|
210 { return base == other.base; }
|
Chris@16
|
211
|
Chris@16
|
212 void increment() { base = g->adj_succ(base); }
|
Chris@16
|
213 void decrement() { base = g->adj_pred(base); }
|
Chris@16
|
214
|
Chris@16
|
215 leda::edge base;
|
Chris@16
|
216 const leda::graph* g;
|
Chris@16
|
217
|
Chris@16
|
218 friend class iterator_core_access;
|
Chris@16
|
219 };
|
Chris@16
|
220
|
Chris@16
|
221 class out_edge_iterator
|
Chris@16
|
222 : public iterator_facade<out_edge_iterator,
|
Chris@16
|
223 leda::edge,
|
Chris@16
|
224 bidirectional_traversal_tag,
|
Chris@16
|
225 const leda::edge&,
|
Chris@16
|
226 const leda::edge*>
|
Chris@16
|
227 {
|
Chris@16
|
228 public:
|
Chris@16
|
229 out_edge_iterator(leda::edge edge = 0,
|
Chris@16
|
230 const leda::graph* g = 0)
|
Chris@16
|
231 : base(edge), g(g) {}
|
Chris@16
|
232
|
Chris@16
|
233 private:
|
Chris@16
|
234 const leda::edge& dereference() const { return base; }
|
Chris@16
|
235
|
Chris@16
|
236 bool equal(const out_edge_iterator& other) const
|
Chris@16
|
237 { return base == other.base; }
|
Chris@16
|
238
|
Chris@16
|
239 void increment() { base = g->adj_succ(base); }
|
Chris@16
|
240 void decrement() { base = g->adj_pred(base); }
|
Chris@16
|
241
|
Chris@16
|
242 leda::edge base;
|
Chris@16
|
243 const leda::graph* g;
|
Chris@16
|
244
|
Chris@16
|
245 friend class iterator_core_access;
|
Chris@16
|
246 };
|
Chris@16
|
247
|
Chris@16
|
248 class in_edge_iterator
|
Chris@16
|
249 : public iterator_facade<in_edge_iterator,
|
Chris@16
|
250 leda::edge,
|
Chris@16
|
251 bidirectional_traversal_tag,
|
Chris@16
|
252 const leda::edge&,
|
Chris@16
|
253 const leda::edge*>
|
Chris@16
|
254 {
|
Chris@16
|
255 public:
|
Chris@16
|
256 in_edge_iterator(leda::edge edge = 0,
|
Chris@16
|
257 const leda::graph* g = 0)
|
Chris@16
|
258 : base(edge), g(g) {}
|
Chris@16
|
259
|
Chris@16
|
260 private:
|
Chris@16
|
261 const leda::edge& dereference() const { return base; }
|
Chris@16
|
262
|
Chris@16
|
263 bool equal(const in_edge_iterator& other) const
|
Chris@16
|
264 { return base == other.base; }
|
Chris@16
|
265
|
Chris@16
|
266 void increment() { base = g->in_succ(base); }
|
Chris@16
|
267 void decrement() { base = g->in_pred(base); }
|
Chris@16
|
268
|
Chris@16
|
269 leda::edge base;
|
Chris@16
|
270 const leda::graph* g;
|
Chris@16
|
271
|
Chris@16
|
272 friend class iterator_core_access;
|
Chris@16
|
273 };
|
Chris@16
|
274
|
Chris@16
|
275 class vertex_iterator
|
Chris@16
|
276 : public iterator_facade<vertex_iterator,
|
Chris@16
|
277 leda::node,
|
Chris@16
|
278 bidirectional_traversal_tag,
|
Chris@16
|
279 const leda::node&,
|
Chris@16
|
280 const leda::node*>
|
Chris@16
|
281 {
|
Chris@16
|
282 public:
|
Chris@16
|
283 vertex_iterator(leda::node node = 0,
|
Chris@16
|
284 const leda::graph* g = 0)
|
Chris@16
|
285 : base(node), g(g) {}
|
Chris@16
|
286
|
Chris@16
|
287 private:
|
Chris@16
|
288 const leda::node& dereference() const { return base; }
|
Chris@16
|
289
|
Chris@16
|
290 bool equal(const vertex_iterator& other) const
|
Chris@16
|
291 { return base == other.base; }
|
Chris@16
|
292
|
Chris@16
|
293 void increment() { base = g->succ_node(base); }
|
Chris@16
|
294 void decrement() { base = g->pred_node(base); }
|
Chris@16
|
295
|
Chris@16
|
296 leda::node base;
|
Chris@16
|
297 const leda::graph* g;
|
Chris@16
|
298
|
Chris@16
|
299 friend class iterator_core_access;
|
Chris@16
|
300 };
|
Chris@16
|
301
|
Chris@16
|
302 class edge_iterator
|
Chris@16
|
303 : public iterator_facade<edge_iterator,
|
Chris@16
|
304 leda::edge,
|
Chris@16
|
305 bidirectional_traversal_tag,
|
Chris@16
|
306 const leda::edge&,
|
Chris@16
|
307 const leda::edge*>
|
Chris@16
|
308 {
|
Chris@16
|
309 public:
|
Chris@16
|
310 edge_iterator(leda::edge edge = 0,
|
Chris@16
|
311 const leda::graph* g = 0)
|
Chris@16
|
312 : base(edge), g(g) {}
|
Chris@16
|
313
|
Chris@16
|
314 private:
|
Chris@16
|
315 const leda::edge& dereference() const { return base; }
|
Chris@16
|
316
|
Chris@16
|
317 bool equal(const edge_iterator& other) const
|
Chris@16
|
318 { return base == other.base; }
|
Chris@16
|
319
|
Chris@16
|
320 void increment() { base = g->succ_edge(base); }
|
Chris@16
|
321 void decrement() { base = g->pred_edge(base); }
|
Chris@16
|
322
|
Chris@16
|
323 leda::edge base;
|
Chris@16
|
324 const leda::graph* g;
|
Chris@16
|
325
|
Chris@16
|
326 friend class iterator_core_access;
|
Chris@16
|
327 };
|
Chris@16
|
328
|
Chris@16
|
329 typedef directed_tag directed_category;
|
Chris@16
|
330 typedef allow_parallel_edge_tag edge_parallel_category; // not sure here
|
Chris@16
|
331 typedef leda_graph_traversal_category traversal_category;
|
Chris@16
|
332 typedef int vertices_size_type;
|
Chris@16
|
333 typedef int edges_size_type;
|
Chris@16
|
334 typedef int degree_size_type;
|
Chris@16
|
335 };
|
Chris@16
|
336
|
Chris@16
|
337 } // namespace boost
|
Chris@16
|
338
|
Chris@16
|
339 namespace boost {
|
Chris@16
|
340
|
Chris@16
|
341 //===========================================================================
|
Chris@16
|
342 // functions for GRAPH<vtype,etype>
|
Chris@16
|
343
|
Chris@16
|
344 template <class vtype, class etype>
|
Chris@16
|
345 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
|
Chris@16
|
346 source(typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor e,
|
Chris@16
|
347 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
348 {
|
Chris@16
|
349 return source(e);
|
Chris@16
|
350 }
|
Chris@16
|
351
|
Chris@16
|
352 template <class vtype, class etype>
|
Chris@16
|
353 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
|
Chris@16
|
354 target(typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor e,
|
Chris@16
|
355 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
356 {
|
Chris@16
|
357 return target(e);
|
Chris@16
|
358 }
|
Chris@16
|
359
|
Chris@16
|
360 template <class vtype, class etype>
|
Chris@16
|
361 inline std::pair<
|
Chris@16
|
362 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_iterator,
|
Chris@16
|
363 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_iterator >
|
Chris@16
|
364 vertices(const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
365 {
|
Chris@16
|
366 typedef typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_iterator
|
Chris@16
|
367 Iter;
|
Chris@16
|
368 return std::make_pair( Iter(g.first_node(),&g), Iter(0,&g) );
|
Chris@16
|
369 }
|
Chris@16
|
370
|
Chris@16
|
371 template <class vtype, class etype>
|
Chris@16
|
372 inline std::pair<
|
Chris@16
|
373 typename graph_traits< leda::GRAPH<vtype,etype> >::edge_iterator,
|
Chris@16
|
374 typename graph_traits< leda::GRAPH<vtype,etype> >::edge_iterator >
|
Chris@16
|
375 edges(const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
376 {
|
Chris@16
|
377 typedef typename graph_traits< leda::GRAPH<vtype,etype> >::edge_iterator
|
Chris@16
|
378 Iter;
|
Chris@16
|
379 return std::make_pair( Iter(g.first_edge(),&g), Iter(0,&g) );
|
Chris@16
|
380 }
|
Chris@16
|
381
|
Chris@16
|
382 template <class vtype, class etype>
|
Chris@16
|
383 inline std::pair<
|
Chris@16
|
384 typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator,
|
Chris@16
|
385 typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator >
|
Chris@16
|
386 out_edges(
|
Chris@16
|
387 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
388 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
389 {
|
Chris@16
|
390 typedef typename graph_traits< leda::GRAPH<vtype,etype> >
|
Chris@16
|
391 ::out_edge_iterator Iter;
|
Chris@16
|
392 return std::make_pair( Iter(g.first_adj_edge(u,0),&g), Iter(0,&g) );
|
Chris@16
|
393 }
|
Chris@16
|
394
|
Chris@16
|
395 template <class vtype, class etype>
|
Chris@16
|
396 inline std::pair<
|
Chris@16
|
397 typename graph_traits< leda::GRAPH<vtype,etype> >::in_edge_iterator,
|
Chris@16
|
398 typename graph_traits< leda::GRAPH<vtype,etype> >::in_edge_iterator >
|
Chris@16
|
399 in_edges(
|
Chris@16
|
400 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
401 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
402 {
|
Chris@16
|
403 typedef typename graph_traits< leda::GRAPH<vtype,etype> >
|
Chris@16
|
404 ::in_edge_iterator Iter;
|
Chris@16
|
405 return std::make_pair( Iter(g.first_adj_edge(u,1),&g), Iter(0,&g) );
|
Chris@16
|
406 }
|
Chris@16
|
407
|
Chris@16
|
408 template <class vtype, class etype>
|
Chris@16
|
409 inline std::pair<
|
Chris@16
|
410 typename graph_traits< leda::GRAPH<vtype,etype> >::adjacency_iterator,
|
Chris@16
|
411 typename graph_traits< leda::GRAPH<vtype,etype> >::adjacency_iterator >
|
Chris@16
|
412 adjacent_vertices(
|
Chris@16
|
413 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
414 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
415 {
|
Chris@16
|
416 typedef typename graph_traits< leda::GRAPH<vtype,etype> >
|
Chris@16
|
417 ::adjacency_iterator Iter;
|
Chris@16
|
418 return std::make_pair( Iter(g.first_adj_edge(u,0),&g), Iter(0,&g) );
|
Chris@16
|
419 }
|
Chris@16
|
420
|
Chris@16
|
421 template <class vtype, class etype>
|
Chris@16
|
422 typename graph_traits< leda::GRAPH<vtype,etype> >::vertices_size_type
|
Chris@16
|
423 num_vertices(const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
424 {
|
Chris@16
|
425 return g.number_of_nodes();
|
Chris@16
|
426 }
|
Chris@16
|
427
|
Chris@16
|
428 template <class vtype, class etype>
|
Chris@16
|
429 typename graph_traits< leda::GRAPH<vtype,etype> >::edges_size_type
|
Chris@16
|
430 num_edges(const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
431 {
|
Chris@16
|
432 return g.number_of_edges();
|
Chris@16
|
433 }
|
Chris@16
|
434
|
Chris@16
|
435 template <class vtype, class etype>
|
Chris@16
|
436 typename graph_traits< leda::GRAPH<vtype,etype> >::degree_size_type
|
Chris@16
|
437 out_degree(
|
Chris@16
|
438 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
439 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
440 {
|
Chris@16
|
441 return g.outdeg(u);
|
Chris@16
|
442 }
|
Chris@16
|
443
|
Chris@16
|
444 template <class vtype, class etype>
|
Chris@16
|
445 typename graph_traits< leda::GRAPH<vtype,etype> >::degree_size_type
|
Chris@16
|
446 in_degree(
|
Chris@16
|
447 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
448 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
449 {
|
Chris@16
|
450 return g.indeg(u);
|
Chris@16
|
451 }
|
Chris@16
|
452
|
Chris@16
|
453 template <class vtype, class etype>
|
Chris@16
|
454 typename graph_traits< leda::GRAPH<vtype,etype> >::degree_size_type
|
Chris@16
|
455 degree(
|
Chris@16
|
456 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
457 const leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
458 {
|
Chris@16
|
459 return g.outdeg(u) + g.indeg(u);
|
Chris@16
|
460 }
|
Chris@16
|
461
|
Chris@16
|
462 template <class vtype, class etype>
|
Chris@16
|
463 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
|
Chris@16
|
464 add_vertex(leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
465 {
|
Chris@16
|
466 return g.new_node();
|
Chris@16
|
467 }
|
Chris@16
|
468
|
Chris@16
|
469 template <class vtype, class etype>
|
Chris@16
|
470 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
|
Chris@16
|
471 add_vertex(const vtype& vp, leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
472 {
|
Chris@16
|
473 return g.new_node(vp);
|
Chris@16
|
474 }
|
Chris@16
|
475
|
Chris@16
|
476 template <class vtype, class etype>
|
Chris@16
|
477 void clear_vertex(
|
Chris@16
|
478 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
479 leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
480 {
|
Chris@16
|
481 typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator ei, ei_end;
|
Chris@16
|
482 for (boost::tie(ei, ei_end)=out_edges(u,g); ei!=ei_end; ei++)
|
Chris@16
|
483 remove_edge(*ei);
|
Chris@16
|
484
|
Chris@16
|
485 typename graph_traits< leda::GRAPH<vtype,etype> >::in_edge_iterator iei, iei_end;
|
Chris@16
|
486 for (boost::tie(iei, iei_end)=in_edges(u,g); iei!=iei_end; iei++)
|
Chris@16
|
487 remove_edge(*iei);
|
Chris@16
|
488 }
|
Chris@16
|
489
|
Chris@16
|
490 template <class vtype, class etype>
|
Chris@16
|
491 void remove_vertex(
|
Chris@16
|
492 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
493 leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
494 {
|
Chris@16
|
495 g.del_node(u);
|
Chris@16
|
496 }
|
Chris@16
|
497
|
Chris@16
|
498 template <class vtype, class etype>
|
Chris@16
|
499 std::pair<
|
Chris@16
|
500 typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor,
|
Chris@16
|
501 bool>
|
Chris@16
|
502 add_edge(
|
Chris@16
|
503 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
504 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor v,
|
Chris@16
|
505 leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
506 {
|
Chris@16
|
507 return std::make_pair(g.new_edge(u, v), true);
|
Chris@16
|
508 }
|
Chris@16
|
509
|
Chris@16
|
510 template <class vtype, class etype>
|
Chris@16
|
511 std::pair<
|
Chris@16
|
512 typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor,
|
Chris@16
|
513 bool>
|
Chris@16
|
514 add_edge(
|
Chris@16
|
515 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
516 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor v,
|
Chris@16
|
517 const etype& et,
|
Chris@16
|
518 leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
519 {
|
Chris@16
|
520 return std::make_pair(g.new_edge(u, v, et), true);
|
Chris@16
|
521 }
|
Chris@16
|
522
|
Chris@16
|
523 template <class vtype, class etype>
|
Chris@16
|
524 void
|
Chris@16
|
525 remove_edge(
|
Chris@16
|
526 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
|
Chris@16
|
527 typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor v,
|
Chris@16
|
528 leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
529 {
|
Chris@16
|
530 typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator
|
Chris@16
|
531 i,iend;
|
Chris@16
|
532 for (boost::tie(i,iend) = out_edges(u,g); i != iend; ++i)
|
Chris@16
|
533 if (target(*i,g) == v)
|
Chris@16
|
534 g.del_edge(*i);
|
Chris@16
|
535 }
|
Chris@16
|
536
|
Chris@16
|
537 template <class vtype, class etype>
|
Chris@16
|
538 void
|
Chris@16
|
539 remove_edge(
|
Chris@16
|
540 typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor e,
|
Chris@16
|
541 leda::GRAPH<vtype,etype>& g)
|
Chris@16
|
542 {
|
Chris@16
|
543 g.del_edge(e);
|
Chris@16
|
544 }
|
Chris@16
|
545
|
Chris@16
|
546 //===========================================================================
|
Chris@16
|
547 // functions for graph (non-templated version)
|
Chris@16
|
548
|
Chris@16
|
549 graph_traits<leda::graph>::vertex_descriptor
|
Chris@16
|
550 source(graph_traits<leda::graph>::edge_descriptor e,
|
Chris@16
|
551 const leda::graph& g)
|
Chris@16
|
552 {
|
Chris@16
|
553 return source(e);
|
Chris@16
|
554 }
|
Chris@16
|
555
|
Chris@16
|
556 graph_traits<leda::graph>::vertex_descriptor
|
Chris@16
|
557 target(graph_traits<leda::graph>::edge_descriptor e,
|
Chris@16
|
558 const leda::graph& g)
|
Chris@16
|
559 {
|
Chris@16
|
560 return target(e);
|
Chris@16
|
561 }
|
Chris@16
|
562
|
Chris@16
|
563 inline std::pair<
|
Chris@16
|
564 graph_traits<leda::graph>::vertex_iterator,
|
Chris@16
|
565 graph_traits<leda::graph>::vertex_iterator >
|
Chris@16
|
566 vertices(const leda::graph& g)
|
Chris@16
|
567 {
|
Chris@16
|
568 typedef graph_traits<leda::graph>::vertex_iterator
|
Chris@16
|
569 Iter;
|
Chris@16
|
570 return std::make_pair( Iter(g.first_node(),&g), Iter(0,&g) );
|
Chris@16
|
571 }
|
Chris@16
|
572
|
Chris@16
|
573 inline std::pair<
|
Chris@16
|
574 graph_traits<leda::graph>::edge_iterator,
|
Chris@16
|
575 graph_traits<leda::graph>::edge_iterator >
|
Chris@16
|
576 edges(const leda::graph& g)
|
Chris@16
|
577 {
|
Chris@16
|
578 typedef graph_traits<leda::graph>::edge_iterator
|
Chris@16
|
579 Iter;
|
Chris@16
|
580 return std::make_pair( Iter(g.first_edge(),&g), Iter(0,&g) );
|
Chris@16
|
581 }
|
Chris@16
|
582
|
Chris@16
|
583 inline std::pair<
|
Chris@16
|
584 graph_traits<leda::graph>::out_edge_iterator,
|
Chris@16
|
585 graph_traits<leda::graph>::out_edge_iterator >
|
Chris@16
|
586 out_edges(
|
Chris@16
|
587 graph_traits<leda::graph>::vertex_descriptor u, const leda::graph& g)
|
Chris@16
|
588 {
|
Chris@16
|
589 typedef graph_traits<leda::graph>::out_edge_iterator Iter;
|
Chris@16
|
590 return std::make_pair( Iter(g.first_adj_edge(u),&g), Iter(0,&g) );
|
Chris@16
|
591 }
|
Chris@16
|
592
|
Chris@16
|
593 inline std::pair<
|
Chris@16
|
594 graph_traits<leda::graph>::in_edge_iterator,
|
Chris@16
|
595 graph_traits<leda::graph>::in_edge_iterator >
|
Chris@16
|
596 in_edges(
|
Chris@16
|
597 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
598 const leda::graph& g)
|
Chris@16
|
599 {
|
Chris@16
|
600 typedef graph_traits<leda::graph>
|
Chris@16
|
601 ::in_edge_iterator Iter;
|
Chris@16
|
602 return std::make_pair( Iter(g.first_in_edge(u),&g), Iter(0,&g) );
|
Chris@16
|
603 }
|
Chris@16
|
604
|
Chris@16
|
605 inline std::pair<
|
Chris@16
|
606 graph_traits<leda::graph>::adjacency_iterator,
|
Chris@16
|
607 graph_traits<leda::graph>::adjacency_iterator >
|
Chris@16
|
608 adjacent_vertices(
|
Chris@16
|
609 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
610 const leda::graph& g)
|
Chris@16
|
611 {
|
Chris@16
|
612 typedef graph_traits<leda::graph>
|
Chris@16
|
613 ::adjacency_iterator Iter;
|
Chris@16
|
614 return std::make_pair( Iter(g.first_adj_edge(u),&g), Iter(0,&g) );
|
Chris@16
|
615 }
|
Chris@16
|
616
|
Chris@16
|
617 graph_traits<leda::graph>::vertices_size_type
|
Chris@16
|
618 num_vertices(const leda::graph& g)
|
Chris@16
|
619 {
|
Chris@16
|
620 return g.number_of_nodes();
|
Chris@16
|
621 }
|
Chris@16
|
622
|
Chris@16
|
623 graph_traits<leda::graph>::edges_size_type
|
Chris@16
|
624 num_edges(const leda::graph& g)
|
Chris@16
|
625 {
|
Chris@16
|
626 return g.number_of_edges();
|
Chris@16
|
627 }
|
Chris@16
|
628
|
Chris@16
|
629 graph_traits<leda::graph>::degree_size_type
|
Chris@16
|
630 out_degree(
|
Chris@16
|
631 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
632 const leda::graph& g)
|
Chris@16
|
633 {
|
Chris@16
|
634 return g.outdeg(u);
|
Chris@16
|
635 }
|
Chris@16
|
636
|
Chris@16
|
637 graph_traits<leda::graph>::degree_size_type
|
Chris@16
|
638 in_degree(
|
Chris@16
|
639 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
640 const leda::graph& g)
|
Chris@16
|
641 {
|
Chris@16
|
642 return g.indeg(u);
|
Chris@16
|
643 }
|
Chris@16
|
644
|
Chris@16
|
645 graph_traits<leda::graph>::degree_size_type
|
Chris@16
|
646 degree(
|
Chris@16
|
647 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
648 const leda::graph& g)
|
Chris@16
|
649 {
|
Chris@16
|
650 return g.outdeg(u) + g.indeg(u);
|
Chris@16
|
651 }
|
Chris@16
|
652
|
Chris@16
|
653 graph_traits<leda::graph>::vertex_descriptor
|
Chris@16
|
654 add_vertex(leda::graph& g)
|
Chris@16
|
655 {
|
Chris@16
|
656 return g.new_node();
|
Chris@16
|
657 }
|
Chris@16
|
658
|
Chris@16
|
659 void
|
Chris@16
|
660 remove_edge(
|
Chris@16
|
661 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
662 graph_traits<leda::graph>::vertex_descriptor v,
|
Chris@16
|
663 leda::graph& g)
|
Chris@16
|
664 {
|
Chris@16
|
665 graph_traits<leda::graph>::out_edge_iterator
|
Chris@16
|
666 i,iend;
|
Chris@16
|
667 for (boost::tie(i,iend) = out_edges(u,g); i != iend; ++i)
|
Chris@16
|
668 if (target(*i,g) == v)
|
Chris@16
|
669 g.del_edge(*i);
|
Chris@16
|
670 }
|
Chris@16
|
671
|
Chris@16
|
672 void
|
Chris@16
|
673 remove_edge(
|
Chris@16
|
674 graph_traits<leda::graph>::edge_descriptor e,
|
Chris@16
|
675 leda::graph& g)
|
Chris@16
|
676 {
|
Chris@16
|
677 g.del_edge(e);
|
Chris@16
|
678 }
|
Chris@16
|
679
|
Chris@16
|
680 void clear_vertex(
|
Chris@16
|
681 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
682 leda::graph& g)
|
Chris@16
|
683 {
|
Chris@16
|
684 graph_traits<leda::graph>::out_edge_iterator ei, ei_end;
|
Chris@16
|
685 for (boost::tie(ei, ei_end)=out_edges(u,g); ei!=ei_end; ei++)
|
Chris@16
|
686 remove_edge(*ei, g);
|
Chris@16
|
687
|
Chris@16
|
688 graph_traits<leda::graph>::in_edge_iterator iei, iei_end;
|
Chris@16
|
689 for (boost::tie(iei, iei_end)=in_edges(u,g); iei!=iei_end; iei++)
|
Chris@16
|
690 remove_edge(*iei, g);
|
Chris@16
|
691 }
|
Chris@16
|
692
|
Chris@16
|
693 void remove_vertex(
|
Chris@16
|
694 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
695 leda::graph& g)
|
Chris@16
|
696 {
|
Chris@16
|
697 g.del_node(u);
|
Chris@16
|
698 }
|
Chris@16
|
699
|
Chris@16
|
700 std::pair<
|
Chris@16
|
701 graph_traits<leda::graph>::edge_descriptor,
|
Chris@16
|
702 bool>
|
Chris@16
|
703 add_edge(
|
Chris@16
|
704 graph_traits<leda::graph>::vertex_descriptor u,
|
Chris@16
|
705 graph_traits<leda::graph>::vertex_descriptor v,
|
Chris@16
|
706 leda::graph& g)
|
Chris@16
|
707 {
|
Chris@16
|
708 return std::make_pair(g.new_edge(u, v), true);
|
Chris@16
|
709 }
|
Chris@16
|
710
|
Chris@16
|
711
|
Chris@16
|
712 //===========================================================================
|
Chris@16
|
713 // property maps for GRAPH<vtype,etype>
|
Chris@16
|
714
|
Chris@16
|
715 class leda_graph_id_map
|
Chris@16
|
716 : public put_get_helper<int, leda_graph_id_map>
|
Chris@16
|
717 {
|
Chris@16
|
718 public:
|
Chris@16
|
719 typedef readable_property_map_tag category;
|
Chris@16
|
720 typedef int value_type;
|
Chris@16
|
721 typedef int reference;
|
Chris@16
|
722 typedef leda::node key_type;
|
Chris@16
|
723 leda_graph_id_map() { }
|
Chris@16
|
724 template <class T>
|
Chris@16
|
725 long operator[](T x) const { return x->id(); }
|
Chris@16
|
726 };
|
Chris@16
|
727 template <class vtype, class etype>
|
Chris@16
|
728 inline leda_graph_id_map
|
Chris@16
|
729 get(vertex_index_t, const leda::GRAPH<vtype, etype>& g) {
|
Chris@16
|
730 return leda_graph_id_map();
|
Chris@16
|
731 }
|
Chris@16
|
732 template <class vtype, class etype>
|
Chris@16
|
733 inline leda_graph_id_map
|
Chris@16
|
734 get(edge_index_t, const leda::GRAPH<vtype, etype>& g) {
|
Chris@16
|
735 return leda_graph_id_map();
|
Chris@16
|
736 }
|
Chris@16
|
737
|
Chris@16
|
738 template <class Tag>
|
Chris@16
|
739 struct leda_property_map { };
|
Chris@16
|
740
|
Chris@16
|
741 template <>
|
Chris@16
|
742 struct leda_property_map<vertex_index_t> {
|
Chris@16
|
743 template <class vtype, class etype>
|
Chris@16
|
744 struct bind_ {
|
Chris@16
|
745 typedef leda_graph_id_map type;
|
Chris@16
|
746 typedef leda_graph_id_map const_type;
|
Chris@16
|
747 };
|
Chris@16
|
748 };
|
Chris@16
|
749 template <>
|
Chris@16
|
750 struct leda_property_map<edge_index_t> {
|
Chris@16
|
751 template <class vtype, class etype>
|
Chris@16
|
752 struct bind_ {
|
Chris@16
|
753 typedef leda_graph_id_map type;
|
Chris@16
|
754 typedef leda_graph_id_map const_type;
|
Chris@16
|
755 };
|
Chris@16
|
756 };
|
Chris@16
|
757
|
Chris@16
|
758
|
Chris@16
|
759 template <class Data, class DataRef, class GraphPtr>
|
Chris@16
|
760 class leda_graph_data_map
|
Chris@16
|
761 : public put_get_helper<DataRef,
|
Chris@16
|
762 leda_graph_data_map<Data,DataRef,GraphPtr> >
|
Chris@16
|
763 {
|
Chris@16
|
764 public:
|
Chris@16
|
765 typedef Data value_type;
|
Chris@16
|
766 typedef DataRef reference;
|
Chris@16
|
767 typedef void key_type;
|
Chris@16
|
768 typedef lvalue_property_map_tag category;
|
Chris@16
|
769 leda_graph_data_map(GraphPtr g) : m_g(g) { }
|
Chris@16
|
770 template <class NodeOrEdge>
|
Chris@16
|
771 DataRef operator[](NodeOrEdge x) const { return (*m_g)[x]; }
|
Chris@16
|
772 protected:
|
Chris@16
|
773 GraphPtr m_g;
|
Chris@16
|
774 };
|
Chris@16
|
775
|
Chris@16
|
776 template <>
|
Chris@16
|
777 struct leda_property_map<vertex_all_t> {
|
Chris@16
|
778 template <class vtype, class etype>
|
Chris@16
|
779 struct bind_ {
|
Chris@16
|
780 typedef leda_graph_data_map<vtype, vtype&, leda::GRAPH<vtype, etype>*> type;
|
Chris@16
|
781 typedef leda_graph_data_map<vtype, const vtype&,
|
Chris@16
|
782 const leda::GRAPH<vtype, etype>*> const_type;
|
Chris@16
|
783 };
|
Chris@16
|
784 };
|
Chris@16
|
785 template <class vtype, class etype >
|
Chris@16
|
786 inline typename property_map< leda::GRAPH<vtype, etype>, vertex_all_t>::type
|
Chris@16
|
787 get(vertex_all_t, leda::GRAPH<vtype, etype>& g) {
|
Chris@16
|
788 typedef typename property_map< leda::GRAPH<vtype, etype>, vertex_all_t>::type
|
Chris@16
|
789 pmap_type;
|
Chris@16
|
790 return pmap_type(&g);
|
Chris@16
|
791 }
|
Chris@16
|
792 template <class vtype, class etype >
|
Chris@16
|
793 inline typename property_map< leda::GRAPH<vtype, etype>, vertex_all_t>::const_type
|
Chris@16
|
794 get(vertex_all_t, const leda::GRAPH<vtype, etype>& g) {
|
Chris@16
|
795 typedef typename property_map< leda::GRAPH<vtype, etype>,
|
Chris@16
|
796 vertex_all_t>::const_type pmap_type;
|
Chris@16
|
797 return pmap_type(&g);
|
Chris@16
|
798 }
|
Chris@16
|
799
|
Chris@16
|
800 template <>
|
Chris@16
|
801 struct leda_property_map<edge_all_t> {
|
Chris@16
|
802 template <class vtype, class etype>
|
Chris@16
|
803 struct bind_ {
|
Chris@16
|
804 typedef leda_graph_data_map<etype, etype&, leda::GRAPH<vtype, etype>*> type;
|
Chris@16
|
805 typedef leda_graph_data_map<etype, const etype&,
|
Chris@16
|
806 const leda::GRAPH<vtype, etype>*> const_type;
|
Chris@16
|
807 };
|
Chris@16
|
808 };
|
Chris@16
|
809 template <class vtype, class etype >
|
Chris@16
|
810 inline typename property_map< leda::GRAPH<vtype, etype>, edge_all_t>::type
|
Chris@16
|
811 get(edge_all_t, leda::GRAPH<vtype, etype>& g) {
|
Chris@16
|
812 typedef typename property_map< leda::GRAPH<vtype, etype>, edge_all_t>::type
|
Chris@16
|
813 pmap_type;
|
Chris@16
|
814 return pmap_type(&g);
|
Chris@16
|
815 }
|
Chris@16
|
816 template <class vtype, class etype >
|
Chris@16
|
817 inline typename property_map< leda::GRAPH<vtype, etype>, edge_all_t>::const_type
|
Chris@16
|
818 get(edge_all_t, const leda::GRAPH<vtype, etype>& g) {
|
Chris@16
|
819 typedef typename property_map< leda::GRAPH<vtype, etype>,
|
Chris@16
|
820 edge_all_t>::const_type pmap_type;
|
Chris@16
|
821 return pmap_type(&g);
|
Chris@16
|
822 }
|
Chris@16
|
823
|
Chris@16
|
824 // property map interface to the LEDA node_array class
|
Chris@16
|
825
|
Chris@16
|
826 template <class E, class ERef, class NodeMapPtr>
|
Chris@16
|
827 class leda_node_property_map
|
Chris@16
|
828 : public put_get_helper<ERef, leda_node_property_map<E, ERef, NodeMapPtr> >
|
Chris@16
|
829 {
|
Chris@16
|
830 public:
|
Chris@16
|
831 typedef E value_type;
|
Chris@16
|
832 typedef ERef reference;
|
Chris@16
|
833 typedef leda::node key_type;
|
Chris@16
|
834 typedef lvalue_property_map_tag category;
|
Chris@16
|
835 leda_node_property_map(NodeMapPtr a) : m_array(a) { }
|
Chris@16
|
836 ERef operator[](leda::node n) const { return (*m_array)[n]; }
|
Chris@16
|
837 protected:
|
Chris@16
|
838 NodeMapPtr m_array;
|
Chris@16
|
839 };
|
Chris@16
|
840 template <class E>
|
Chris@16
|
841 leda_node_property_map<E, const E&, const leda::node_array<E>*>
|
Chris@16
|
842 make_leda_node_property_map(const leda::node_array<E>& a)
|
Chris@16
|
843 {
|
Chris@16
|
844 typedef leda_node_property_map<E, const E&, const leda::node_array<E>*>
|
Chris@16
|
845 pmap_type;
|
Chris@16
|
846 return pmap_type(&a);
|
Chris@16
|
847 }
|
Chris@16
|
848 template <class E>
|
Chris@16
|
849 leda_node_property_map<E, E&, leda::node_array<E>*>
|
Chris@16
|
850 make_leda_node_property_map(leda::node_array<E>& a)
|
Chris@16
|
851 {
|
Chris@16
|
852 typedef leda_node_property_map<E, E&, leda::node_array<E>*> pmap_type;
|
Chris@16
|
853 return pmap_type(&a);
|
Chris@16
|
854 }
|
Chris@16
|
855
|
Chris@16
|
856 template <class E>
|
Chris@16
|
857 leda_node_property_map<E, const E&, const leda::node_map<E>*>
|
Chris@16
|
858 make_leda_node_property_map(const leda::node_map<E>& a)
|
Chris@16
|
859 {
|
Chris@16
|
860 typedef leda_node_property_map<E,const E&,const leda::node_map<E>*>
|
Chris@16
|
861 pmap_type;
|
Chris@16
|
862 return pmap_type(&a);
|
Chris@16
|
863 }
|
Chris@16
|
864 template <class E>
|
Chris@16
|
865 leda_node_property_map<E, E&, leda::node_map<E>*>
|
Chris@16
|
866 make_leda_node_property_map(leda::node_map<E>& a)
|
Chris@16
|
867 {
|
Chris@16
|
868 typedef leda_node_property_map<E, E&, leda::node_map<E>*> pmap_type;
|
Chris@16
|
869 return pmap_type(&a);
|
Chris@16
|
870 }
|
Chris@16
|
871
|
Chris@16
|
872 // g++ 'enumeral_type' in template unification not implemented workaround
|
Chris@16
|
873 template <class vtype, class etype, class Tag>
|
Chris@16
|
874 struct property_map<leda::GRAPH<vtype, etype>, Tag> {
|
Chris@16
|
875 typedef typename
|
Chris@16
|
876 leda_property_map<Tag>::template bind_<vtype, etype> map_gen;
|
Chris@16
|
877 typedef typename map_gen::type type;
|
Chris@16
|
878 typedef typename map_gen::const_type const_type;
|
Chris@16
|
879 };
|
Chris@16
|
880
|
Chris@16
|
881 template <class vtype, class etype, class PropertyTag, class Key>
|
Chris@16
|
882 inline
|
Chris@16
|
883 typename boost::property_traits<
|
Chris@16
|
884 typename boost::property_map<leda::GRAPH<vtype, etype>,PropertyTag>::const_type
|
Chris@16
|
885 >::value_type
|
Chris@16
|
886 get(PropertyTag p, const leda::GRAPH<vtype, etype>& g, const Key& key) {
|
Chris@16
|
887 return get(get(p, g), key);
|
Chris@16
|
888 }
|
Chris@16
|
889
|
Chris@16
|
890 template <class vtype, class etype, class PropertyTag, class Key,class Value>
|
Chris@16
|
891 inline void
|
Chris@16
|
892 put(PropertyTag p, leda::GRAPH<vtype, etype>& g,
|
Chris@16
|
893 const Key& key, const Value& value)
|
Chris@16
|
894 {
|
Chris@16
|
895 typedef typename property_map<leda::GRAPH<vtype, etype>, PropertyTag>::type Map;
|
Chris@16
|
896 Map pmap = get(p, g);
|
Chris@16
|
897 put(pmap, key, value);
|
Chris@16
|
898 }
|
Chris@16
|
899
|
Chris@16
|
900 // property map interface to the LEDA edge_array class
|
Chris@16
|
901
|
Chris@16
|
902 template <class E, class ERef, class EdgeMapPtr>
|
Chris@16
|
903 class leda_edge_property_map
|
Chris@16
|
904 : public put_get_helper<ERef, leda_edge_property_map<E, ERef, EdgeMapPtr> >
|
Chris@16
|
905 {
|
Chris@16
|
906 public:
|
Chris@16
|
907 typedef E value_type;
|
Chris@16
|
908 typedef ERef reference;
|
Chris@16
|
909 typedef leda::edge key_type;
|
Chris@16
|
910 typedef lvalue_property_map_tag category;
|
Chris@16
|
911 leda_edge_property_map(EdgeMapPtr a) : m_array(a) { }
|
Chris@16
|
912 ERef operator[](leda::edge n) const { return (*m_array)[n]; }
|
Chris@16
|
913 protected:
|
Chris@16
|
914 EdgeMapPtr m_array;
|
Chris@16
|
915 };
|
Chris@16
|
916 template <class E>
|
Chris@16
|
917 leda_edge_property_map<E, const E&, const leda::edge_array<E>*>
|
Chris@16
|
918 make_leda_node_property_map(const leda::node_array<E>& a)
|
Chris@16
|
919 {
|
Chris@16
|
920 typedef leda_edge_property_map<E, const E&, const leda::node_array<E>*>
|
Chris@16
|
921 pmap_type;
|
Chris@16
|
922 return pmap_type(&a);
|
Chris@16
|
923 }
|
Chris@16
|
924 template <class E>
|
Chris@16
|
925 leda_edge_property_map<E, E&, leda::edge_array<E>*>
|
Chris@16
|
926 make_leda_edge_property_map(leda::edge_array<E>& a)
|
Chris@16
|
927 {
|
Chris@16
|
928 typedef leda_edge_property_map<E, E&, leda::edge_array<E>*> pmap_type;
|
Chris@16
|
929 return pmap_type(&a);
|
Chris@16
|
930 }
|
Chris@16
|
931
|
Chris@16
|
932 template <class E>
|
Chris@16
|
933 leda_edge_property_map<E, const E&, const leda::edge_map<E>*>
|
Chris@16
|
934 make_leda_edge_property_map(const leda::edge_map<E>& a)
|
Chris@16
|
935 {
|
Chris@16
|
936 typedef leda_edge_property_map<E,const E&,const leda::edge_map<E>*>
|
Chris@16
|
937 pmap_type;
|
Chris@16
|
938 return pmap_type(&a);
|
Chris@16
|
939 }
|
Chris@16
|
940 template <class E>
|
Chris@16
|
941 leda_edge_property_map<E, E&, leda::edge_map<E>*>
|
Chris@16
|
942 make_leda_edge_property_map(leda::edge_map<E>& a)
|
Chris@16
|
943 {
|
Chris@16
|
944 typedef leda_edge_property_map<E, E&, leda::edge_map<E>*> pmap_type;
|
Chris@16
|
945 return pmap_type(&a);
|
Chris@16
|
946 }
|
Chris@16
|
947
|
Chris@16
|
948 } // namespace boost
|
Chris@16
|
949
|
Chris@16
|
950 #endif // BOOST_GRAPH_LEDA_HPP
|