dune-grid  2.3.1-rc1
geometrygrid/intersectioniterator.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOGRID_INTERSECTIONITERATOR_HH
4 #define DUNE_GEOGRID_INTERSECTIONITERATOR_HH
5 
8 
9 namespace Dune
10 {
11 
12  namespace GeoGrid
13  {
14 
15  // IntersectionIterator
16  // --------------------
17 
18  template< class Grid, class HostIntersectionIterator >
19  class IntersectionIterator
20  {
21  typedef typename remove_const< Grid >::type::Traits Traits;
22 
23  typedef GeoGrid::Intersection< Grid, typename HostIntersectionIterator::Intersection > IntersectionImpl;
24 
25  typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
26  typedef typename Traits::template Codim< 0 >::Geometry ElementGeometry;
27 
28  public:
30 
31  typedef typename Traits::template Codim< 0 >::EntityPointer EntityPointer;
32 
33  template< class Entity >
34  IntersectionIterator ( const Entity &inside,
35  const HostIntersectionIterator &hostIterator )
36  : hostIterator_( hostIterator ),
37  intersection_( IntersectionImpl( inside.geometry() ) )
38  {}
39 
41  : hostIterator_( other.hostIterator_ ),
42  intersection_( IntersectionImpl( Grid::getRealImplementation( other.intersection_ ) ) )
43  {}
44 
46  {
47  hostIterator_ = other.hostIterator_;
48  Grid::getRealImplementation( intersection_ ) = Grid::getRealImplementation( other.intersection_ );
49  return *this;
50  }
51 
52  bool equals ( const IntersectionIterator &other ) const
53  {
54  return (hostIterator_ == other.hostIterator_);
55  }
56 
57  void increment ()
58  {
59  ++hostIterator_;
60  intersectionImpl().invalidate();
61  }
62 
63  const Intersection &dereference () const
64  {
65  if( !intersectionImpl() )
66  intersectionImpl().initialize( *hostIterator_ );
67  return intersection_;
68  }
69 
70  private:
71  IntersectionImpl &intersectionImpl () const
72  {
73  return Grid::getRealImplementation( intersection_ );
74  }
75 
76  HostIntersectionIterator hostIterator_;
77  mutable Intersection intersection_;
78  };
79 
80  } // namespace GeoGrid
81 
82 } // namespace Dune
83 
84 #endif // #ifndef DUNE_GEOGRID_INTERSECTIONITERATOR_HH
IntersectionIterator(const Entity &inside, const HostIntersectionIterator &hostIterator)
Definition: geometrygrid/intersectioniterator.hh:34
void initialize(const HostIntersection &hostIntersection)
Definition: geometrygrid/intersection.hh:186
IntersectionIterator(const IntersectionIterator &other)
Definition: geometrygrid/intersectioniterator.hh:40
DUNE-conform implementation of the entityThis class merely changes the template parameters of the ent...
Definition: geometrygrid/entity.hh:49
Traits::template Codim< 0 >::EntityPointer EntityPointer
Definition: geometrygrid/intersectioniterator.hh:31
Definition: geometrygrid/intersection.hh:20
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:386
bool equals(const IntersectionIterator &other) const
Definition: geometrygrid/intersectioniterator.hh:52
IntersectionIterator & operator=(const IntersectionIterator &other)
Definition: geometrygrid/intersectioniterator.hh:45
const Intersection & dereference() const
Definition: geometrygrid/intersectioniterator.hh:63
Dune::Intersection< Grid, IntersectionImpl > Intersection
Definition: geometrygrid/intersectioniterator.hh:29
void invalidate()
Definition: geometrygrid/intersection.hh:180
void increment()
Definition: geometrygrid/intersectioniterator.hh:57
Definition: geometrygrid/entity.hh:60