dune-grid  2.4.1
common/entitypointer.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GRID_ENTITYPOINTER_HH
4 #define DUNE_GRID_ENTITYPOINTER_HH
5 
6 #include <utility>
7 
8 #include <dune/common/proxymemberaccess.hh>
9 #include <dune/common/iteratorfacades.hh>
10 #include <dune/common/deprecated.hh>
11 #include <dune/grid/common/grid.hh>
12 
17 #define DUNE_ENTITYPOINTER_DEPRECATED_MSG DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. Instead, you can copy and store entities directly now. Note, this might lead to a decreased performance until all grid implementations properly addressed this interface change.")
18 namespace Dune
19 {
20 
21  // External forward declaration
22  // ----------------------------
23 
24  template< int, int, class, template< int, int, class > class >
25  class Entity;
26 
27 
28 
111  template<class GridImp, class IteratorImp>
113  {
114  // need to make copy constructor of EntityPointer work for any iterator
115  //friend class EntityPointer<GridImp,typename IteratorImp::EntityPointerImp>;
116  template< class, class > friend class EntityPointer;
117 
118 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
119  public:
120 #else
121  protected:
122  // give the GridDefaultImplementation class access to the realImp
123  friend class GridDefaultImplementation<
124  GridImp::dimension, GridImp::dimensionworld,
125  typename GridImp::ctype,
126  typename GridImp::GridFamily> ;
127 #endif
128  // type of underlying implementation, for internal use only
129  typedef IteratorImp Implementation;
130 
134  const Implementation &impl () const { return realIterator; }
135 
136  protected:
138 
139  public:
141  enum { codimension = IteratorImp::codimension };
142 
144  typedef typename IteratorImp::Entity Entity;
145 
147  typedef typename std::conditional<
148  std::is_lvalue_reference<
149  decltype(realIterator.dereference())
150  >::value,
151  const Entity&,
152  Entity
154 
155  //===========================================================
159  //===========================================================
160 
167  template< class ItImp >
169  : realIterator( ep.realIterator )
170  {}
171 
174  {}
175 
183  EntityPointer(const Entity& entity)
184  : realIterator( entity.impl() )
185  {}
186 
192  EntityPointer ( const typename Entity::Implementation &entityImp )
193  : realIterator( entityImp )
194  {}
195 
196  template< class ItImp >
199  {
200  realIterator = ep.realIterator;
201  return *this;
202  }
203 
205 
206  //===========================================================
210  //===========================================================
211 
212  // The behavior when dereferencing the EntityPointer facade depends on
213  // the way the grid implementation handles returning entities. The implementation
214  // may either return a reference to an entity stored inside the EntityPointer
215  // implementation or a temporary Entity object. This object has to be forwarded through
216  // the facade to the user, which requires a little trickery, especially for operator->().
217  //
218  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
219  // function signatures to Doxygen and hide the actual implementations.
220 
221 #ifdef DOXYGEN
222 
224  Entity operator*() const
226 
227 
229  const Entity* operator->() const
231 
232 #else // DOXYGEN
233 
235  Reference
236  operator*() const
237  DUNE_ENTITYPOINTER_DEPRECATED_MSG
238  {
239  return realIterator.dereference();
240  }
241 
243  decltype(handle_proxy_member_access(realIterator.dereference()))
244  operator->() const
245  DUNE_ENTITYPOINTER_DEPRECATED_MSG
246  {
247  return handle_proxy_member_access(realIterator.dereference());
248  }
249 
250  template<typename T>
251  // this construction, where the deprecation warning is triggered by a separate function,
252  // is slightly convoluted, but I could not get the warning to trigger reliably when attached
253  // directly to the cast operator.
254  DUNE_DEPRECATED_MSG("The implicit cast from EntityPointer to an Entity reference is DANGEROUS. It's mainly there for writing backwards compatible code that doesn't trigger a deprecation warning for ported grids and must ONLY be used if the returned reference is used in an rvalue-like setting!")
255  void trigger_entity_cast_warning() const
256  {}
257 
258  template<typename T, typename std::enable_if<std::is_same<T,Entity>::value,int>::type = 0>
259  operator const T&() const
260  {
261  static_assert(std::is_same<T,Entity>::value,"invalid cast");
262  trigger_entity_cast_warning<T>();
263  return realIterator.dereference();
264  }
265 
266 #endif // DOXYGEN
267 
269 
270  //===========================================================
274  //===========================================================
275 
281  template< class ItImp >
283  {
284  return equals( rhs );
285  }
286 
292  template< class ItImp >
294  {
295  return !equals( rhs );
296  }
298 
304  DUNE_ENTITYPOINTER_DEPRECATED_MSG
305  bool operator==(const Entity& rhs) const
306  {
307  return (**this) == rhs;
308  }
309 
315  DUNE_ENTITYPOINTER_DEPRECATED_MSG
316  bool operator!=(const Entity& rhs) const
317  {
318  return (**this) != rhs;
319  }
320 
321 
322  //===========================================================
326  //===========================================================
327 
337  int level () const
338  DUNE_ENTITYPOINTER_DEPRECATED_MSG
339  {
340  return realIterator.level();
341  }
342 
344 
345 
346  //===========================================================
350  //===========================================================
351 
357  EntityPointer(const IteratorImp & i) :
358  realIterator(i) {}
359 
361  template< class ItImp >
362  bool equals ( const EntityPointer< GridImp, ItImp > &rhs ) const
363  {
364  return realIterator.equals( rhs.realIterator );
365  }
367 
368  //===========================================================
372  //===========================================================
373 
375  typedef typename GridImp::template Codim<codimension>::Geometry Geometry;
376 
378  typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed;
379 
387  typedef typename GridImp::template Codim<codimension>::LocalGeometry LocalGeometry;
388 
390  template <int cd>
391  struct Codim
392  {
393  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
394  typedef typename GridImp::template Codim<cd>::Entity Entity;
395  };
396 
398  // typedef typename Entity::EntityPointer EntityPointer;
399 
401  typedef typename GridImp::HierarchicIterator HierarchicIterator;
402 
403  enum {
406  };
407  enum {
410  };
411 
413  PartitionType partitionType () const { return realIterator.dereference().partitionType(); }
414 
427  Geometry geometry () const { return realIterator.dereference().geometry(); }
428 
432  GeometryType type () const { return realIterator.dereference().type(); }
433 
437  EntitySeed seed () const { return realIterator.dereference().seed(); }
438 
439 #define CHECK_CODIM0 int ecodim = codimension, typename std::enable_if<ecodim == 0,int>::type = 0
440 #define ONLY_CODIM0 template<int ecodim = codimension, typename std::enable_if<ecodim == 0,int>::type = 0>
441 
442  template< int codim, CHECK_CODIM0 >
443  typename Codim<codim>::Entity
444  subEntity ( int i ) const
445  {
446  return realIterator.dereference().template subEntity< codim >(i);
447  }
448 
453  bool hasFather () const
454  {
455  return realIterator.dereference().hasFather();
456  }
457 
460  bool isLeaf () const
461  {
462  return realIterator.dereference().isLeaf();
463  }
464 
469  bool isRegular() const { return realIterator.dereference().isRegular(); }
470 
497  LocalGeometry geometryInFather () const { return realIterator.dereference().geometryInFather(); }
498 
511  HierarchicIterator hbegin (int maxLevel) const
512  {
513  return realIterator.dereference().hbegin(maxLevel);
514  }
515 
524  HierarchicIterator hend (int maxLevel) const
525  {
526  return realIterator.dereference().hend(maxLevel);
527  }
528 
532  bool isNew () const { return realIterator.dereference().isNew(); }
533 
539  bool mightVanish () const { return realIterator.dereference().mightVanish(); }
540 
544  bool hasBoundaryIntersections () const { return realIterator.dereference().hasBoundaryIntersections(); }
546 
547  };
548 
549 
550 
551 #ifndef DOXYEN
552 
553  // DefaultEntityPointer
554  // --------------------
555 
556  /* The EntityPointer class defined above has been deprecated. Unitil its
557  final removal valid Dune grids still have to provide at least a suitable
558  EntityPointer typedef. This class provides a default implementation of an
559  entity pointer from a given Dune::Entity type:
560  \code
561  struct GridFamily
562  {
563  ...
564  typedef ImplementationDefined Entity;
565  typedef DefaultEntityPointer<Entity> EntityPointer;
566  ...
567  };
568  \endcode
569 
570  This class will retain a possible compatibility support with the
571  deprecated interface behavior if the iterator classes in the grid
572  implementation provide the following two additional methods:
573  \code
574  class Iterator
575  {
576  // dereference() method required by Dune::EntityIterator
577  typedef ImplemenatationDefined Entity;
578  Entity dereference () const;
579 
580  // allow for (deprecated) construction/assignment of EntityPointer from a given iterator
581  operator Dune::DefaultEntityPointer<Entity>() const
582  {
583  return Dune::DefaultEntityPointer<Entity>(dereference());
584  }
585 
586  // allow for (deprecated) comparison of an iterator with an entity pointer
587  bool equals(const Dune::DefaultEntityPointer<Entity> &rhs) const
588  {
589  return dereference() == rhs.dereference();
590  }
591  };
592  \endcode
593  */
594  template< class E >
596 
597  template< int codim, int dim, class Grid, template< int, int, class > class EntityImp >
598  class DefaultEntityPointer< Dune::Entity< codim, dim, Grid, EntityImp > >
599  {
600  public:
601  static const int codimension = codim;
602 
604 
606 
607  explicit DefaultEntityPointer ( Entity entity )
608  : entity_( std::move( entity ) )
609  {}
610 
611  explicit DefaultEntityPointer ( EntityImp< codim, dim, Grid > entity )
612  : entity_( std::move( entity ) )
613  {}
614 
615  const Entity &dereference () const { return entity_; }
616 
617  bool equals ( const DefaultEntityPointer &rhs ) const
618  {
619  return entity_ == rhs.entity_;
620  }
621 
622  int level () const { return entity_.level(); }
623 
624  private:
625  Entity entity_;
626  };
627 
628 #endif // #ifndef DOXYEN
629 
630 }
631 #undef DUNE_ENTITYPOINTER_DEPRECATED_MSG
632 
633 #endif // DUNE_GRID_ENTITYPOINTER_HH
GridImp::template Codim< cd >::Entity Entity
Definition: common/entitypointer.hh:394
const Entity * operator->() const DUNE_ENTITYPOINTER_DEPRECATED_MSG
Pointer operator.
ONLY_CODIM0 bool isRegular() const
Returns true if element is of regular type in red/green type refinement. In bisection or hanging node...
Definition: common/entitypointer.hh:469
Codim< codim >::Entity subEntity(int i) const
Definition: common/entitypointer.hh:444
Definition: common/entitypointer.hh:595
DUNE_ENTITYPOINTER_DEPRECATED_MSG bool operator==(const Entity &rhs) const
Compares an EntityPointer with an Entity for equality.
Definition: common/entitypointer.hh:305
DefaultEntityPointer(Entity entity)
Definition: common/entitypointer.hh:607
ONLY_CODIM0 HierarchicIterator hend(int maxLevel) const
Returns iterator to one past the last son element.
Definition: common/entitypointer.hh:524
DUNE_ENTITYPOINTER_DEPRECATED_MSG bool operator!=(const Entity &rhs) const
Compares an EntityPointer with an Entity for inequality.
Definition: common/entitypointer.hh:316
Know dimension of the entity.
Definition: common/entitypointer.hh:409
bool equals(const DefaultEntityPointer &rhs) const
Definition: common/entitypointer.hh:617
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:178
EntityPointer(const typename Entity::Implementation &entityImp)
Constructor from type of entity implementation that this entity pointer points to. This constructor is only used in the EntityDefaultImplementation to implement the method seed() by default when the type of EntitySeed and EntityPointer coniside.
Definition: common/entitypointer.hh:192
ONLY_CODIM0 bool isLeaf() const
Returns true if the entity is contained in the leaf grid.
Definition: common/entitypointer.hh:460
bool equals(const EntityPointer< GridImp, ItImp > &rhs) const
Forward equality check to realIterator.
Definition: common/entitypointer.hh:362
int level() const
Definition: common/entitypointer.hh:622
const Entity & dereference() const
Definition: common/entitypointer.hh:615
EntityPointer types of the different codimensions.
Definition: common/entitypointer.hh:391
Wrapper class for pointers to entities.
Definition: common/entitypointer.hh:112
Definition: common/geometry.hh:24
DUNE_ENTITYPOINTER_DEPRECATED_MSG EntityPointer & operator=(const EntityPointer< GridImp, ItImp > &ep)
Definition: common/entitypointer.hh:198
IteratorImp::Entity Entity
The Entity that this EntityPointer can point to.
Definition: common/entitypointer.hh:144
Implementation & impl()
return reference to the real implementation
Definition: common/entitypointer.hh:132
GridImp::template Codim< codimension >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entitypointer.hh:378
EntityPointer(const EntityPointer< GridImp, ItImp > &ep)
Templatized copy constructor from arbitrary IteratorImp. This enables that an EntityPointer can be co...
Definition: common/entitypointer.hh:168
Know the grid&#39;s dimension.
Definition: common/entitypointer.hh:405
GridImp::template Codim< codimension >::Geometry Geometry
The geometry type of this entity.
Definition: common/entitypointer.hh:375
GridImp::template Codim< cd >::EntityPointer EntityPointer
Definition: common/entitypointer.hh:393
Implementation realIterator
Definition: common/entitypointer.hh:137
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entitypointer.hh:432
GridImp::HierarchicIterator HierarchicIterator
The codim==0 EntityPointer type.
Definition: common/entitypointer.hh:401
ONLY_CODIM0 bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: common/entitypointer.hh:532
bool operator==(const EntityPointer< GridImp, ItImp > &rhs) const
Checks for equality. Only works for EntityPointers and iterators on the same grid. Due to the conversion operators one can compare all kinds of iterators and EntityPointer.
Definition: common/entitypointer.hh:282
Know the grid dimension.
Definition: common/entity.hh:108
int level() const DUNE_ENTITYPOINTER_DEPRECATED_MSG
Ask for level of entity.
Definition: common/entitypointer.hh:337
ONLY_CODIM0 bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary.
Definition: common/entitypointer.hh:544
IteratorImp Implementation
Definition: common/entitypointer.hh:129
EntityPointer()
Default constructor of an empty (undefined) EntityPointer.
Definition: common/entitypointer.hh:173
static void(*)(*)(*)(*)(*)(*) move(const double *)
Definition: partitiondisplay.cc:122
ONLY_CODIM0 HierarchicIterator hbegin(int maxLevel) const
Inter-level access to elements that resulted from (recursive) subdivision of this element...
Definition: common/entitypointer.hh:511
DUNE_ENTITYPOINTER_DEPRECATED_MSG EntityPointer(const Entity &entity)
Templatized constructor from type of entity that this entity pointer points to. This constructor can ...
Definition: common/entitypointer.hh:183
Definition: common/entitypointer.hh:141
PartitionType partitionType() const
Partition type of this entity.
Definition: common/entitypointer.hh:413
Geometry geometry() const
obtain geometric realization of the entity
Definition: common/entitypointer.hh:427
bool operator!=(const EntityPointer< GridImp, ItImp > &rhs) const
Checks for inequality. Only works for EntityPointers and iterators on the same grid. Due to the conversion operators one can compare all kinds of iterators and EntityPointer.
Definition: common/entitypointer.hh:293
Entity operator*() const DUNE_ENTITYPOINTER_DEPRECATED_MSG
Dereferencing operator.
ONLY_CODIM0 bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). If the method returns false...
Definition: common/entitypointer.hh:539
const Implementation & impl() const
return reference to the real implementation
Definition: common/entitypointer.hh:134
#define DUNE_ENTITYPOINTER_DEPRECATED_MSG
Definition: common/entitypointer.hh:17
Dune::Entity< codim, dim, Grid, EntityImp > Entity
Definition: common/entitypointer.hh:603
Include standard header files.
Definition: agrid.hh:59
std::conditional< std::is_lvalue_reference< decltype(realIterator.dereference()) >::value, const Entity &, Entity >::type Reference
Tpy of the reference used when derefencing the Ptr.
Definition: common/entitypointer.hh:153
STL namespace.
EntityImp< cd, dim, GridImp > Implementation
Definition: common/entity.hh:78
EntityPointer(const IteratorImp &i)
Copy Constructor from an Iterator implementation.
Definition: common/entitypointer.hh:357
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: common/entitypointer.hh:437
GridImp::template Codim< codimension >::LocalGeometry LocalGeometry
The geometry type of this entity when the geometry is expressed embedded in the father element...
Definition: common/entitypointer.hh:387
Different resources needed by all grid implementations.
#define ONLY_CODIM0
Definition: common/entitypointer.hh:440
ONLY_CODIM0 bool hasFather() const
Return true if entity has a father entity which can be accessed using the father() method...
Definition: common/entitypointer.hh:453
DefaultEntityPointer(EntityImp< codim, dim, Grid > entity)
Definition: common/entitypointer.hh:611
ONLY_CODIM0 LocalGeometry geometryInFather() const
Provides information how this element has been subdivided from its father element.
Definition: common/entitypointer.hh:497