dune-grid  2.7.0
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 
9 namespace Dune
10 {
11 
28  template< int codim, class Grid, class IteratorImp >
30  {
31  protected:
32  IteratorImp realIterator;
33 
34  public:
40  typedef IteratorImp Implementation;
41 
53  const Implementation &impl () const { return realIterator; }
54 
55  typedef typename Grid::template Codim< codim >::Entity Entity;
56 
58  typedef typename std::conditional<
59  std::is_lvalue_reference<
60  decltype(realIterator.dereference())
61  >::value,
62  const Entity&,
63  Entity
64  >::type Reference;
65 
68  {
69  realIterator.increment();
70  return *this;
71  }
72 
75  {
76  EntityIterator tmp(*this);
77  realIterator.increment();
78  return tmp;
79  }
80 
81  // The behavior when dereferencing the EntityIterator facade depends on
82  // the way the grid implementation handles returning entities. The implementation
83  // may either return a reference to an entity stored inside the EntityIterator
84  // implementation or a temporary Entity object. This object has to be forwarded through
85  // the facade to the user, which requires a little trickery, especially for operator->().
86  //
87  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
88  // function signatures to Doxygen and hide the actual implementations.
89 
90 
91 #ifdef DOXYGEN
92 
94  const Entity& operator*() const;
95 
97  const Entity& operator->() const;
98 
99 #else // DOXYGEN
100 
102  typename std::conditional<
103  std::is_lvalue_reference<
104  decltype(realIterator.dereference())
105  >::value,
106  const Entity&,
107  Entity
108  >::type
109  operator*() const
110  {
111  return realIterator.dereference();
112  }
113 
115  decltype(handle_proxy_member_access(realIterator.dereference()))
116  operator->() const
117  {
118  return handle_proxy_member_access(realIterator.dereference());
119  }
120 
121 #endif // DOXYGEN
122 
123 
125  bool operator==(const EntityIterator& rhs) const
126  {
127  return this->realIterator.equals(rhs.realIterator);
128  }
129 
131  bool operator!=(const EntityIterator& rhs) const
132  {
133  return !this->realIterator.equals(rhs.realIterator);
134  }
135 
136 
143  {}
144 
146  EntityIterator ( const IteratorImp &imp )
147  : realIterator( imp )
148  {}
149 
151  };
152 
153 } // namespace Dune
154 
155 namespace std
156 {
157 
158  template< int codim, class Grid, class IteratorImp >
159  struct iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >
160  {
161  typedef ptrdiff_t difference_type;
162  typedef const typename IteratorImp::Entity value_type;
163  typedef value_type *pointer;
164  typedef value_type &reference;
165  typedef forward_iterator_tag iterator_category;
166  };
167 
168 } // namespace std
169 
170 #endif // #ifndef DUNE_GRID_ENTITYITERATOR_HH
Dune::EntityIterator::Reference
std::conditional< std::is_lvalue_reference< decltype(realIterator.dereference()) >::value, const Entity &, Entity >::type Reference
Type of the reference used when derefencing the Ptr.
Definition: entityiterator.hh:64
Dune::EntityIterator::EntityIterator
EntityIterator()
default construct (undefined) iterator
Definition: entityiterator.hh:142
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::difference_type
ptrdiff_t difference_type
Definition: entityiterator.hh:161
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::pointer
value_type * pointer
Definition: entityiterator.hh:163
Dune::EntityIterator::impl
const Implementation & impl() const
access to the underlying implementation
Definition: entityiterator.hh:53
Dune::EntityIterator::operator->
const Entity & operator->() const
Pointer operator.
Dune::EntityIterator::operator!=
bool operator!=(const EntityIterator &rhs) const
Checks for inequality.
Definition: entityiterator.hh:131
Dune::EntityIterator::impl
Implementation & impl()
access to the underlying implementation
Definition: entityiterator.hh:47
Dune::EntityIterator::realIterator
IteratorImp realIterator
Definition: entityiterator.hh:32
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::value_type
const typedef IteratorImp::Entity value_type
Definition: entityiterator.hh:162
Dune::EntityIterator::Entity
Grid::template Codim< codim >::Entity Entity
Definition: entityiterator.hh:55
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::iterator_category
forward_iterator_tag iterator_category
Definition: entityiterator.hh:165
Dune::EntityIterator::operator*
const Entity & operator*() const
Dereferencing operator.
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::reference
value_type & reference
Definition: entityiterator.hh:164
Dune::EntityIterator::operator==
bool operator==(const EntityIterator &rhs) const
Checks for equality.
Definition: entityiterator.hh:125
Dune::EntityIterator::Implementation
IteratorImp Implementation
type of underlying implementation
Definition: entityiterator.hh:40
Dune::EntityIterator
interface class for an iterator over grid entities
Definition: entityiterator.hh:29
Dune::EntityIterator::EntityIterator
EntityIterator(const IteratorImp &imp)
copy constructor from implementaton
Definition: entityiterator.hh:146
Dune
Include standard header files.
Definition: agrid.hh:58
Dune::EntityIterator::operator++
EntityIterator & operator++()
prefix increment operator
Definition: entityiterator.hh:67
Dune::Entity
Wrapper class for entities.
Definition: common/entity.hh:63