DUNE-FEM (unstable)

dofiterator.hh
1#ifndef DUNE_FEM_DOFITERATOR_HH
2#define DUNE_FEM_DOFITERATOR_HH
3
4#include <dune/fem/misc/bartonnackmaninterface.hh>
5
6namespace Dune
7{
8
9 namespace Fem
10 {
11
19 template< class DofImp, class DofIteratorImp >
21 : public BartonNackmanInterface< DofIteratorInterface< DofImp, DofIteratorImp >,
22 DofIteratorImp >
23 {
24 public:
26 typedef DofImp DofType;
27
29 typedef DofIteratorImp DofIteratorType;
30
31 private:
33 typedef BartonNackmanInterface< ThisType, DofIteratorType > BaseType;
34
35 protected:
36 using BaseType :: asImp;
37
38 public:
44 {
45 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().operator=( other ) );
46 return asImp();
47 }
48
54 {
55 CHECK_INTERFACE_IMPLEMENTATION( *asImp() );
56 return *asImp();
57 }
58
63 const DofType &operator* () const
64 {
65 CHECK_INTERFACE_IMPLEMENTATION( *asImp() );
66 return *asImp();
67 }
68
69 const DofImp &operator[] ( const int n ) const
70 {
71 CHECK_INTERFACE_IMPLEMENTATION( asImp()[ n ] );
72 return asImp()[ n ];
73 }
74
75 DofImp &operator[] ( const int n )
76 {
77 CHECK_INTERFACE_IMPLEMENTATION( asImp()[ n ] );
78 return asImp()[ n ];
79 }
80
88 {
89 CHECK_AND_CALL_INTERFACE_IMPLEMENTATON( asImp().operator++() );
90 return asImp();
91 }
92
99 bool operator== ( const DofIteratorType &other ) const
100 {
101 CHECK_INTERFACE_IMPLEMENTATION( asImp().operator==( other ) );
102 return asImp().operator==( other );
103 }
104
111 bool operator!= ( const DofIteratorType &other ) const
112 {
113 CHECK_INTERFACE_IMPLEMENTATION( asImp().operator!=( other ) );
114 return asImp().operator!=( other );
115 }
116
121 int index () const
122 {
123 CHECK_INTERFACE_IMPLEMENTATION( asImp().index() );
124 return asImp().index();
125 }
126
128 void reset ()
129 {
131 }
132 }; // end DofIteratorInterface
133
134
135
140 template< class DofImp, class DofIteratorImp >
142 : public DofIteratorInterface< DofImp, DofIteratorImp >
143 {
144 public:
146 typedef DofImp DofType;
147
149 typedef DofIteratorImp DofIteratorType;
150
151 private:
154
155 protected:
156 using BaseType :: asImp;
157
158 public:
159 const DofImp &operator[] ( const int n ) const
160 {
161 DofIteratorType &it = const_cast< DofIteratorType & >( asImp() );
162 it.reset();
163 for( int i = 0; i < n; ++i )
164 ++it;
165 return *asImp();
166 }
167
168 DofType &operator[] ( const int n )
169 {
170 asImp().reset();
171 for( int i = 0; i < n; ++i )
172 ++asImp();
173 return *asImp();
174 }
175
176 /* \copydoc Dune::Fem::DofIteratorInterface::operator!=
177 *
178 * \note The default implementation is just
179 * \code
180 * return !operator==( other );
181 * \endcode
182 */
183 bool operator!= ( const DofIteratorType &other ) const
184 {
185 return !asImp().operator==( other );
186 }
187
189 int index () const
190 {
191 DofIteratorType it( asImp() );
192 it.reset();
193
194 int idx = 0;
195 for( ; it != *this; ++it )
196 ++idx;
197
198 return idx;
199 }
200 }; // end class DofIteratorDefault
201
202
203
204 /* \class ConstDofIteratorDefault
205 * \brief makes a const DoF iterator out of DoF iterator
206 */
207 template< class DofIteratorImp >
208 class ConstDofIteratorDefault
209 : public DofIteratorDefault< typename DofIteratorImp :: DofType,
210 DofIteratorImp >
211 {
212 public:
214 typedef DofIteratorImp WrappedDofIteratorType;
215
217 typedef typename WrappedDofIteratorType :: DofType DofType;
218
219 typedef ConstDofIteratorDefault< WrappedDofIteratorType > ThisType;
220 typedef DofIteratorDefault< DofType, ThisType > BaseType;
221
222 protected:
223 WrappedDofIteratorType it_;
224
225 public:
226 ConstDofIteratorDefault( const WrappedDofIteratorType &it )
227 : it_( it )
228 {
229 }
230
231 ConstDofIteratorDefault( const ThisType &other )
232 : it_( other.it_ )
233 {
234 }
235
237 const ThisType &operator= ( const ThisType &other )
238 {
239 it_ = other.it_;
240 return *this;
241 }
242
244 const DofType& operator* () const
245 {
246 return (*it_);
247 }
248
249 const DofType &operator[] ( const int n ) const
250 {
251 return it_[ n ];
252 }
253
255 int index () const
256 {
257 return it_.index();
258 }
259
261 ThisType &operator++ ()
262 {
263 ++it_;
264 return (*this);
265 }
266
268 bool operator== ( const ThisType &other ) const
269 {
270 return (it_ == other.it_);
271 }
272
274 bool operator!= ( const ThisType &other ) const
275 {
276 return (it_ != other.it_);
277 }
278
280 void reset ()
281 {
282 it_.reset();
283 }
284
285 // note: this method is not in the interface!
286 const DofType *vector () const
287 {
288 return it_.vector();
289 }
290 }; // end class DofIteratorDefault
291
292 } // namespace Fem
293
294} // namespace Dune
295
296#endif // #ifndef DUNE_FEM_DOFITERATOR_HH
#define CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(__interface_method_to_call__)
Definition: bartonnackmanifcheck.hh:61
default implementation of DofManagerInterface
Definition: dofiterator.hh:143
int index() const
Definition: dofiterator.hh:189
DofIteratorImp DofIteratorType
type of the implementation (Barton-Nackman)
Definition: dofiterator.hh:149
DofImp DofType
type of the DoFs
Definition: dofiterator.hh:146
interface for DoF iterators of discrete functions
Definition: dofiterator.hh:23
DofType & operator*()
obtain reference to current DoF
Definition: dofiterator.hh:53
DofIteratorImp DofIteratorType
type of the implementation (Barton-Nackman)
Definition: dofiterator.hh:29
DofImp DofType
type of the DoFs
Definition: dofiterator.hh:26
bool operator==(const DofIteratorType &other) const
check for equality
Definition: dofiterator.hh:99
DofIteratorType & operator=(const DofIteratorType &other)
assign another DoF iterator to this one
Definition: dofiterator.hh:43
bool operator!=(const DofIteratorType &other) const
check for inequality
Definition: dofiterator.hh:111
int index() const
get the global number of the current DoF
Definition: dofiterator.hh:121
DofIteratorType & operator++()
increment the iterator
Definition: dofiterator.hh:87
void reset()
reset iterator to the first position
Definition: dofiterator.hh:128
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:260
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)