dune-grid  2.2.0
common/entitypointer.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GRID_ENTITYPOINTER_HH
00002 #define DUNE_GRID_ENTITYPOINTER_HH
00003 
00004 #include <dune/common/iteratorfacades.hh>
00005 #include <dune/grid/common/grid.hh>
00006 
00011 namespace Dune
00012 {
00013 
00089 template<class GridImp, class IteratorImp>
00090 class EntityPointer
00091 {
00092   // we must be able to initialize a GenericLeafIterator.realIterator from
00093   // EntityPointer.realIterator
00094   friend class Dune::GenericLeafIterator<GridImp>;
00095 
00096   // need to make copy constructor of EntityPointer work for any iterator
00097   //friend class EntityPointer<GridImp,typename IteratorImp::EntityPointerImp>;
00098   template< class, class > friend class EntityPointer;
00099 
00100 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
00101 public:
00102 #else
00103 protected:
00104   // give the GridDefaultImplementation class access to the realImp 
00105   friend class GridDefaultImplementation< 
00106             GridImp::dimension, GridImp::dimensionworld,
00107             typename GridImp::ctype,
00108             typename GridImp::GridFamily> ;
00109 #endif
00110   // type of underlying implementation, for internal use only 
00111   typedef IteratorImp Implementation;
00112 
00114   Implementation &impl () { return realIterator; }
00116   const Implementation &impl () const { return realIterator; }
00117 
00118 protected:
00119   Implementation realIterator;
00120 
00121 public:
00123   enum { codimension = IteratorImp::codimension };
00124   
00126   typedef typename IteratorImp::Entity Entity;
00127 
00128   enum { 
00130         codim = IteratorImp::codimension 
00131   };
00132 
00133   //===========================================================
00137   //===========================================================
00138 
00145   template< class ItImp >
00146   explicit EntityPointer ( const EntityPointer< GridImp, ItImp > &ep )
00147   : realIterator( ep.realIterator )
00148   {}
00149 
00156   EntityPointer(const Entity& entity)
00157   : realIterator( entity.impl() )
00158   {}
00159 
00165   EntityPointer ( const typename Entity::Implementation &entityImp )
00166   : realIterator( entityImp )
00167   {}
00168 
00169   template< class ItImp >
00170   EntityPointer &operator= ( const EntityPointer< GridImp, ItImp > &ep )
00171   {
00172     realIterator = ep.realIterator;
00173     return *this;
00174   }
00175 
00177 
00178   //===========================================================
00182   //===========================================================
00183 
00185   Entity & operator*() const
00186     {
00187       return realIterator.dereference();
00188     }
00189 
00191   Entity * operator->() const
00192     {
00193       return & realIterator.dereference();
00194     }
00196 
00197   //===========================================================
00201   //===========================================================
00202 
00208   template< class ItImp >
00209   bool operator== ( const EntityPointer< GridImp, ItImp > &rhs ) const
00210   {
00211     return equals( rhs );
00212   }
00213 
00219   template< class ItImp >
00220   bool operator!= ( const EntityPointer< GridImp, ItImp > &rhs ) const
00221   {
00222     return !equals( rhs );
00223   }
00225 
00226 
00227   //===========================================================
00231   //===========================================================
00232 
00238   int level () const
00239     {
00240       return realIterator.level();
00241     }
00242 
00244   
00245 
00246   //===========================================================
00250   //===========================================================
00251 
00252 
00258   EntityPointer(const IteratorImp & i) :
00259     realIterator(i) {};
00260 
00262   template< class ItImp >
00263   bool equals ( const EntityPointer< GridImp, ItImp > &rhs ) const
00264   {
00265     return realIterator.equals( rhs.realIterator );
00266   }
00268 };
00269 
00270 }
00271 
00272 #endif // DUNE_GRID_ENTITYPOINTER_HH