DGtal  1.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends
boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::out_edge_iterator Class Reference

#include <DGtal/graph/ObjectBoostGraphInterface.h>

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

Public Member Functions

 out_edge_iterator ()
 Default, invalid, constructor. More...
 
 out_edge_iterator (typename OutEdgeContainer::const_iterator it, const DGtal::CountedPtr< OutEdgeContainer > &out_edges)
 

Private Member Functions

const Edgedereference () const
 
bool equal (const out_edge_iterator &other) const
 
void increment ()
 
void decrement ()
 

Private Attributes

OutEdgeContainer::const_iterator myIterator
 The iterator pointing in the container of out edges. More...
 
DGtal::CountedPtr< OutEdgeContainermyOutEdges
 

Friends

class iterator_core_access
 Requirement for boost::iterator_facade. More...
 

Detailed Description

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

Iterator for visiting out edges. 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 out edges (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 out_edges, which returns a pair of out_edge_iterator, both points on the same container. Another problem is that the user may have called twice out_edges on the same vertex, and may wish to compare iterators obtained by two different calls..
typedef typename Object<...> G;
typedef typename graph_traits<G>::out_edge_iterator out_edge_iterator;
G g(...);
std::pair<out_edge_iterator,out_edge_iterator> vp1 = boost::out_edges( vertex, g );
std::pair<out_edge_iterator,out_edge_iterator> vp2 = boost::out_edges( vertex, g );
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::out_edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::out_edge_iterator > out_edges(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 out_edge_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 282 of file ObjectBoostGraphInterface.h.

Constructor & Destructor Documentation

◆ out_edge_iterator() [1/2]

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

Default, invalid, constructor.

Definition at line 291 of file ObjectBoostGraphInterface.h.

292  : myIterator(), myOutEdges( 0 ) {}
OutEdgeContainer::const_iterator myIterator
The iterator pointing in the container of out edges.

◆ out_edge_iterator() [2/2]

template<class TDigitalTopology , class TDigitalSet >
boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::out_edge_iterator::out_edge_iterator ( typename OutEdgeContainer::const_iterator  it,
const DGtal::CountedPtr< OutEdgeContainer > &  out_edges 
)
inline

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

Parameters
itconst_iterator of OutEdgeContainer.
out_edgesCountedPtr of an OutEdgeContainer

Definition at line 303 of file ObjectBoostGraphInterface.h.

305  : myIterator( it ), myOutEdges( out_edges ) {}

Member Function Documentation

◆ decrement()

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

Decrement iterator. Required to implement Bidirectional Traversal Iterator Concept.

Definition at line 346 of file ObjectBoostGraphInterface.h.

346 { --myIterator; }

◆ dereference()

template<class TDigitalTopology , class TDigitalSet >
const Edge& boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::out_edge_iterator::dereference ( ) const
inlineprivate
Returns
const reference to the Edge the iterator is pointing to. Required for Readable Iterator, Writable Iterator Concepts

Definition at line 312 of file ObjectBoostGraphInterface.h.

313  {
314  ASSERT( myIterator != myOutEdges->end() );
315  return *myIterator;
316  }

◆ equal()

template<class TDigitalTopology , class TDigitalSet >
bool boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::out_edge_iterator::equal ( const out_edge_iterator other) const
inlineprivate

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

Parameters
otherout_edge_iterator to compare with.
Returns
true iff other and this refer to the same Edge.

Definition at line 327 of file ObjectBoostGraphInterface.h.

328  {
329  bool thisAtEnd = ( myIterator == myOutEdges->end() );
330  bool otherAtEnd = ( other.myIterator == other.myOutEdges->end() );
331  if ( thisAtEnd || otherAtEnd ) return thisAtEnd && otherAtEnd;
332  else return *myIterator == *other.myIterator;
333  }

◆ increment()

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

Increment iterator. Required to implement Incrementable Iterator Concept.

Definition at line 340 of file ObjectBoostGraphInterface.h.

340 { ++myIterator; }

Friends And Related Function Documentation

◆ iterator_core_access

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

Requirement for boost::iterator_facade.

Definition at line 357 of file ObjectBoostGraphInterface.h.

Field Documentation

◆ myIterator

template<class TDigitalTopology , class TDigitalSet >
OutEdgeContainer::const_iterator boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::out_edge_iterator::myIterator
private

The iterator pointing in the container of out edges.

Definition at line 349 of file ObjectBoostGraphInterface.h.

◆ myOutEdges

template<class TDigitalTopology , class TDigitalSet >
DGtal::CountedPtr< OutEdgeContainer > boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::out_edge_iterator::myOutEdges
private

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

Definition at line 354 of file ObjectBoostGraphInterface.h.


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