dune-grid  2.2.0
common/entitypointer.hh
Go to the documentation of this file.
1 #ifndef DUNE_GRID_ENTITYPOINTER_HH
2 #define DUNE_GRID_ENTITYPOINTER_HH
3 
4 #include <dune/common/iteratorfacades.hh>
6 
11 namespace Dune
12 {
13 
89 template<class GridImp, class IteratorImp>
91 {
92  // we must be able to initialize a GenericLeafIterator.realIterator from
93  // EntityPointer.realIterator
94  friend class Dune::GenericLeafIterator<GridImp>;
95 
96  // need to make copy constructor of EntityPointer work for any iterator
97  //friend class EntityPointer<GridImp,typename IteratorImp::EntityPointerImp>;
98  template< class, class > friend class EntityPointer;
99 
100 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
101 public:
102 #else
103 protected:
104  // give the GridDefaultImplementation class access to the realImp
105  friend class GridDefaultImplementation<
106  GridImp::dimension, GridImp::dimensionworld,
107  typename GridImp::ctype,
108  typename GridImp::GridFamily> ;
109 #endif
110  // type of underlying implementation, for internal use only
111  typedef IteratorImp Implementation;
112 
116  const Implementation &impl () const { return realIterator; }
117 
118 protected:
120 
121 public:
123  enum { codimension = IteratorImp::codimension };
124 
126  typedef typename IteratorImp::Entity Entity;
127 
128  enum {
130  codim = IteratorImp::codimension
131  };
132 
133  //===========================================================
137  //===========================================================
138 
145  template< class ItImp >
147  : realIterator( ep.realIterator )
148  {}
149 
156  EntityPointer(const Entity& entity)
157  : realIterator( entity.impl() )
158  {}
159 
165  EntityPointer ( const typename Entity::Implementation &entityImp )
166  : realIterator( entityImp )
167  {}
168 
169  template< class ItImp >
171  {
173  return *this;
174  }
175 
177 
178  //===========================================================
182  //===========================================================
183 
185  Entity & operator*() const
186  {
187  return realIterator.dereference();
188  }
189 
191  Entity * operator->() const
192  {
193  return & realIterator.dereference();
194  }
196 
197  //===========================================================
201  //===========================================================
202 
208  template< class ItImp >
210  {
211  return equals( rhs );
212  }
213 
219  template< class ItImp >
221  {
222  return !equals( rhs );
223  }
225 
226 
227  //===========================================================
231  //===========================================================
232 
238  int level () const
239  {
240  return realIterator.level();
241  }
242 
244 
245 
246  //===========================================================
250  //===========================================================
251 
252 
258  EntityPointer(const IteratorImp & i) :
259  realIterator(i) {};
260 
262  template< class ItImp >
263  bool equals ( const EntityPointer< GridImp, ItImp > &rhs ) const
264  {
265  return realIterator.equals( rhs.realIterator );
266  }
268 };
269 
270 }
271 
272 #endif // DUNE_GRID_ENTITYPOINTER_HH