DGtal 1.3.0
Loading...
Searching...
No Matches
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)
35#define GraphVisitorRange_RECURSES
36
37#if !defined GraphVisitorRange_h
39#define GraphVisitorRange_h
40
42// Inclusions
43#include <iostream>
44#include "DGtal/base/Common.h"
45#include "DGtal/base/CountedPtr.h"
47
48namespace 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
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
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
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)
T * get() const noexcept
Definition: CountedPtr.h:195
Aim: Transforms a graph visitor into a single pass input range.
VertexConstIterator ConstIterator
GraphVisitorRange(const GraphVisitorRange &other)
GenericConstIterator< VertexAccessor > VertexConstIterator
ConstIterator begin() const
GraphVisitorRange & operator=(const GraphVisitorRange &other)
CountedPtr< GraphVisitor > myVisitor
A smart pointer on a graph visitor.
GraphVisitor::Vertex Vertex
NodeConstIterator beginNode() const
GraphVisitorRange(GraphVisitor *visitorPtr)
NodeConstIterator endNode() const
GraphVisitor::Node Node
GraphVisitor::Size Size
void selfDisplay(std::ostream &out) const
GraphVisitor::Graph Graph
GenericConstIterator< NodeAccessor > NodeConstIterator
ConstIterator end() const
GraphVisitor::Data Data
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
CountedPtr< GraphVisitor > myVisitor
Smart pointer to a Visitor.
GenericConstIterator< TAccessor > Self
GenericConstIterator(CountedPtr< GraphVisitor > ptrV)
static reference get(const Node &node)
static reference get(const Node &node)