Dune Core Modules (2.8.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_COMMON_ENTITYITERATOR_HH
4#define DUNE_GRID_COMMON_ENTITYITERATOR_HH
5
6#include <cstddef>
7#include <iterator>
8
9namespace 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
47 Implementation &impl () { return realIterator; }
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
155namespace 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_COMMON_ENTITYITERATOR_HH
interface class for an iterator over grid entities
Definition: entityiterator.hh:30
IteratorImp Implementation
type of underlying implementation
Definition: entityiterator.hh:40
Implementation & impl()
access to the underlying implementation
Definition: entityiterator.hh:47
EntityIterator(const IteratorImp &imp)
copy constructor from implementaton
Definition: entityiterator.hh:146
const Entity & operator*() const
Dereferencing operator.
bool operator!=(const EntityIterator &rhs) const
Checks for inequality.
Definition: entityiterator.hh:131
EntityIterator()
default construct (undefined) iterator
Definition: entityiterator.hh:142
EntityIterator & operator++()
prefix increment operator
Definition: entityiterator.hh:67
const Implementation & impl() const
access to the underlying implementation
Definition: entityiterator.hh:53
std::conditional< std::is_lvalue_reference< decltype(realIterator.dereference())>::value, constEntity &, Entity >::type Reference
Type of the reference used when derefencing the Ptr.
Definition: entityiterator.hh:64
bool operator==(const EntityIterator &rhs) const
Checks for equality.
Definition: entityiterator.hh:125
const Entity & operator->() const
Pointer operator.
Wrapper class for entities.
Definition: entity.hh:64
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:11
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 (Nov 21, 23:30, 2024)