dune-grid  2.4.1
entityiterator.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_ENTITYITERATOR_HH
4 #define DUNE_GRID_ENTITYITERATOR_HH
5 
6 #include <cstddef>
7 #include <iterator>
8 
10 
11 namespace Dune
12 {
13 
34  template< int codim, class Grid, class IteratorImp >
36  : public EntityPointer< Grid, IteratorImp >
37  {
39 
40  protected:
41  using Base::realIterator;
42 
43  public:
44  typedef typename Grid::template Codim< codim >::Entity Entity;
45 
48  {
49  realIterator.increment();
50  return *this;
51  }
52 
55  {
56  EntityIterator tmp(*this);
57  realIterator.increment();
58  return tmp;
59  }
60 
61  // The dereferencing operators are overridden here to avoid calling
62  // the deprecated versions int the EntityPointer facade.
63 
64  // The behavior when dereferencing the EntityIterator facade depends on
65  // the way the grid implementation handles returning entities. The implementation
66  // may either return a reference to an entity stored inside the EntityIterator
67  // implementation or a temporary Entity object. This object has to be forwarded through
68  // the facade to the user, which requires a little trickery, especially for operator->().
69  //
70  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
71  // function signatures to Doxygen and hide the actual implementations.
72 
73 
74 #ifdef DOXYGEN
75 
77  const Entity& operator*() const;
78 
80  const Entity* operator->() const;
81 
82 #else // DOXYGEN
83 
85  typename std::conditional<
86  std::is_lvalue_reference<
87  decltype(realIterator.dereference())
88  >::value,
89  const Entity&,
90  Entity
91  >::type
92  operator*() const
93  {
94  return realIterator.dereference();
95  }
96 
98  decltype(handle_proxy_member_access(realIterator.dereference()))
99  operator->() const
100  {
101  return handle_proxy_member_access(realIterator.dereference());
102  }
103 
104 #endif // DOXYGEN
105 
106 
108  bool operator==(const EntityIterator& rhs) const
109  {
110  return this->realIterator.equals(rhs.realIterator);
111  }
112 
114  bool operator!=(const EntityIterator& rhs) const
115  {
116  return !this->realIterator.equals(rhs.realIterator);
117  }
118 
128  template< class ItImp >
129  DUNE_DEPRECATED_MSG("Comparing different types of iterators is deprecated and will be removed after the \
130 release of dune-grid 2.4. If you want to compare the entities pointed at by the iterators, dereference the \
131 iterators before comparing them.")
132  bool operator== ( const EntityIterator< codim, Grid, ItImp > &rhs ) const
133  {
134  return this->equals( rhs );
135  }
136 
146  template< class ItImp >
147  DUNE_DEPRECATED_MSG("Comparing different types of iterators is deprecated and will be removed after the \
148 release of dune-grid 2.4. If you want to compare the entities pointed at by the iterators, dereference the \
149 iterators before comparing them.")
150  bool operator!= ( const EntityIterator< codim, Grid, ItImp > &rhs ) const
151  {
152  return !this->equals( rhs );
153  }
154 
164  template< class ItImp >
165  DUNE_DEPRECATED_MSG("EntityPointer is deprecated will be removed after the release of dune-grid 2.4. \
166 Moreover, comparing different types of iterators is deprecated as well and will also be removed after the \
167 release of dune-grid 2.4. If you want to compare the entities pointed at by the iterators, dereference the \
168 iterators before comparing them.")
169  bool operator== ( const EntityPointer< Grid, ItImp > &rhs ) const
170  {
171  return this->equals( rhs );
172  }
173 
183  template< class ItImp >
184  DUNE_DEPRECATED_MSG("EntityPointer is deprecated will be removed after the release of dune-grid 2.4. \
185 Moreover, comparing different types of iterators is deprecated as well and will also be removed after the \
186 release of dune-grid 2.4. If you want to compare the entities pointed at by the iterators, dereference the \
187 iterators before comparing them.")
188  bool operator!= ( const EntityPointer< Grid, ItImp > &rhs ) const
189  {
190  return !this->equals( rhs );
191  }
192 
193 
199  DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. \
200 Instead, you can copy and store entities directly now. You probably stumbled across this warning because you \
201 compared the return value of Entity::father(), Entity::subEntity(), Intersection::inside() or \
202 Intersection::outside() with an iterator. To fix the problem, derefence the iterator before comparing.")
203  bool operator==(const Entity& rhs) const
204  {
205  return (**this) == rhs;
206  }
207 
213  DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. \
214 Instead, you can copy and store entities directly now. You probably stumbled across this warning because you \
215 compared the return value of Entity::father(), Entity::subEntity(), Intersection::inside() or \
216 Intersection::outside() with an iterator. To fix the problem, derefence the iterator before comparing.")
217  bool operator!=(const Entity& rhs) const
218  {
219  return (**this) != rhs;
220  }
221 
222 
229  {}
230 
232  EntityIterator ( const IteratorImp &imp )
233  : Base( imp )
234  {}
235 
237  };
238 
239 } // namespace Dune
240 
241 namespace std
242 {
243 
244  template< int codim, class Grid, class IteratorImp >
245  struct iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >
246  {
247  typedef ptrdiff_t difference_type;
248  typedef const typename IteratorImp::Entity value_type;
249  typedef value_type *pointer;
251  typedef forward_iterator_tag iterator_category;
252  };
253 
254 } // namespace std
255 
256 #endif // #ifndef DUNE_GRID_ENTITYITERATOR_HH
bool operator!=(const EntityIterator &rhs) const
Checks for inequality.
Definition: entityiterator.hh:114
EntityIterator(const IteratorImp &imp)
copy constructor from implementaton
Definition: entityiterator.hh:232
Wrapper class for entities.
Definition: common/entity.hh:61
Wrapper and interface class for a static iterator (EntityPointer)
Wrapper class for pointers to entities.
Definition: common/entitypointer.hh:112
Grid::template Codim< codim >::Entity Entity
Definition: entityiterator.hh:44
forward_iterator_tag iterator_category
Definition: entityiterator.hh:251
const Entity * operator->() const
Pointer operator.
EntityIterator()
default construct (undefined) iterator
Definition: entityiterator.hh:228
bool operator==(const EntityIterator &rhs) const
Checks for equality.
Definition: entityiterator.hh:108
EntityIterator & operator++()
prefix increment operator
Definition: entityiterator.hh:47
const IteratorImp::Entity value_type
Definition: entityiterator.hh:248
interface class for an iterator over grid entitiesAn entity iterator is an iterator over a subset of ...
Definition: entityiterator.hh:35
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:388
const Entity & operator*() const
Dereferencing operator.
bool equals(const EntityPointer< Grid, ItImp > &rhs) const
Forward equality check to realIterator.
Definition: common/entitypointer.hh:362
Implementation realIterator
Definition: common/entitypointer.hh:137
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entitypointer.hh:432