dune-fem  2.4.1-rc
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:
43  inline DofIteratorType &operator= ( const DofIteratorType &other )
44  {
45  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().operator=( other ) );
46  return asImp();
47  }
48 
53  inline DofType &operator* ()
54  {
55  CHECK_INTERFACE_IMPLEMENTATION( *asImp() );
56  return *asImp();
57  }
58 
63  inline const DofType &operator* () const
64  {
65  CHECK_INTERFACE_IMPLEMENTATION( *asImp() );
66  return *asImp();
67  }
68 
69  inline const DofImp &operator[] ( const int n ) const
70  {
71  CHECK_INTERFACE_IMPLEMENTATION( asImp()[ n ] );
72  return asImp()[ n ];
73  }
74 
75  inline DofImp &operator[] ( const int n )
76  {
77  CHECK_INTERFACE_IMPLEMENTATION( asImp()[ n ] );
78  return asImp()[ n ];
79  }
80 
87  inline DofIteratorType &operator++ ()
88  {
89  CHECK_AND_CALL_INTERFACE_IMPLEMENTATON( asImp().operator++() );
90  return asImp();
91  }
92 
99  inline bool operator== ( const DofIteratorType &other ) const
100  {
101  CHECK_INTERFACE_IMPLEMENTATION( asImp().operator==( other ) );
102  return asImp().operator==( other );
103  }
104 
111  inline bool operator!= ( const DofIteratorType &other ) const
112  {
113  CHECK_INTERFACE_IMPLEMENTATION( asImp().operator!=( other ) );
114  return asImp().operator!=( other );
115  }
116 
121  inline int index () const
122  {
123  CHECK_INTERFACE_IMPLEMENTATION( asImp().index() );
124  return asImp().index();
125  }
126 
128  inline 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  inline 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  inline 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  inline bool operator!= ( const DofIteratorType &other ) const
184  {
185  return !asImp().operator==( other );
186  }
187 
189  inline 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 
219  public:
222 
223  protected:
224  WrappedDofIteratorType it_;
225 
226  public:
227  inline ConstDofIteratorDefault( const WrappedDofIteratorType &it )
228  : it_( it )
229  {
230  }
231 
232  inline ConstDofIteratorDefault( const ThisType &other )
233  : it_( other.it_ )
234  {
235  }
236 
238  inline const ThisType &operator= ( const ThisType &other )
239  {
240  it_ = other.it_;
241  return *this;
242  }
243 
245  const DofType& operator* () const
246  {
247  return (*it_);
248  }
249 
250  inline const DofType &operator[] ( const int n ) const
251  {
252  return it_[ n ];
253  }
254 
256  inline int index () const
257  {
258  return it_.index();
259  }
260 
262  inline ThisType &operator++ ()
263  {
264  ++it_;
265  return (*this);
266  }
267 
269  inline bool operator== ( const ThisType &other ) const
270  {
271  return (it_ == other.it_);
272  }
273 
275  inline bool operator!= ( const ThisType &other ) const
276  {
277  return (it_ != other.it_);
278  }
279 
281  inline void reset ()
282  {
283  it_.reset();
284  }
285 
286  // note: this method is not in the interface!
287  const DofType *vector () const
288  {
289  return it_.vector();
290  }
291  }; // end class DofIteratorDefault
292 
293  } // namespace Fem
294 
295 } // namespace Dune
296 
297 #endif // #ifndef DUNE_FEM_DOFITERATOR_HH
DofImp DofType
type of the DoFs
Definition: dofiterator.hh:26
DofIteratorType & operator=(const DofIteratorType &other)
assign another DoF iterator to this one
Definition: dofiterator.hh:43
DofIteratorImp DofIteratorType
type of the implementation (Barton-Nackman)
Definition: dofiterator.hh:149
int index() const
get the global number of the current DoF
Definition: dofiterator.hh:256
Definition: dofiterator.hh:208
ConstDofIteratorDefault(const WrappedDofIteratorType &it)
Definition: dofiterator.hh:227
DofIteratorImp WrappedDofIteratorType
type of the wrapped DoF iterator
Definition: dofiterator.hh:214
DofIteratorImp DofIteratorType
type of the implementation (Barton-Nackman)
Definition: dofiterator.hh:29
const Implementation & asImp() const
Definition: bartonnackmaninterface.hh:37
bool operator==(const DofIteratorType &other) const
check for equality
Definition: dofiterator.hh:99
int index() const
Definition: dofiterator.hh:189
WrappedDofIteratorType::DofType DofType
type of the DoFs
Definition: dofiterator.hh:217
WrappedDofIteratorType it_
Definition: dofiterator.hh:224
interface for DoF iterators of discrete functions
Definition: dofiterator.hh:20
void reset()
reset iterator to the first position
Definition: dofiterator.hh:128
Definition: coordinate.hh:4
const DofType * vector() const
Definition: dofiterator.hh:287
ConstDofIteratorDefault< WrappedDofIteratorType > ThisType
Definition: dofiterator.hh:220
int index() const
get the global number of the current DoF
Definition: dofiterator.hh:121
DofIteratorType & operator++()
increment the iterator
Definition: dofiterator.hh:87
DofImp DofType
type of the DoFs
Definition: dofiterator.hh:146
void reset()
reset iterator to the first position
Definition: dofiterator.hh:281
void reset()
Definition: combinedfunction/combinedfunction.hh:494
default implementation of DofManagerInterface
Definition: dofiterator.hh:141
bool operator!=(const DofIteratorType &other) const
check for inequality
Definition: dofiterator.hh:111
DofType & operator*()
obtain reference to current DoF
Definition: dofiterator.hh:53
ConstDofIteratorDefault(const ThisType &other)
Definition: dofiterator.hh:232
const DofImp & operator[](const int n) const
Definition: dofiterator.hh:69
DofIteratorDefault< DofType, ThisType > BaseType
Definition: dofiterator.hh:221
Definition: bartonnackmaninterface.hh:15