Dune Core Modules (2.5.0)

entityiterator.hh
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:
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
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;
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
interface class for an iterator over grid entities
Definition: entityiterator.hh:37
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.
Wrapper class for pointers to entities.
Definition: entitypointer.hh:115
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entitypointer.hh:434
Wrapper and interface class for a static iterator (EntityPointer)
Dune namespace.
Definition: alignment.hh:11
pointer_or_proxy_holder handle_proxy_member_access(T &&t)
Transparent support for providing member access to both lvalues and rvalues (temporary proxies).
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)