albertagrid/entitypointer.hh
00001 #ifndef DUNE_ALBERTA_ENTITYPOINTER_HH
00002 #define DUNE_ALBERTA_ENTITYPOINTER_HH
00003
00004 #include <dune/grid/common/entitypointer.hh>
00005
00006 #include <dune/grid/albertagrid/elementinfo.hh>
00007
00008 namespace Dune
00009 {
00010
00011
00012
00013
00014 template< int dim, int dimworld >
00015 class AlbertaGrid;
00016
00017
00018
00023 template< int codim, class GridImp >
00024 class AlbertaGridEntityPointer
00025 {
00026 typedef AlbertaGridEntityPointer< codim, GridImp > This;
00027
00028 friend class AlbertaGrid< GridImp::dimension, GridImp::dimensionworld >;
00029
00030 public:
00031 static const int dimension = GridImp::dimension;
00032 static const int codimension = codim;
00033 static const int mydimension = dimension - codimension;
00034 static const int dimensionworld = GridImp::dimensionworld;
00035
00036 typedef typename GridImp::template Codim< codimension >::Entity Entity;
00037
00038 protected:
00039 typedef MakeableInterfaceObject< Entity > EntityObject;
00040 typedef typename EntityObject::ImplementationType EntityImp;
00041
00042 public:
00043 typedef AlbertaGridEntityPointer< codimension, GridImp > EntityPointerImp;
00044
00045 typedef typename EntityImp::ElementInfo ElementInfo;
00046
00048 AlbertaGridEntityPointer ( const GridImp &grid,
00049 const ElementInfo &elementInfo,
00050 int subEntity );
00051
00053 AlbertaGridEntityPointer ( const GridImp &grid );
00054
00056 AlbertaGridEntityPointer ( const EntityImp &entity );
00057
00059 AlbertaGridEntityPointer ( const This &other );
00060
00062 ~AlbertaGridEntityPointer();
00063
00065 This &operator= ( const This &other );
00066
00068 bool equals ( const This &other ) const;
00069
00071 Entity &dereference () const;
00072
00074 int level () const;
00075
00077 void compactify ();
00078
00079 protected:
00081 EntityImp &entityImp ();
00082
00084 const EntityImp &entityImp () const;
00085
00087 const GridImp &grid () const;
00088
00089 private:
00090 EntityObject *entity_;
00091 };
00092
00093
00094
00095 template< int codim, class GridImp >
00096 inline AlbertaGridEntityPointer< codim, GridImp >
00097 ::AlbertaGridEntityPointer ( const GridImp &grid,
00098 const ElementInfo &elementInfo,
00099 int subEntity )
00100 : entity_( grid.template getNewEntity< codim >() )
00101 {
00102 assert( entity_ != 0 );
00103 entityImp().setElement( elementInfo, subEntity );
00104 }
00105
00106
00107 template<int codim, class GridImp >
00108 inline AlbertaGridEntityPointer< codim, GridImp >
00109 ::AlbertaGridEntityPointer ( const GridImp &grid )
00110 : entity_( grid.template getNewEntity< codim >() )
00111 {
00112 assert( entity_ != 0 );
00113 entityImp().clearElement();
00114 }
00115
00116
00117 template< int codim, class GridImp >
00118 inline AlbertaGridEntityPointer< codim, GridImp >
00119 ::AlbertaGridEntityPointer ( const EntityImp &entity )
00120 : entity_( entity.grid().template getNewEntity< codim >() )
00121 {
00122 assert( entity_ != 0 );
00123 entityImp().setEntity( entity );
00124 }
00125
00126
00127 template< int codim, class GridImp >
00128 inline AlbertaGridEntityPointer< codim, GridImp >
00129 ::AlbertaGridEntityPointer ( const This &other )
00130 : entity_( other.grid().template getNewEntity< codim >() )
00131 {
00132 assert( entity_ != 0 );
00133 entityImp().setEntity( other.entityImp() );
00134 }
00135
00136
00137 template<int codim, class GridImp >
00138 inline AlbertaGridEntityPointer< codim, GridImp >::~AlbertaGridEntityPointer ()
00139 {
00140 entityImp().clearElement();
00141 grid().template freeEntity< codim >( entity_ );
00142 entity_ = 0;
00143 }
00144
00145
00146 template< int codim, class GridImp >
00147 inline typename AlbertaGridEntityPointer< codim, GridImp >::This &
00148 AlbertaGridEntityPointer< codim, GridImp >::operator= ( const This &other )
00149 {
00150 entityImp().setEntity( other.entityImp() );
00151 return *this;
00152 }
00153
00154
00155 template<int codim, class GridImp >
00156 inline bool
00157 AlbertaGridEntityPointer< codim, GridImp >::equals ( const This &other ) const
00158 {
00159 return entityImp().equals( other.entityImp() );
00160 }
00161
00162
00163 template<int codim, class GridImp >
00164 inline typename AlbertaGridEntityPointer< codim, GridImp >::Entity &
00165 AlbertaGridEntityPointer< codim, GridImp >::dereference () const
00166 {
00167 assert( entity_ != 0 );
00168 return *entity_;
00169 }
00170
00171
00172 template< int codim, class GridImp >
00173 inline int AlbertaGridEntityPointer< codim, GridImp >::level () const
00174 {
00175 return entityImp().level();
00176 }
00177
00178
00179 template< int codim, class GridImp >
00180 inline void AlbertaGridEntityPointer< codim, GridImp >::compactify ()
00181 {}
00182
00183
00184 template< int codim, class GridImp >
00185 inline typename AlbertaGridEntityPointer<codim,GridImp>::EntityImp &
00186 AlbertaGridEntityPointer< codim, GridImp >::entityImp ()
00187 {
00188 assert( entity_ != 0 );
00189 return GridImp::getRealImplementation( *entity_ );
00190 }
00191
00192
00193 template< int codim, class GridImp >
00194 inline const typename AlbertaGridEntityPointer< codim, GridImp >::EntityImp &
00195 AlbertaGridEntityPointer< codim, GridImp >::entityImp () const
00196 {
00197 assert( entity_ != 0 );
00198 return GridImp::getRealImplementation( *entity_ );
00199 }
00200
00201
00202 template< int codim, class GridImp >
00203 inline const GridImp &AlbertaGridEntityPointer< codim, GridImp >::grid () const
00204 {
00205 return entityImp().grid();
00206 }
00207
00208 }
00209
00210 #endif