00001 #ifndef DUNE_GRID_ENTITYPOINTER_HH
00002 #define DUNE_GRID_ENTITYPOINTER_HH
00003
00004 #include <dune/common/iteratorfacades.hh>
00005
00010 namespace Dune
00011 {
00012
00098 template<class GridImp, class IteratorImp>
00099 class EntityPointer
00100 {
00101
00102
00103 friend class Dune::GenericLeafIterator<GridImp>;
00104
00105
00106 friend class EntityPointer<GridImp,typename IteratorImp::Base>;
00107
00108 protected:
00109 IteratorImp realIterator;
00110
00111 public:
00113 typedef IteratorImp ImplementationType;
00114
00116 typedef typename
00117 Dune::EnableIfInterOperable<typename IteratorImp::base,IteratorImp,
00118 typename IteratorImp::base>::type base;
00119
00121 typedef typename IteratorImp::Entity Entity;
00122
00123 enum {
00125 codim = IteratorImp::codimension
00126 };
00127
00128
00132
00133
00140 template<class ItImp>
00141 EntityPointer(const EntityPointer<GridImp,ItImp> & ep) :
00142 realIterator(ep.realIterator) {}
00143
00148 operator EntityPointer<GridImp,base>&()
00149 {
00150 return reinterpret_cast<EntityPointer<GridImp,base>&>(*this);
00151 };
00152
00157 operator const EntityPointer<GridImp,base>&() const
00158 {
00159 return reinterpret_cast<const EntityPointer<GridImp,base>&>(*this);
00160 };
00162
00163
00164
00168
00169
00171 Entity & operator*() const
00172 {
00173 return realIterator.dereference();
00174 }
00175
00177 Entity * operator->() const
00178 {
00179 return & realIterator.dereference();
00180 }
00182
00183
00184
00188
00189
00195 bool operator==(const EntityPointer<GridImp,base>& rhs) const
00196 {
00197 return rhs.equals(*this);
00198 }
00199
00205 bool operator!=(const EntityPointer<GridImp,base>& rhs) const
00206 {
00207 return ! rhs.equals(*this);
00208 }
00210
00211
00212
00216
00217
00223 int level () const
00224 {
00225 return realIterator.level();
00226 }
00227
00229
00230
00231
00235
00236
00237
00243 EntityPointer(const IteratorImp & i) :
00244 realIterator(i) {};
00245
00247 bool equals(const EntityPointer& rhs) const
00248 {
00249 return this->realIterator.equals(rhs.realIterator);
00250 }
00252
00253 protected:
00254
00255
00256 friend class GridDefaultImplementation<
00257 GridImp::dimension, GridImp::dimensionworld,
00258 typename GridImp::ctype,
00259 typename GridImp::GridFamily> ;
00260
00262 ImplementationType & getRealImp() { return realIterator; }
00264 const ImplementationType & getRealImp() const { return realIterator; }
00265
00266 };
00267
00268
00269
00270
00271
00273
00274 template<int codim, class GridImp, class IteratorImp>
00275 class EntityPointerDefaultImplementation
00276 {
00277 public:
00278 typedef IteratorImp base;
00279
00281 enum { codimension = codim };
00282
00283 private:
00285 IteratorImp& asImp () {
00286 return static_cast<IteratorImp&>(*this);
00287 }
00288 const IteratorImp& asImp () const {
00289 return static_cast<const IteratorImp&>(*this);
00290 }
00291 };
00292
00293 }
00294
00295 #endif // DUNE_GRID_ENTITYPOINTER_HH