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
11namespace Dune
12{
13
34 template< int codim, class Grid, class IteratorImp >
36 : public EntityPointer< Grid, IteratorImp >
37 {
39
40 protected:
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
138namespace 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;
148 typedef forward_iterator_tag iterator_category;
149 };
150
151} // namespace std
152
153#endif // #ifndef DUNE_GRID_ENTITYITERATOR_HH
STL namespace.
Include standard header files.
Definition agrid.hh:60
interface class for an iterator over grid entities
Definition entityiterator.hh:37
Grid::template Codim< codim >::Entity Entity
Definition entityiterator.hh:44
EntityIterator(const IteratorImp &imp)
copy constructor from implementaton
Definition entityiterator.hh:129
const Entity & operator*() const
Dereferencing operator.
bool operator!=(const EntityIterator &rhs) const
Checks for inequality.
Definition entityiterator.hh:114
EntityIterator()
default construct (undefined) iterator
Definition entityiterator.hh:125
EntityIterator & operator++()
prefix increment operator
Definition entityiterator.hh:47
bool operator==(const EntityIterator &rhs) const
Checks for equality.
Definition entityiterator.hh:108
const Entity & operator->() const
Pointer operator.
const IteratorImp::Entity value_type
Definition entityiterator.hh:145
forward_iterator_tag iterator_category
Definition entityiterator.hh:148
Wrapper class for pointers to entities.
Definition common/entitypointer.hh:114
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
Implementation realIterator
Definition common/entitypointer.hh:138
Wrapper and interface class for a static iterator (EntityPointer)