DGtal  1.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends
boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator Class Reference

#include <DGtal/graph/DigitalSurfaceBoostGraphInterface.h>

Inheritance diagram for boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::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
 The iterator pointing in the container of adjacent vertices. More...
 
DGtal::CountedPtr< AdjacentVertexContainermyVertices
 

Friends

class iterator_core_access
 

Detailed Description

template<class TDigitalSurfaceContainer>
class boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::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 desallocated, the container is automatically desallocated. 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 DigitalSurface<...> 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 );
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator > adjacent_vertices(typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_descriptor u, const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)

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 172 of file DigitalSurfaceBoostGraphInterface.h.

Constructor & Destructor Documentation

◆ adjacency_iterator() [1/2]

template<class TDigitalSurfaceContainer >
boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::adjacency_iterator ( )
inline

Definition at line 180 of file DigitalSurfaceBoostGraphInterface.h.

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

◆ adjacency_iterator() [2/2]

template<class TDigitalSurfaceContainer >
boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::adjacency_iterator ( typename AdjacentVertexContainer::const_iterator  it,
const DGtal::CountedPtr< AdjacentVertexContainer > &  vertices 
)
inline

Definition at line 183 of file DigitalSurfaceBoostGraphInterface.h.

185  : myIterator( it ), myVertices( vertices ) {}
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)

Member Function Documentation

◆ decrement()

template<class TDigitalSurfaceContainer >
void boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::decrement ( )
inlineprivate

Definition at line 206 of file DigitalSurfaceBoostGraphInterface.h.

206 { --myIterator; }

◆ dereference()

template<class TDigitalSurfaceContainer >
const Vertex& boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::dereference ( ) const
inlineprivate

Definition at line 188 of file DigitalSurfaceBoostGraphInterface.h.

189  {
190  ASSERT( myIterator != myVertices->end() );
191  return *myIterator;
192  }

◆ equal()

template<class TDigitalSurfaceContainer >
bool boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::equal ( const adjacency_iterator other) const
inlineprivate

Definition at line 195 of file DigitalSurfaceBoostGraphInterface.h.

196  {
197  bool thisAtEnd = ( myIterator == myVertices->end() );
198  bool otherAtEnd = ( other.myIterator == other.myVertices->end() );
199  if ( thisAtEnd || otherAtEnd ) return thisAtEnd && otherAtEnd;
200  else return *myIterator == *other.myIterator;
201  }

◆ increment()

template<class TDigitalSurfaceContainer >
void boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::increment ( )
inlineprivate

Definition at line 204 of file DigitalSurfaceBoostGraphInterface.h.

204 { ++myIterator; }

Friends And Related Function Documentation

◆ iterator_core_access

template<class TDigitalSurfaceContainer >
friend class iterator_core_access
friend

Definition at line 215 of file DigitalSurfaceBoostGraphInterface.h.

Field Documentation

◆ myIterator

template<class TDigitalSurfaceContainer >
AdjacentVertexContainer::const_iterator boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::adjacency_iterator::myIterator
private

The iterator pointing in the container of adjacent vertices.

Definition at line 209 of file DigitalSurfaceBoostGraphInterface.h.

◆ myVertices

template<class TDigitalSurfaceContainer >
DGtal::CountedPtr< AdjacentVertexContainer > boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::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 213 of file DigitalSurfaceBoostGraphInterface.h.


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