DGtal  1.1.0
GraphVisitorRange.h
1 
17 #pragma once
18 
31 #if defined(GraphVisitorRange_RECURSES)
32 #error Recursive header files inclusion detected in GraphVisitorRange.h
33 #else // defined(GraphVisitorRange_RECURSES)
34 
35 #define GraphVisitorRange_RECURSES
36 
37 #if !defined GraphVisitorRange_h
38 
39 #define GraphVisitorRange_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/CountedPtr.h"
47 
48 namespace DGtal
49 {
50 
52  // template class GraphVisitorRange
70  template < typename TGraphVisitor >
72  {
73  public:
74  typedef TGraphVisitor GraphVisitor;
75  typedef typename GraphVisitor::Graph Graph;
76  typedef typename GraphVisitor::Vertex Vertex;
77  typedef typename GraphVisitor::Node Node;
78  typedef typename GraphVisitor::Size Size;
79  typedef typename GraphVisitor::Data Data;
80 
85  struct NodeAccessor {
86  typedef const Node value;
87  typedef const Node value_type;
88  typedef const Node* pointer;
89  typedef const Node& reference;
90  inline
91  static reference get( const Node & node )
92  { return node; }
93  };
94 
99  struct VertexAccessor {
100  typedef const Vertex value;
101  typedef const Vertex value_type;
102  typedef const Vertex* pointer;
103  typedef const Vertex& reference;
104  inline
105  static reference get( const Node & node )
106  { return node.first; }
107  };
108 
116  template <typename TAccessor>
118  {
120  typedef TAccessor Accessor;
121 
122  // stl iterator types.
123  typedef std::input_iterator_tag iterator_category;
124  typedef typename Accessor::value value_type;
125  typedef std::ptrdiff_t difference_type;
126  typedef typename Accessor::pointer pointer;
127  typedef typename Accessor::reference reference;
128 
131 
132  inline
134  : myVisitor( 0 ) {}
135  inline
137  : myVisitor( ptrV ) {}
138  inline
139  GenericConstIterator( const Self & other )
140  : myVisitor( other.myVisitor ) {}
141 
142  inline
143  Self & operator=( const Self & other )
144  {
145  if ( this != &other )
146  myVisitor = other.myVisitor;
147  return *this;
148  }
149 
150  inline
151  reference
152  operator*() const
153  {
154  ASSERT( ( myVisitor.get() != 0 )
155  && "DGtal::GraphVisitorRange<>::GenericConstIterator<>::operator*(): you cannot dereferenced a null visitor (i.e. end()).");
156  return Accessor::get( myVisitor->current() );
157  }
158 
159  inline
160  pointer
161  operator->() const
162  {
163  ASSERT( ( myVisitor.get() != 0 )
164  && "DGtal::GraphVisitorRange<>::GenericConstIterator<>::operator->(): you cannot dereferenced a null visitor (i.e. end()).");
165  return & Accessor::get( operator*() );
166  }
167 
168  inline
169  Self&
171  {
172  myVisitor->expand();
173  return *this;
174  }
175 
176  inline
177  Self
179  {
180  Self __tmp = *this;
181  myVisitor->expand();
182  return __tmp;
183  }
184 
185  inline
186  bool operator==( const Self & other ) const
187  {
188  if ( ( myVisitor.get() == 0 ) || myVisitor->finished() )
189  return ( other.myVisitor.get() == 0 ) || other.myVisitor->finished();
190  else if ( other.myVisitor.get() == 0 )
191  return false;
192  else
193  return &(myVisitor->current()) == &(other.myVisitor->current());
194  }
195 
196  inline
197  bool operator!=( const Self & other ) const
198  {
199  return ! ( this->operator==( other ) );
200  }
201  };
202 
209 
212 
213  // ----------------------- Standard services ------------------------------
214  public:
215 
220 
230 
238 
244 
252 
258 
259  // ----------------------- Interface --------------------------------------
260  public:
261 
266  void selfDisplay ( std::ostream & out ) const;
267 
272  bool isValid() const;
273 
274  // ------------------------- Protected Datas ------------------------------
275  private:
276  // ------------------------- Private Datas --------------------------------
277  private:
278 
281 
282  // ------------------------- Hidden services ------------------------------
283  protected:
284 
290 
291  private:
292 
299 
307 
308  // ------------------------- Internals ------------------------------------
309  private:
310 
311  }; // end of class GraphVisitorRange
312 
313 
320  template <typename TGraphVisitor>
321  std::ostream&
322  operator<< ( std::ostream & out, const GraphVisitorRange<TGraphVisitor> & object );
323 
324 } // namespace DGtal
325 
326 
328 // Includes inline functions.
329 #include "DGtal/graph/GraphVisitorRange.ih"
330 
331 // //
333 
334 #endif // !defined GraphVisitorRange_h
335 
336 #undef GraphVisitorRange_RECURSES
337 #endif // else defined(GraphVisitorRange_RECURSES)
DGtal::GraphVisitorRange::NodeAccessor::pointer
const Node * pointer
Definition: GraphVisitorRange.h:88
DGtal::GraphVisitorRange::Data
GraphVisitor::Data Data
Definition: GraphVisitorRange.h:79
DGtal::GraphVisitorRange::begin
ConstIterator begin() const
DGtal::GraphVisitorRange::GenericConstIterator::iterator_category
std::input_iterator_tag iterator_category
Definition: GraphVisitorRange.h:123
DGtal::GraphVisitorRange::Size
GraphVisitor::Size Size
Definition: GraphVisitorRange.h:78
DGtal::GraphVisitorRange::Graph
GraphVisitor::Graph Graph
Definition: GraphVisitorRange.h:75
DGtal::GraphVisitorRange
Aim: Transforms a graph visitor into a single pass input range.
Definition: GraphVisitorRange.h:72
DGtal::GraphVisitorRange::VertexAccessor::get
static reference get(const Node &node)
Definition: GraphVisitorRange.h:105
DGtal::GraphVisitorRange::GraphVisitorRange
GraphVisitorRange(GraphVisitor *visitorPtr)
DGtal::GraphVisitorRange::VertexAccessor::reference
const Vertex & reference
Definition: GraphVisitorRange.h:103
DGtal::GraphVisitorRange::GenericConstIterator::Self
GenericConstIterator< TAccessor > Self
Definition: GraphVisitorRange.h:119
DGtal::GraphVisitorRange::myVisitor
CountedPtr< GraphVisitor > myVisitor
A smart pointer on a graph visitor.
Definition: GraphVisitorRange.h:280
DGtal::GraphVisitorRange::VertexAccessor
Definition: GraphVisitorRange.h:99
DGtal::GraphVisitorRange::GraphVisitorRange
GraphVisitorRange(const GraphVisitorRange &other)
DGtal::GraphVisitorRange::VertexAccessor::value_type
const Vertex value_type
Definition: GraphVisitorRange.h:101
DGtal::GraphVisitorRange::GraphVisitorRange
GraphVisitorRange()
DGtal::GraphVisitorRange::endNode
NodeConstIterator endNode() const
DGtal::GraphVisitorRange::GenericConstIterator::operator++
Self operator++(int)
Definition: GraphVisitorRange.h:178
DGtal::GraphVisitorRange::operator=
GraphVisitorRange & operator=(const GraphVisitorRange &other)
Vertex
TriMesh::Vertex Vertex
Definition: testTriangulatedSurface.cpp:57
DGtal::GraphVisitorRange::NodeAccessor
Definition: GraphVisitorRange.h:85
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::GraphVisitorRange::GenericConstIterator::GenericConstIterator
GenericConstIterator()
Definition: GraphVisitorRange.h:133
DGtal::GraphVisitorRange::~GraphVisitorRange
~GraphVisitorRange()
DGtal::GraphVisitorRange::NodeAccessor::reference
const Node & reference
Definition: GraphVisitorRange.h:89
DGtal::GraphVisitorRange::GenericConstIterator::operator++
Self & operator++()
Definition: GraphVisitorRange.h:170
DGtal::GraphVisitorRange::isValid
bool isValid() const
DGtal::GraphVisitorRange::GenericConstIterator::pointer
Accessor::pointer pointer
Definition: GraphVisitorRange.h:126
DGtal::GraphVisitorRange::GraphVisitor
TGraphVisitor GraphVisitor
Definition: GraphVisitorRange.h:74
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::GraphVisitorRange::GenericConstIterator::operator->
pointer operator->() const
Definition: GraphVisitorRange.h:161
DGtal::GraphVisitorRange::Node
GraphVisitor::Node Node
Definition: GraphVisitorRange.h:77
DGtal::GraphVisitorRange::Vertex
GraphVisitor::Vertex Vertex
Definition: GraphVisitorRange.h:76
DGtal::GraphVisitorRange::NodeAccessor::value_type
const Node value_type
Definition: GraphVisitorRange.h:87
DGtal::GraphVisitorRange::NodeAccessor::value
const Node value
Definition: GraphVisitorRange.h:86
DGtal::CountedPtr< GraphVisitor >
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::GraphVisitorRange::GenericConstIterator::difference_type
std::ptrdiff_t difference_type
Definition: GraphVisitorRange.h:125
DGtal::GraphVisitorRange::NodeAccessor::get
static reference get(const Node &node)
Definition: GraphVisitorRange.h:91
DGtal::GraphVisitorRange::GenericConstIterator
Definition: GraphVisitorRange.h:118
DGtal::GraphVisitorRange::ConstIterator
VertexConstIterator ConstIterator
Definition: GraphVisitorRange.h:210
DGtal::GraphVisitorRange::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::GraphVisitorRange::GenericConstIterator::operator*
reference operator*() const
Definition: GraphVisitorRange.h:152
DGtal::GraphVisitorRange::NodeConstIterator
GenericConstIterator< NodeAccessor > NodeConstIterator
Definition: GraphVisitorRange.h:208
DGtal::GraphVisitorRange::GenericConstIterator::operator=
Self & operator=(const Self &other)
Definition: GraphVisitorRange.h:143
DGtal::GraphVisitorRange::GenericConstIterator::operator==
bool operator==(const Self &other) const
Definition: GraphVisitorRange.h:186
DGtal::CountedPtr::get
T * get() const noexcept
Definition: CountedPtr.h:195
DGtal::GraphVisitorRange::GenericConstIterator::myVisitor
CountedPtr< GraphVisitor > myVisitor
Smart pointer to a Visitor.
Definition: GraphVisitorRange.h:130
DGtal::GraphVisitorRange::GenericConstIterator::operator!=
bool operator!=(const Self &other) const
Definition: GraphVisitorRange.h:197
DGtal::GraphVisitorRange::GenericConstIterator::GenericConstIterator
GenericConstIterator(const Self &other)
Definition: GraphVisitorRange.h:139
DGtal::GraphVisitorRange::GenericConstIterator::Accessor
TAccessor Accessor
Definition: GraphVisitorRange.h:120
DGtal::GraphVisitorRange::GenericConstIterator::GenericConstIterator
GenericConstIterator(CountedPtr< GraphVisitor > ptrV)
Definition: GraphVisitorRange.h:136
DGtal::GraphVisitorRange::VertexAccessor::value
const Vertex value
Definition: GraphVisitorRange.h:100
DGtal::GraphVisitorRange::GenericConstIterator::reference
Accessor::reference reference
Definition: GraphVisitorRange.h:127
DGtal::GraphVisitorRange::const_iterator
ConstIterator const_iterator
Definition: GraphVisitorRange.h:211
DGtal::GraphVisitorRange::GenericConstIterator::value_type
Accessor::value value_type
Definition: GraphVisitorRange.h:124
DGtal::GraphVisitorRange::VertexAccessor::pointer
const Vertex * pointer
Definition: GraphVisitorRange.h:102
DGtal::GraphVisitorRange::beginNode
NodeConstIterator beginNode() const
DGtal::GraphVisitorRange::end
ConstIterator end() const
DGtal::GraphVisitorRange::VertexConstIterator
GenericConstIterator< VertexAccessor > VertexConstIterator
Definition: GraphVisitorRange.h:205