dune-grid  2.5-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 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
83  public:
84 #else
85  protected:
86  // give the GridDefaultImplementation class access to the realImp
87  friend class GridDefaultImplementation<
88  GridImp::dimension, GridImp::dimensionworld,
89  typename GridImp::ctype,
90  typename GridImp::GridFamily> ;
91 #endif
92  // type of underlying implementation, for internal use only
93  typedef IntersectionIteratorImp Implementation;
94 
98  const Implementation &impl () const { return realIterator; }
99 
100  protected:
102 
103  public:
106 
107  //===========================================================
111  //===========================================================
112 
113  // The behavior when dereferencing the IntersectionIterator facade depends on
114  // the way the grid implementation handles returning intersections. The implementation
115  // may either return a reference to an intersection stored inside the IntersectionIterator
116  // implementation or a temporary Intersection object. This object has to be forwarded through
117  // the facade to the user, which requires a little trickery, especially for operator->().
118  //
119  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
120  // function signatures to Doxygen and hide the actual implementations.
121 
122 #ifdef DOXYGEN
123 
125  Intersection operator*() const;
126 
128  const Intersection* operator->() const;
129 
130 #else // DOXYGEN
131 
133  typename std::conditional<
134  std::is_lvalue_reference<
135  decltype(realIterator.dereference())
136  >::value,
137  const Intersection&,
138  Intersection
139  >::type
140  operator*() const
141  {
142  return this->realIterator.dereference();
143  }
144 
146  decltype(handle_proxy_member_access(realIterator.dereference()))
147  operator->() const
148  {
149  return handle_proxy_member_access(realIterator.dereference());
150  }
151 
152 #endif // DOXYGEN
153 
155 
156 
157  //===========================================================
161  //===========================================================
162 
168  bool operator==(const IntersectionIterator& rhs) const
169  {
170  return rhs.equals(*this);
171  }
172 
178  bool operator!=(const IntersectionIterator& rhs) const
179  {
180  return ! rhs.equals(*this);
181  }
183 
186  {
187  this->realIterator.increment();
188  return *this;
189  }
190 
193  {
194  IntersectionIterator copy(*this);
195  this->realIterator.increment();
196  return copy;
197  }
198 
201  {}
202 
203  //===========================================================
207  //===========================================================
208 
210  bool equals(const IntersectionIterator& rhs) const
211  {
212  return this->realIterator.equals(rhs.realIterator);
213  }
214 
217  : realIterator( impl )
218  {}
219 
222  realIterator(i.realIterator) {}
224  };
225 
226 } // namespace Dune
227 
228 
229 namespace std
230 {
231 
232  template< class GridImp, class IntersectionIteratorImp, class IntersectionImp >
233  struct iterator_traits< Dune::IntersectionIterator< GridImp, IntersectionIteratorImp, IntersectionImp > >
234  {
235  typedef ptrdiff_t difference_type;
237  typedef value_type *pointer;
238  typedef value_type &reference;
239  typedef forward_iterator_tag iterator_category;
240  };
241 
242 } // namespace std
243 
244 #include "intersection.hh"
245 
246 #endif // DUNE_GRID_INTERSECTIONITERATOR_HH
Implementation & impl()
return reference to the real implementation
Definition: common/intersectioniterator.hh:96
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: albertagrid/dgfparser.hh:26
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:168
bool equals(const IntersectionIterator &rhs) const
forward equality check to realIterator
Definition: common/intersectioniterator.hh:210
const Implementation & impl() const
return reference to the real implementation
Definition: common/intersectioniterator.hh:98
IntersectionIterator(const IntersectionIterator &i)
Definition: common/intersectioniterator.hh:221
forward_iterator_tag iterator_category
Definition: common/intersectioniterator.hh:239
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: common/grid.hh:345
const Intersection * operator->() const
Pointer operator.
IntersectionIteratorImp Implementation
Definition: common/intersectioniterator.hh:93
Intersection operator*() const
Dereferencing operator.
Include standard header files.
Definition: agrid.hh:59
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:178
const Dune::Intersection< GridImp, IntersectionImp > value_type
Definition: common/intersectioniterator.hh:236
IntersectionIterator(const Implementation &impl)
Definition: common/intersectioniterator.hh:216
Implementation realIterator
Definition: common/intersectioniterator.hh:101
IntersectionIterator & operator++()
Preincrement operator. Proceed to next intersection.
Definition: common/intersectioniterator.hh:185
STL namespace.
IntersectionIterator operator++(int)
Postincrement operator. Proceed to next intersection.
Definition: common/intersectioniterator.hh:192
IntersectionIterator()
Default constructor.
Definition: common/intersectioniterator.hh:200
Dune::Intersection< GridImp, IntersectionImp > Intersection
Type of Intersection this IntersectionIterator points to.
Definition: common/intersectioniterator.hh:105