dune-fem  2.8-git
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  public:
29  // type of entity
30  typedef typename HostIteratorType::Entity Entity;
31 
32  static const int codimension = codim;
33 
35  FilteredGridPartIterator ( const GridPartType &gridPart, const HostIteratorType &hostIterator )
36  : gridPart_( gridPart ),
37  hostIterator_( hostIterator ),
38  hostEnd_( gridPart.hostGridPart().template end< codim, pitype >() )
39  {
40  if( done() )
41  return;
42 
43  if( !gridPart.contains( *hostIterator_ ) )
44  increment();
45  }
46 
49  : gridPart_( other.gridPart_ ),
50  hostIterator_( other.hostIterator_ ),
51  hostEnd_( other.hostEnd_ )
52  {}
53 
55  ThisType &operator= ( const ThisType &other )
56  {
57  assert( &gridPart_ == &other.gridPart_ );
58  hostIterator_ = other.hostIterator_;
59  hostEnd_ = other.hostEnd_;
60  return *this;
61  }
62 
64  void increment ()
65  {
66  assert( !done() );
67  do { ++hostIterator_; } while ( !done() && !contains() );
68  }
69 
71  int level () const { return hostIterator_.level(); }
72 
74  Entity dereference () const { return *hostIterator_; }
75 
77  bool equals ( const ThisType &other ) const
78  {
79  return hostIterator_ == other.hostIterator_;
80  }
81 
82  private:
83  bool done () const
84  {
85  return (hostIterator_ == hostEnd_);
86  }
87 
88  bool contains () const
89  {
90  assert( !done() );
91  return gridPart().contains( *hostIterator_ );
92  }
93 
94  // reference to grid part
95  const GridPartType &gridPart () const { return gridPart_; }
96 
97  const GridPartType &gridPart_;
98  HostIteratorType hostIterator_;
99  HostIteratorType hostEnd_;
100  };
101 
102  } // namespace Fem
103 
104 } // namespace Dune
105 
106 #endif // #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_ITERATOR_HH
Definition: bindguard.hh:11
Definition: filteredgridpart/iterator.hh:21
ThisType & operator=(const ThisType &other)
assignment operator
Definition: filteredgridpart/iterator.hh:55
static const int codimension
Definition: filteredgridpart/iterator.hh:32
void increment()
increment
Definition: filteredgridpart/iterator.hh:64
FilteredGridPartIterator(const ThisType &other)
constructor
Definition: filteredgridpart/iterator.hh:48
FilteredGridPartIterator(const GridPartType &gridPart, const HostIteratorType &hostIterator)
constructor
Definition: filteredgridpart/iterator.hh:35
HostIteratorType::Entity Entity
Definition: filteredgridpart/iterator.hh:30
int level() const
return level
Definition: filteredgridpart/iterator.hh:71
bool equals(const ThisType &other) const
check for equality
Definition: filteredgridpart/iterator.hh:77
Entity dereference() const
return reference to entity object
Definition: filteredgridpart/iterator.hh:74