DGtal  0.9.4beta
Public Member Functions | Private Member Functions | Private Attributes | Friends
boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator Class Reference

#include <DGtal/graph/ObjectBoostGraphInterface.h>

Inheritance diagram for boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator:
[legend]
Collaboration diagram for boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator:
[legend]

Public Member Functions

 adjacency_iterator ()
 
 adjacency_iterator (typename AdjacentVertexContainer::const_iterator it, const DGtal::CountedPtr< AdjacentVertexContainer > &vertices)
 

Private Member Functions

const Vertexdereference () const
 
bool equal (const adjacency_iterator &other) const
 
void increment ()
 
void decrement ()
 

Private Attributes

AdjacentVertexContainer::const_iterator myIterator
 
DGtal::CountedPtr< AdjacentVertexContainermyVertices
 

Friends

class iterator_core_access
 

Detailed Description

template<class TDigitalTopology, class TDigitalSet>
class boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator

Iterator for visiting adjacent vertices. We use an iterator facade to create a STL-compliant iterator with as little effort as possible.

Note
The difficulty is that DGtal graphs do not provide iterators for visiting edges or adjacent vertices, but merely provide a method that outputs them. Therefore, this iterator shares the container of adjacent vertices (a std::vector) with other (potentially) iterators, through a DGtal::CountedPtr. When the last iterator pointing in this structure is deallocated, the container is automatically deallocated. This is for instance used by function adjacent_vertices, which returns a pair of adjacency_iterator, both points on the same container. Another problem is that the user may have called twice adjacent_vertices on the same vertex, and may wish to compare iterators obtained by two different calls.
typedef typename Object<...> G;
typedef typename graph_traits<G>::adjacency_iterator adjacency_iterator;
G g(...);
std::pair<adjacency_iterator,adjacency_iterator> vp1 = boost::adjacent_vertices( vertex, g );
std::pair<adjacency_iterator,adjacency_iterator> vp2 = boost::adjacent_vertices( vertex, g );

In this case, vp1 and vp2 are not pointing on the same structure, hence the address pointed by vp1 is different from the address pointed by vp2. They are then not comparable a priori. The adjacency_iterator is written so that vp1 (.first or .second) and vp2 (.first or .second) are comparable, using value comparison and out-of-range check.

Definition at line 165 of file ObjectBoostGraphInterface.h.

Constructor & Destructor Documentation

template<class TDigitalTopology , class TDigitalSet >
boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::adjacency_iterator ( )
inline

Default, invalid, constructor.

Definition at line 174 of file ObjectBoostGraphInterface.h.

175  : myIterator(), myVertices( 0 ) {}
AdjacentVertexContainer::const_iterator myIterator
The iterator pointing in the container of adjacent vertices.
template<class TDigitalTopology , class TDigitalSet >
boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::adjacency_iterator ( typename AdjacentVertexContainer::const_iterator  it,
const DGtal::CountedPtr< AdjacentVertexContainer > &  vertices 
)
inline

Valid constructor from instance of AdjacentVertexContainer. The iterator shares the container of adjacent vertices (a std::vector) with other (potentially) iterators, through a DGtal::CountedPtr.

Parameters
itconst_iterator of AdjacentVertexContainer.
verticesCountedPtr of an AdjacentVertexContainer

Definition at line 187 of file ObjectBoostGraphInterface.h.

189  : myIterator( it ), myVertices( vertices ) {}
AdjacentVertexContainer::const_iterator myIterator
The iterator pointing in the container of adjacent vertices.

Member Function Documentation

template<class TDigitalTopology , class TDigitalSet >
void boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::decrement ( )
inlineprivate

Decrement iterator. Required to implement Bidirectional Traversal Iterator Concept.

Definition at line 232 of file ObjectBoostGraphInterface.h.

232 { --myIterator; }
AdjacentVertexContainer::const_iterator myIterator
The iterator pointing in the container of adjacent vertices.
template<class TDigitalTopology , class TDigitalSet >
const Vertex& boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::dereference ( ) const
inlineprivate
Returns
const reference to the Vertex the iterator is pointing to. Required for Readable Iterator, Writable Iterator Concepts

Definition at line 197 of file ObjectBoostGraphInterface.h.

198  {
199  ASSERT( myIterator != myVertices->end() );
200  return *myIterator;
201  }
AdjacentVertexContainer::const_iterator myIterator
The iterator pointing in the container of adjacent vertices.
template<class TDigitalTopology , class TDigitalSet >
bool boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::equal ( const adjacency_iterator other) const
inlineprivate

Predicate to compare equal value of iterators. Required to implement Single Pass Iterator Concept.

Parameters
otheradjacency_iterator to compare with.
Returns
true iff other and this refer to the same Vertex.

Definition at line 212 of file ObjectBoostGraphInterface.h.

213  {
214  bool thisAtEnd = ( myIterator == myVertices->end() );
215  bool otherAtEnd = ( other.myIterator == other.myVertices->end() );
216  if ( thisAtEnd || otherAtEnd ) return thisAtEnd && otherAtEnd;
217  else return *myIterator == *other.myIterator;
218  }
AdjacentVertexContainer::const_iterator myIterator
The iterator pointing in the container of adjacent vertices.
template<class TDigitalTopology , class TDigitalSet >
void boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::increment ( )
inlineprivate

Increment iterator. Required to implement Incrementable Iterator Concept.

Definition at line 225 of file ObjectBoostGraphInterface.h.

225 { ++myIterator; }
AdjacentVertexContainer::const_iterator myIterator
The iterator pointing in the container of adjacent vertices.

Friends And Related Function Documentation

template<class TDigitalTopology , class TDigitalSet >
friend class iterator_core_access
friend

Requirement for boost::iterator_facade.

Definition at line 246 of file ObjectBoostGraphInterface.h.

Field Documentation

template<class TDigitalTopology , class TDigitalSet >
AdjacentVertexContainer::const_iterator boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::myIterator
private

The iterator pointing in the container of adjacent vertices.

Definition at line 237 of file ObjectBoostGraphInterface.h.

template<class TDigitalTopology , class TDigitalSet >
DGtal::CountedPtr< AdjacentVertexContainer > boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::adjacency_iterator::myVertices
private

A counted pointer to the dynamically allocated container of vertices. Will be automatically deallocated when there is no more iterators pointing on it.

Definition at line 243 of file ObjectBoostGraphInterface.h.


The documentation for this class was generated from the following file: