dune-grid  3.0-git
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 in 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 
119 
126  {}
127 
129  EntityIterator ( const IteratorImp &imp )
130  : Base( imp )
131  {}
132 
134  };
135 
136 } // namespace Dune
137 
138 namespace std
139 {
140 
141  template< int codim, class Grid, class IteratorImp >
142  struct iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >
143  {
144  typedef ptrdiff_t difference_type;
145  typedef const typename IteratorImp::Entity value_type;
146  typedef value_type *pointer;
147  typedef value_type &reference;
148  typedef forward_iterator_tag iterator_category;
149  };
150 
151 } // namespace std
152 
153 #endif // #ifndef DUNE_GRID_ENTITYITERATOR_HH
Dune
Include standard header files.
Definition: agrid.hh:59
Dune::EntityPointer< Grid, IteratorImp >::type
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entitypointer.hh:433
Dune::EntityIterator::operator->
const Entity & operator->() const
Pointer operator.
Dune::EntityPointer< Grid, IteratorImp >::realIterator
Implementation realIterator
Definition: common/entitypointer.hh:138
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::iterator_category
forward_iterator_tag iterator_category
Definition: entityiterator.hh:148
Dune::EntityIterator
interface class for an iterator over grid entities
Definition: entityiterator.hh:35
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::reference
value_type & reference
Definition: entityiterator.hh:147
Dune::Entity
Wrapper class for entities.
Definition: common/entity.hh:61
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::value_type
const typedef IteratorImp::Entity value_type
Definition: entityiterator.hh:145
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::difference_type
ptrdiff_t difference_type
Definition: entityiterator.hh:144
Dune::EntityIterator::EntityIterator
EntityIterator(const IteratorImp &imp)
copy constructor from implementaton
Definition: entityiterator.hh:129
Dune::EntityIterator::operator*
const Entity & operator*() const
Dereferencing operator.
Dune::EntityIterator::operator!=
bool operator!=(const EntityIterator &rhs) const
Checks for inequality.
Definition: entityiterator.hh:114
Dune::EntityIterator::Entity
Grid::template Codim< codim >::Entity Entity
Definition: entityiterator.hh:44
std::iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >::pointer
value_type * pointer
Definition: entityiterator.hh:146
Dune::EntityIterator::operator==
bool operator==(const EntityIterator &rhs) const
Checks for equality.
Definition: entityiterator.hh:108
Dune::EntityIterator::operator++
EntityIterator & operator++()
prefix increment operator
Definition: entityiterator.hh:47
entitypointer.hh
Wrapper and interface class for a static iterator (EntityPointer)
Dune::EntityIterator::EntityIterator
EntityIterator()
default construct (undefined) iterator
Definition: entityiterator.hh:125
Dune::EntityPointer
Wrapper class for pointers to entities.
Definition: common/entitypointer.hh:113