dune-grid  2.6-git
common/intersectioniterator.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GRID_INTERSECTIONITERATOR_HH
4 #define DUNE_GRID_INTERSECTIONITERATOR_HH
5 
6 #include <dune/common/iteratorfacades.hh>
7 #include <dune/common/proxymemberaccess.hh>
8 
10 
11 namespace Dune
12 {
13 
79  template< class GridImp, class IntersectionIteratorImp, class IntersectionImp >
80  class IntersectionIterator
81  {
82  public:
88  typedef IntersectionIteratorImp Implementation;
89 
95  Implementation &impl () { return realIterator; }
96 
102  const Implementation &impl () const { return realIterator; }
103 
104  protected:
105  Implementation realIterator;
106 
107  public:
110 
111  //===========================================================
115  //===========================================================
116 
117  // The behavior when dereferencing the IntersectionIterator facade depends on
118  // the way the grid implementation handles returning intersections. The implementation
119  // may either return a reference to an intersection stored inside the IntersectionIterator
120  // implementation or a temporary Intersection object. This object has to be forwarded through
121  // the facade to the user, which requires a little trickery, especially for operator->().
122  //
123  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
124  // function signatures to Doxygen and hide the actual implementations.
125 
126 #ifdef DOXYGEN
127 
129  Intersection operator*() const;
130 
132  const Intersection* operator->() const;
133 
134 #else // DOXYGEN
135 
137  typename std::conditional<
138  std::is_lvalue_reference<
139  decltype(realIterator.dereference())
140  >::value,
141  const Intersection&,
142  Intersection
143  >::type
144  operator*() const
145  {
146  return this->realIterator.dereference();
147  }
148 
150  decltype(handle_proxy_member_access(realIterator.dereference()))
151  operator->() const
152  {
153  return handle_proxy_member_access(realIterator.dereference());
154  }
155 
156 #endif // DOXYGEN
157 
159 
160 
161  //===========================================================
165  //===========================================================
166 
172  bool operator==(const IntersectionIterator& rhs) const
173  {
174  return rhs.equals(*this);
175  }
176 
182  bool operator!=(const IntersectionIterator& rhs) const
183  {
184  return ! rhs.equals(*this);
185  }
187 
190  {
191  this->realIterator.increment();
192  return *this;
193  }
194 
197  {
198  IntersectionIterator copy(*this);
199  this->realIterator.increment();
200  return copy;
201  }
202 
205  {}
206 
207  //===========================================================
211  //===========================================================
212 
214  bool equals(const IntersectionIterator& rhs) const
215  {
216  return this->realIterator.equals(rhs.realIterator);
217  }
218 
220  IntersectionIterator ( const Implementation &impl )
221  : realIterator( impl )
222  {}
223 
226  realIterator(i.realIterator) {}
228  };
229 
230 } // namespace Dune
231 
232 
233 namespace std
234 {
235 
236  template< class GridImp, class IntersectionIteratorImp, class IntersectionImp >
237  struct iterator_traits< Dune::IntersectionIterator< GridImp, IntersectionIteratorImp, IntersectionImp > >
238  {
239  typedef ptrdiff_t difference_type;
241  typedef value_type *pointer;
242  typedef value_type &reference;
243  typedef forward_iterator_tag iterator_category;
244  };
245 
246 } // namespace std
247 
248 #include "intersection.hh"
249 
250 #endif // DUNE_GRID_INTERSECTIONITERATOR_HH
const Implementation & impl() const
access to the underlying implementation
Definition: common/intersectioniterator.hh:102
IntersectionIteratorImp Implementation
type of underlying implementation
Definition: common/intersectioniterator.hh:88
STL namespace.
bool operator==(const IntersectionIterator &rhs) const
Checks for equality. Only Iterators pointing to the same intersection from the same Entity are equal...
Definition: common/intersectioniterator.hh:172
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: common/grid.hh:345
forward_iterator_tag iterator_category
Definition: common/intersectioniterator.hh:243
IntersectionIterator operator++(int)
Postincrement operator. Proceed to next intersection.
Definition: common/intersectioniterator.hh:196
IntersectionIterator()
Default constructor.
Definition: common/intersectioniterator.hh:204
Implementation realIterator
Definition: common/intersectioniterator.hh:105
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: albertagrid/dgfparser.hh:26
Dune::Intersection< GridImp, IntersectionImp > Intersection
Type of Intersection this IntersectionIterator points to.
Definition: common/intersectioniterator.hh:109
const Intersection * operator->() const
Pointer operator.
Implementation & impl()
access to the underlying implementation
Definition: common/intersectioniterator.hh:95
const Dune::Intersection< GridImp, IntersectionImp > value_type
Definition: common/intersectioniterator.hh:240
IntersectionIterator(const Implementation &impl)
Definition: common/intersectioniterator.hh:220
Intersection operator*() const
Dereferencing operator.
IntersectionIterator & operator++()
Preincrement operator. Proceed to next intersection.
Definition: common/intersectioniterator.hh:189
bool operator!=(const IntersectionIterator &rhs) const
Checks for inequality. Only Iterators pointing to the same intersection from the same Entity are equa...
Definition: common/intersectioniterator.hh:182
IntersectionIterator(const IntersectionIterator &i)
Definition: common/intersectioniterator.hh:225
bool equals(const IntersectionIterator &rhs) const
forward equality check to realIterator
Definition: common/intersectioniterator.hh:214
Include standard header files.
Definition: agrid.hh:58