dune-grid
2.1.1
|
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 protected: 00101 IteratorImp realIterator; 00102 00103 // autocheck whether imp is convertable into imp::base 00104 typedef typename 00105 Dune::EnableIfInterOperable<typename IteratorImp::EntityPointerImp,IteratorImp, 00106 typename IteratorImp::EntityPointerImp>::type base; 00107 00108 public: 00110 enum { codimension = IteratorImp::codimension }; 00111 00113 typedef IteratorImp ImplementationType; 00114 00116 typedef typename IteratorImp::Entity Entity; 00117 00118 enum { 00120 codim = IteratorImp::codimension 00121 }; 00122 00123 //=========================================================== 00127 //=========================================================== 00128 00135 template< class ItImp > 00136 explicit EntityPointer ( const EntityPointer< GridImp, ItImp > &ep ) 00137 : realIterator( ep.realIterator ) 00138 {} 00139 00146 EntityPointer(const Entity& entity) : 00147 realIterator( entity.getRealImp() ) {} 00148 00154 EntityPointer(const typename Entity :: ImplementationType& entityImp) : 00155 realIterator( entityImp ) {} 00156 00157 template< class ItImp > 00158 EntityPointer &operator= ( const EntityPointer< GridImp, ItImp > &ep ) 00159 { 00160 realIterator = ep.realIterator; 00161 return *this; 00162 } 00163 00169 operator const EntityPointer< GridImp, base > & () const DUNE_DEPRECATED 00170 { 00171 return reinterpret_cast<const EntityPointer<GridImp,base>&>(*this); 00172 } 00173 00179 void compactify () DUNE_DEPRECATED 00180 { 00181 realIterator.compactify(); 00182 } 00183 00185 00186 //=========================================================== 00190 //=========================================================== 00191 00193 Entity & operator*() const 00194 { 00195 return realIterator.dereference(); 00196 } 00197 00199 Entity * operator->() const 00200 { 00201 return & realIterator.dereference(); 00202 } 00204 00205 //=========================================================== 00209 //=========================================================== 00210 00216 template< class ItImp > 00217 bool operator== ( const EntityPointer< GridImp, ItImp > &rhs ) const 00218 { 00219 return equals( rhs ); 00220 } 00221 00227 template< class ItImp > 00228 bool operator!= ( const EntityPointer< GridImp, ItImp > &rhs ) const 00229 { 00230 return !equals( rhs ); 00231 } 00233 00234 00235 //=========================================================== 00239 //=========================================================== 00240 00246 int level () const 00247 { 00248 return realIterator.level(); 00249 } 00250 00252 00253 00254 //=========================================================== 00258 //=========================================================== 00259 00260 00266 EntityPointer(const IteratorImp & i) : 00267 realIterator(i) {}; 00268 00270 template< class ItImp > 00271 bool equals ( const EntityPointer< GridImp, ItImp > &rhs ) const 00272 { 00273 return realIterator.equals( rhs.realIterator ); 00274 } 00276 00277 protected: 00278 // give the GridDefaultImplementation class access to the realImp 00279 friend class GridDefaultImplementation< 00280 GridImp::dimension, GridImp::dimensionworld, 00281 typename GridImp::ctype, 00282 typename GridImp::GridFamily> ; 00283 00285 ImplementationType & getRealImp() { return realIterator; } 00287 const ImplementationType & getRealImp() const { return realIterator; } 00288 00289 }; 00290 00291 } 00292 00293 #endif // DUNE_GRID_ENTITYPOINTER_HH