dune-grid  2.2.1
geometrygrid/intersectioniterator.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOGRID_INTERSECTIONITERATOR_HH
2 #define DUNE_GEOGRID_INTERSECTIONITERATOR_HH
3 
6 
7 namespace Dune
8 {
9 
10  // External Forward Declataions
11  // ----------------------------
12 
13  namespace GeoGrid
14  {
15 
16  // Internal Forward Declarations
17  // -----------------------------
18 
19  template< class Grid >
20  class LeafIntersectionIterator;
21 
22  template< class Grid >
23  class LevelIntersectionIterator;
24 
25 
26 
27  // IntersectionIterator
28  // --------------------
29 
30  template< class Traits >
32  {
33  typedef typename Traits::HostIntersectionIterator HostIntersectionIterator;
34 
35  typedef typename Traits::GridTraits GridTraits;
36 
37  public:
38  typedef typename Traits::Intersection Intersection;
39  typedef typename GridTraits::Grid Grid;
40 
41  typedef typename GridTraits::template Codim< 0 >::EntityPointer EntityPointer;
42 
43  private:
44  typedef typename Traits::IntersectionImpl IntersectionImpl;
45 
46  typedef typename GridTraits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
47  typedef typename GridTraits::template Codim< 0 >::Geometry ElementGeometry;
48 
49  public:
50  template< class Entity >
51  IntersectionIterator ( const Entity &inside,
52  const HostIntersectionIterator &hostIterator )
53  : hostIterator_( hostIterator ),
54  intersection_( IntersectionImpl( inside.geometry() ) )
55  {}
56 
58  : hostIterator_( other.hostIterator_ ),
59  intersection_( IntersectionImpl( Grid::getRealImplementation( other.intersection_ ) ) )
60  {}
61 
63  {
64  hostIterator_ = other.hostIterator_;
65  Grid::getRealImplementation( intersection_ ) = Grid::getRealImplementation( other.intersection_ );
66  return *this;
67  }
68 
69  bool equals ( const IntersectionIterator &other ) const
70  {
71  return (hostIterator_ == other.hostIterator_);
72  }
73 
74  void increment ()
75  {
76  ++hostIterator_;
77  intersectionImpl().invalidate();
78  }
79 
80  const Intersection &dereference () const
81  {
82  if( !intersectionImpl() )
83  intersectionImpl().initialize( *hostIterator_ );
84  return intersection_;
85  }
86 
87  private:
88  IntersectionImpl &intersectionImpl () const
89  {
90  return Grid::getRealImplementation( intersection_ );
91  }
92 
93  HostIntersectionIterator hostIterator_;
94  mutable Intersection intersection_;
95  };
96 
97 
98 
99  // LeafIntersectionIteratorTraits
100  // ------------------------------
101 
102  template< class Grid >
104  {
105  typedef typename remove_const< Grid >::type::Traits GridTraits;
106 
109 
110  typedef typename GridTraits::HostGrid::Traits::LeafIntersectionIterator
112  };
113 
114 
115 
116  // LeafIntersectionIterator
117  // ------------------------
118 
119  template< class Grid >
121  : public IntersectionIterator< LeafIntersectionIteratorTraits< Grid > >
122  {
124  typedef IntersectionIterator< Traits > Base;
125 
126  typedef typename Traits :: HostIntersectionIterator HostIntersectionIterator;
127 
128  public:
130 
131  public:
132  template< class Entity >
134  const HostIntersectionIterator &hostIterator )
135  : Base( inside, hostIterator )
136  {}
137  };
138 
139 
140 
141  // LevelIntersectionIteratorTraits
142  // -------------------------------
143 
144  template< class Grid >
146  {
147  typedef typename remove_const< Grid >::type::Traits GridTraits;
148 
151 
152  typedef typename GridTraits::HostGrid::Traits::LevelIntersectionIterator
154  };
155 
156 
157 
158  // LevelIntersectionIterator
159  // -------------------------
160 
161  template< class Grid >
163  : public IntersectionIterator< LevelIntersectionIteratorTraits< Grid > >
164  {
166  typedef IntersectionIterator< Traits > Base;
167 
168  typedef typename Traits :: HostIntersectionIterator HostIntersectionIterator;
169 
170  public:
172 
173  public:
174  template< class Entity >
176  const HostIntersectionIterator &hostIterator )
177  : Base( inside, hostIterator )
178  {}
179  };
180 
181  } // namespace GeoGrid
182 
183 } // namespace Dune
184 
185 #endif // #ifndef DUNE_GEOGRID_INTERSECTIONITERATOR_HH