dune-fem  2.4.1-rc
filteredgridpart/iterator.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_ITERATOR_HH
2 #define DUNE_FEM_GRIDPART_FILTEREDGRIDPART_ITERATOR_HH
3 
4 //- system includes
5 #include <cassert>
6 
7 //- dune-grid includes
8 #include <dune/grid/common/gridenums.hh>
9 
10 namespace Dune
11 {
12 
13  namespace Fem
14  {
15 
16  // FilteredGridPartIterator
17  // ------------------------
18 
19  template< int codim, PartitionIteratorType pitype, class GridPartImp >
21  {
23 
24  typedef GridPartImp GridPartType;
25  typedef typename GridPartType::HostGridPartType HostGridPartType;
26  typedef typename HostGridPartType::template Codim< codim >::template Partition< pitype >::IteratorType HostIteratorType;
27 
28  typedef typename GridPartType::template Codim< codim >::EntityPointerType EntityPointerType;
29 
30  public:
31  // type of entity
32  typedef typename HostIteratorType::Entity Entity;
33 
34  static const int codimension = codim;
35 
37  FilteredGridPartIterator ( const GridPartType &gridPart, const HostIteratorType &hostIterator )
38  : gridPart_( gridPart ),
39  hostIterator_( hostIterator ),
40  hostEnd_( gridPart.hostGridPart().template end< codim, pitype >() )
41  {
42  if( done() )
43  return;
44 
45  if( !gridPart.contains( *hostIterator_ ) )
46  increment();
47  }
48 
50  FilteredGridPartIterator ( const ThisType &other )
51  : gridPart_( other.gridPart_ ),
52  hostIterator_( other.hostIterator_ ),
53  hostEnd_( other.hostEnd_ )
54  {}
55 
57  ThisType &operator= ( const ThisType &other )
58  {
59  assert( &gridPart_ == &other.gridPart_ );
60  hostIterator_ = other.hostIterator_;
61  hostEnd_ = other.hostEnd_;
62  return *this;
63  }
64 
66  void increment ()
67  {
68  assert( !done() );
69  do { ++hostIterator_; } while ( !done() && !contains() );
70  }
71 
73  int level () const { return hostIterator_.level(); }
74 
76  Entity dereference () const { return *hostIterator_; }
77 
82  operator typename EntityPointerType::Implementation () const { return hostIterator_.impl(); }
83 
85  bool equals ( const ThisType &other ) const
86  {
87  return hostIterator_ == other.hostIterator_;
88  }
89 
90  private:
91  bool done () const
92  {
93  return (hostIterator_ == hostEnd_);
94  }
95 
96  bool contains () const
97  {
98  assert( !done() );
99  return gridPart().contains( *hostIterator_ );
100  }
101 
102  // reference to grid part
103  const GridPartType &gridPart () const { return gridPart_; }
104 
105  const GridPartType &gridPart_;
106  HostIteratorType hostIterator_;
107  HostIteratorType hostEnd_;
108  };
109 
110  } // namespace Fem
111 
112 } // namespace Dune
113 
114 #endif // #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_ITERATOR_HH
Entity dereference() const
return reference to entity object
Definition: filteredgridpart/iterator.hh:76
ThisType & operator=(const ThisType &other)
assignment operator
Definition: filteredgridpart/iterator.hh:57
FilteredGridPartIterator(const GridPartType &gridPart, const HostIteratorType &hostIterator)
constructor
Definition: filteredgridpart/iterator.hh:37
HostIteratorType::Entity Entity
Definition: filteredgridpart/iterator.hh:32
Definition: coordinate.hh:4
void increment()
increment
Definition: filteredgridpart/iterator.hh:66
static const int codimension
Definition: filteredgridpart/iterator.hh:34
bool equals(const ThisType &other) const
check for equality
Definition: filteredgridpart/iterator.hh:85
int level() const
return level
Definition: filteredgridpart/iterator.hh:73
FilteredGridPartIterator(const ThisType &other)
constructor
Definition: filteredgridpart/iterator.hh:50
Definition: filteredgridpart/iterator.hh:20