graph_analysis
ArcIterator.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_LEMON_ARC_ITERATOR_HPP
2 #define GRAPH_ANALYSIS_LEMON_ARC_ITERATOR_HPP
3 
4 #include "../EdgeIterator.hpp"
5 #include "../Vertex.hpp"
6 
7 namespace graph_analysis {
8 namespace lemon {
9 
10 template<typename T>
11 class ArcIterator : public EdgeIterator
12 {
13 public:
14  ArcIterator(const T& graph)
15  : mGraph(graph)
16  , mArcIt(graph.raw())
17  {}
18 
19  bool next()
20  {
21  while( mArcIt != ::lemon::INVALID )
22  {
23  Edge::Ptr edge = mGraph.mEdgeMap[mArcIt];
24  ++mArcIt;
25  if(skip(edge))
26  {
27  continue;
28  }
29  setNext(edge);
30  return true;
31  }
32  return false;
33  }
34 
35 protected:
36  const T& mGraph;
37  typename T::graph_t::ArcIt mArcIt;
38 
39 };
40 
41 template<typename T>
43 {
44 public:
45  OutArcIterator(const T& graph, Vertex::Ptr vertex)
46  : mGraph(graph)
47  , mOutArcIt(graph.raw(), graph.raw().nodeFromId( vertex->getId(graph.getId())))
48  {}
49 
50  bool next()
51  {
52  while( mOutArcIt != ::lemon::INVALID )
53  {
54  Edge::Ptr edge = mGraph.mEdgeMap[mOutArcIt];
55  ++mOutArcIt;
56  if(skip(edge))
57  {
58  continue;
59  }
60  setNext(edge);
61  return true;
62  }
63  return false;
64  }
65 
66 protected:
67  const T& mGraph;
68  typename T::graph_t::OutArcIt mOutArcIt;
69 
70 };
71 
72 
73 template<typename T>
75 {
76 public:
77  InArcIterator(const T& graph, Vertex::Ptr vertex)
78  : mGraph(graph)
79  , mInArcIt(graph.raw(), graph.raw().nodeFromId( vertex->getId(graph.getId())))
80  {}
81 
82  bool next()
83  {
84  while( mInArcIt != ::lemon::INVALID )
85  {
86  Edge::Ptr edge = mGraph.mEdgeMap[mInArcIt];
87  if(skip(edge))
88  {
89  continue;
90  }
91  setNext(edge);
92  ++mInArcIt;
93  return true;
94  }
95  return false;
96  }
97 
98 protected:
99  const T& mGraph;
100  typename T::graph_t::InArcIt mInArcIt;
101 
102 };
103 
104 
105 template<typename T>
107 {
108 public:
109  InOutArcIterator(const T& graph, Vertex::Ptr vertex)
110  : mGraph(graph)
111  , mInArcIterator(graph, vertex)
112  , mOutArcIterator(graph, vertex)
113  {}
114 
115  bool next()
116  {
117  if(mInArcIterator.next())
118  {
119  setNext( mInArcIterator.current() );
120  return true;
121  }
122 
123  if(mOutArcIterator.next())
124  {
125  setNext( mOutArcIterator.current() );
126  return true;
127  }
128 
129  return false;
130  }
131 
132 
133 protected:
134  const T& mGraph;
137 };
138 
139 
140 } // end namespace lemon
141 } // end namespace graph_analysis
142 #endif // GRAPH_ANALYSIS_LEMON_ARC_ITERATOR_HPP
T::graph_t::ArcIt mArcIt
Definition: ArcIterator.hpp:37
Definition: ArcIterator.hpp:11
OutArcIterator(const T &graph, Vertex::Ptr vertex)
Definition: ArcIterator.hpp:45
Definition: ArcIterator.hpp:74
void setNext(const Edge::Ptr &edge)
Set next edge Should be applied by class implementing next()
Definition: EdgeIterator.hpp:48
shared_ptr< Edge > Ptr
Definition: Edge.hpp:21
bool next()
Test if there is a next item and if it is then updates the current to next.
Definition: ArcIterator.hpp:19
Definition: ArcIterator.hpp:106
bool next()
Test if there is a next item and if it is then updates the current to next.
Definition: ArcIterator.hpp:82
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
shared_ptr< Vertex > Ptr
Definition: Vertex.hpp:22
const T & mGraph
Definition: ArcIterator.hpp:67
Definition: ArcIterator.hpp:42
InOutArcIterator(const T &graph, Vertex::Ptr vertex)
Definition: ArcIterator.hpp:109
InArcIterator(const T &graph, Vertex::Ptr vertex)
Definition: ArcIterator.hpp:77
ArcIterator(const T &graph)
Definition: ArcIterator.hpp:14
const T & mGraph
Definition: ArcIterator.hpp:99
bool skip(const Edge::Ptr &edge) const
Check if edge should be skipped.
Definition: EdgeIterator.cpp:5
bool next()
Test if there is a next item and if it is then updates the current to next.
Definition: ArcIterator.hpp:115
T::graph_t::InArcIt mInArcIt
Definition: ArcIterator.hpp:100
OutArcIterator< T > mOutArcIterator
Definition: ArcIterator.hpp:136
bool next()
Test if there is a next item and if it is then updates the current to next.
Definition: ArcIterator.hpp:50
T::graph_t::OutArcIt mOutArcIt
Definition: ArcIterator.hpp:68
const T & mGraph
Definition: ArcIterator.hpp:36
EdgeIterator interface Allows to access all edges of a graph. Requires implementation to wrap the und...
Definition: EdgeIterator.hpp:14
InArcIterator< T > mInArcIterator
Definition: ArcIterator.hpp:135
const T & mGraph
Definition: ArcIterator.hpp:134