dune-grid  2.9.0
common/intersectioniterator.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GRID_COMMON_INTERSECTIONITERATOR_HH
6 #define DUNE_GRID_COMMON_INTERSECTIONITERATOR_HH
7 
8 #include <dune/common/iteratorfacades.hh>
9 #include <dune/common/proxymemberaccess.hh>
10 
12 
13 namespace Dune
14 {
15 
81  template< class GridImp, class IntersectionIteratorImp, class IntersectionImp >
83  {
84  public:
90  typedef IntersectionIteratorImp Implementation;
91 
98 
104  const Implementation &impl () const { return realIterator; }
105 
106  protected:
108 
109  public:
112 
113  //===========================================================
117  //===========================================================
118 
119  // The behavior when dereferencing the IntersectionIterator facade depends on
120  // the way the grid implementation handles returning intersections. The implementation
121  // may either return a reference to an intersection stored inside the IntersectionIterator
122  // implementation or a temporary Intersection object. This object has to be forwarded through
123  // the facade to the user, which requires a little trickery, especially for operator->().
124  //
125  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
126  // function signatures to Doxygen and hide the actual implementations.
127 
128 #ifdef DOXYGEN
129 
132 
134  const Intersection* operator->() const;
135 
136 #else // DOXYGEN
137 
139  typename std::conditional<
140  std::is_lvalue_reference<
141  decltype(realIterator.dereference())
142  >::value,
143  const Intersection&,
145  >::type
146  operator*() const
147  {
148  return this->realIterator.dereference();
149  }
150 
152  decltype(handle_proxy_member_access(realIterator.dereference()))
153  operator->() const
154  {
155  return handle_proxy_member_access(realIterator.dereference());
156  }
157 
158 #endif // DOXYGEN
159 
161 
162 
163  //===========================================================
167  //===========================================================
168 
174  bool operator==(const IntersectionIterator& rhs) const
175  {
176  return rhs.equals(*this);
177  }
178 
184  bool operator!=(const IntersectionIterator& rhs) const
185  {
186  return ! rhs.equals(*this);
187  }
189 
192  {
193  this->realIterator.increment();
194  return *this;
195  }
196 
199  {
200  IntersectionIterator copy(*this);
201  this->realIterator.increment();
202  return copy;
203  }
204 
207  {}
208 
209  //===========================================================
213  //===========================================================
214 
216  bool equals(const IntersectionIterator& rhs) const
217  {
218  return this->realIterator.equals(rhs.realIterator);
219  }
220 
223  : realIterator( impl )
224  {}
226  };
227 
228 } // namespace Dune
229 
230 
231 namespace std
232 {
233 
234  template< class GridImp, class IntersectionIteratorImp, class IntersectionImp >
235  struct iterator_traits< Dune::IntersectionIterator< GridImp, IntersectionIteratorImp, IntersectionImp > >
236  {
237  typedef ptrdiff_t difference_type;
239  typedef value_type *pointer;
241  typedef forward_iterator_tag iterator_category;
242  };
243 
244 } // namespace std
245 
246 #include "intersection.hh"
247 
248 #endif // DUNE_GRID_COMMON_INTERSECTIONITERATOR_HH
Include standard header files.
Definition: agrid.hh:60
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: common/intersection.hh:164
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: common/intersectioniterator.hh:83
IntersectionIterator()
Default constructor.
Definition: common/intersectioniterator.hh:206
Implementation & impl()
access to the underlying implementation
Definition: common/intersectioniterator.hh:97
IntersectionIteratorImp Implementation
type of underlying implementation
Definition: common/intersectioniterator.hh:90
Intersection operator*() const
Dereferencing operator.
const Implementation & impl() const
access to the underlying implementation
Definition: common/intersectioniterator.hh:104
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:174
Dune::Intersection< GridImp, IntersectionImp > Intersection
Type of Intersection this IntersectionIterator points to.
Definition: common/intersectioniterator.hh:111
IntersectionIterator operator++(int)
Postincrement operator. Proceed to next intersection.
Definition: common/intersectioniterator.hh:198
Implementation realIterator
Definition: common/intersectioniterator.hh:107
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:184
const Intersection * operator->() const
Pointer operator.
IntersectionIterator & operator++()
Preincrement operator. Proceed to next intersection.
Definition: common/intersectioniterator.hh:191
IntersectionIterator(const Implementation &impl)
Definition: common/intersectioniterator.hh:222
bool equals(const IntersectionIterator &rhs) const
forward equality check to realIterator
Definition: common/intersectioniterator.hh:216
forward_iterator_tag iterator_category
Definition: common/intersectioniterator.hh:241
const Dune::Intersection< GridImp, IntersectionImp > value_type
Definition: common/intersectioniterator.hh:238