graph_analysis
NodeIterator.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_BOOST_GRAPH_NODE_ITERATOR_HPP
2 #define GRAPH_ANALYSIS_BOOST_GRAPH_NODE_ITERATOR_HPP
3 
4 #include "../VertexIterator.hpp"
5 
6 namespace graph_analysis {
7 namespace boost_graph {
8 
9 template<typename T>
11 {
12 public:
13  NodeIterator(const T& graph)
14  : mGraph(graph)
15  {
16  boost::tie(mStart, mEnd) = boost::vertices(mGraph.raw());
17  mCurrent = mStart;
18  }
19 
20  bool next()
21  {
22  while(mCurrent != mEnd)
23  {
24  VertexDescriptor vertexDescriptor = *mCurrent;
25  Vertex::Ptr vertex = mGraph.raw()[vertexDescriptor];
26  ++mCurrent;
27  if(skip(vertex))
28  {
29  continue;
30  }
31  setNext(vertex);
32  return true;
33  }
34  return false;
35  }
36 private:
37  const T& mGraph;
38 
39  VertexIteratorImpl mCurrent;
40  VertexIteratorImpl mStart;
41  VertexIteratorImpl mEnd;
42 };
43 
44 } // end namespace boost_graph
45 } // end namespace graph_analysis
46 #endif // GRAPH_ANALYSIS_BOOST_GRAPH_NODE_ITERATOR_HPP
graph_analysis::boost_graph::VertexDescriptor
boost::graph_traits< BidirectionalGraph >::vertex_descriptor VertexDescriptor
Definition: DirectedGraph.hpp:31
graph_analysis::boost_graph::NodeIterator::NodeIterator
NodeIterator(const T &graph)
Definition: NodeIterator.hpp:13
graph_analysis
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
graph_analysis::boost_graph::NodeIterator::next
bool next()
Test if there is a next item and if it is then updates the current to next.
Definition: NodeIterator.hpp:20
graph_analysis::Vertex::Ptr
shared_ptr< Vertex > Ptr
Definition: Vertex.hpp:22
graph_analysis::VertexIterator::skip
bool skip(const Vertex::Ptr &vertex) const
Definition: VertexIterator.cpp:5
graph_analysis::boost_graph::NodeIterator
Definition: NodeIterator.hpp:10
graph_analysis::VertexIterator::setNext
void setNext(const Vertex::Ptr &vertex)
Set next vertex Should be applied by class implementing next()
Definition: VertexIterator.hpp:49
graph_analysis::VertexIterator
VertexIterator interface Allows to access all vertices of a graph. Requires implementation to wrap th...
Definition: VertexIterator.hpp:15
graph_analysis::boost_graph::VertexIteratorImpl
boost::graph_traits< BidirectionalGraph >::vertex_iterator VertexIteratorImpl
Definition: DirectedGraph.hpp:32