DUNE PDELab (git)

entityiterator.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_GRID_COMMON_ENTITYITERATOR_HH
6#define DUNE_GRID_COMMON_ENTITYITERATOR_HH
7
8#include <cstddef>
9#include <iterator>
10
11namespace Dune
12{
13
30 template< int codim, class Grid, class IteratorImp >
32 {
33 protected:
34 IteratorImp realIterator;
35
36 public:
42 typedef IteratorImp Implementation;
43
49 Implementation &impl () { return realIterator; }
55 const Implementation &impl () const { return realIterator; }
56
57 typedef typename Grid::template Codim< codim >::Entity Entity;
58
60 typedef typename std::conditional<
61 std::is_lvalue_reference<
62 decltype(realIterator.dereference())
63 >::value,
64 const Entity&,
65 Entity
66 >::type Reference;
67
70 {
71 realIterator.increment();
72 return *this;
73 }
74
77 {
78 EntityIterator tmp(*this);
79 realIterator.increment();
80 return tmp;
81 }
82
83 // The behavior when dereferencing the EntityIterator facade depends on
84 // the way the grid implementation handles returning entities. The implementation
85 // may either return a reference to an entity stored inside the EntityIterator
86 // implementation or a temporary Entity object. This object has to be forwarded through
87 // the facade to the user, which requires a little trickery, especially for operator->().
88 //
89 // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
90 // function signatures to Doxygen and hide the actual implementations.
91
92
93#ifdef DOXYGEN
94
96 const Entity& operator*() const;
97
99 const Entity& operator->() const;
100
101#else // DOXYGEN
102
104 typename std::conditional<
105 std::is_lvalue_reference<
106 decltype(realIterator.dereference())
107 >::value,
108 const Entity&,
109 Entity
110 >::type
111 operator*() const
112 {
113 return realIterator.dereference();
114 }
115
117 decltype(handle_proxy_member_access(realIterator.dereference()))
118 operator->() const
119 {
120 return handle_proxy_member_access(realIterator.dereference());
121 }
122
123#endif // DOXYGEN
124
125
127 bool operator==(const EntityIterator& rhs) const
128 {
129 return this->realIterator.equals(rhs.realIterator);
130 }
131
133 bool operator!=(const EntityIterator& rhs) const
134 {
135 return !this->realIterator.equals(rhs.realIterator);
136 }
137
138
145 {}
146
148 EntityIterator ( const IteratorImp &imp )
149 : realIterator( imp )
150 {}
151
153 };
154
155} // namespace Dune
156
157namespace std
158{
159
160 template< int codim, class Grid, class IteratorImp >
161 struct iterator_traits< Dune::EntityIterator< codim, Grid, IteratorImp > >
162 {
163 typedef ptrdiff_t difference_type;
164 typedef const typename IteratorImp::Entity value_type;
165 typedef value_type *pointer;
166 typedef value_type &reference;
167 typedef forward_iterator_tag iterator_category;
168 };
169
170} // namespace std
171
172#endif // #ifndef DUNE_GRID_COMMON_ENTITYITERATOR_HH
interface class for an iterator over grid entities
Definition: entityiterator.hh:32
IteratorImp Implementation
type of underlying implementation
Definition: entityiterator.hh:42
Implementation & impl()
access to the underlying implementation
Definition: entityiterator.hh:49
EntityIterator(const IteratorImp &imp)
copy constructor from implementation
Definition: entityiterator.hh:148
const Entity & operator*() const
Dereferencing operator.
bool operator!=(const EntityIterator &rhs) const
Checks for inequality.
Definition: entityiterator.hh:133
EntityIterator()
default construct (undefined) iterator
Definition: entityiterator.hh:144
EntityIterator & operator++()
prefix increment operator
Definition: entityiterator.hh:69
const Implementation & impl() const
access to the underlying implementation
Definition: entityiterator.hh:55
std::conditional< std::is_lvalue_reference< decltype(realIterator.dereference())>::value, constEntity &, Entity >::type Reference
Type of the reference used when dereferencing the Ptr.
Definition: entityiterator.hh:66
bool operator==(const EntityIterator &rhs) const
Checks for equality.
Definition: entityiterator.hh:127
const Entity & operator->() const
Pointer operator.
Wrapper class for entities.
Definition: entity.hh:66
pointer_or_proxy_holder handle_proxy_member_access(T &&t)
Transparent support for providing member access to both lvalues and rvalues (temporary proxies).
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)