dune-fem  2.8-git
dofiterator.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DOFITERATOR_HH
2 #define DUNE_FEM_DOFITERATOR_HH
3 
5 
6 namespace 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:
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  {
130  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().reset() );
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 >
209  : public DofIteratorDefault< typename DofIteratorImp :: DofType,
210  DofIteratorImp >
211  {
212  public:
214  typedef DofIteratorImp WrappedDofIteratorType;
215 
217  typedef typename WrappedDofIteratorType :: DofType DofType;
218 
221 
222  protected:
224 
225  public:
227  : it_( it )
228  {
229  }
230 
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 
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
Definition: bindguard.hh:11
interface for DoF iterators of discrete functions
Definition: dofiterator.hh:23
DofType & operator*()
obtain reference to current DoF
Definition: dofiterator.hh:53
DofIteratorType & operator=(const DofIteratorType &other)
assign another DoF iterator to this one
Definition: dofiterator.hh:43
DofIteratorType & operator++()
increment the iterator
Definition: dofiterator.hh:87
DofIteratorImp DofIteratorType
type of the implementation (Barton-Nackman)
Definition: dofiterator.hh:29
DofImp DofType
type of the DoFs
Definition: dofiterator.hh:26
const DofImp & operator[](const int n) const
Definition: dofiterator.hh:69
bool operator==(const DofIteratorType &other) const
check for equality
Definition: dofiterator.hh:99
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
void reset()
reset iterator to the first position
Definition: dofiterator.hh:128
default implementation of DofManagerInterface
Definition: dofiterator.hh:143
int index() const
Definition: dofiterator.hh:189
const DofImp & operator[](const int n) const
Definition: dofiterator.hh:159
bool operator!=(const DofIteratorType &other) const
Definition: dofiterator.hh:183
DofIteratorImp DofIteratorType
type of the implementation (Barton-Nackman)
Definition: dofiterator.hh:149
DofImp DofType
type of the DoFs
Definition: dofiterator.hh:146
Definition: dofiterator.hh:211
ConstDofIteratorDefault(const ThisType &other)
Definition: dofiterator.hh:231
DofIteratorDefault< DofType, ThisType > BaseType
Definition: dofiterator.hh:220
void reset()
reset iterator to the first position
Definition: dofiterator.hh:280
bool operator!=(const ThisType &other) const
check for inequality
Definition: dofiterator.hh:274
DofIteratorImp WrappedDofIteratorType
type of the wrapped DoF iterator
Definition: dofiterator.hh:214
ConstDofIteratorDefault(const WrappedDofIteratorType &it)
Definition: dofiterator.hh:226
WrappedDofIteratorType it_
Definition: dofiterator.hh:223
ConstDofIteratorDefault< WrappedDofIteratorType > ThisType
Definition: dofiterator.hh:219
const ThisType & operator=(const ThisType &other)
assign another DoF iterator to this one
Definition: dofiterator.hh:237
bool operator==(const ThisType &other) const
check for equality
Definition: dofiterator.hh:268
const DofType * vector() const
Definition: dofiterator.hh:286
int index() const
get the global number of the current DoF
Definition: dofiterator.hh:255
ThisType & operator++()
increment the iterator
Definition: dofiterator.hh:261
const DofType & operator[](const int n) const
Definition: dofiterator.hh:249
const DofType & operator*() const
obtain reference to current DoF
Definition: dofiterator.hh:244
WrappedDofIteratorType ::DofType DofType
type of the DoFs
Definition: dofiterator.hh:217
Definition: bartonnackmaninterface.hh:17
const Implementation & asImp() const
Definition: bartonnackmaninterface.hh:37