Dune Core Modules (2.5.0)

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 
11 #include <dune/geometry/type.hh>
13 #include <dune/grid/common/gridenums.hh>
14 
19 #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.")
20 namespace Dune
21 {
22 
23  // External forward declaration
24  // ----------------------------
25 
26  template< int, int, class, template< int, int, class > class >
27  class Entity;
28 
29 
30 
113  template<class GridImp, class IteratorImp>
115  {
116  // need to make copy constructor of EntityPointer work for any iterator
117  //friend class EntityPointer<GridImp,typename IteratorImp::EntityPointerImp>;
118  template< class, class > friend class EntityPointer;
119 
120 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
121  public:
122 #else
123  protected:
124  // give the GridDefaultImplementation class access to the realImp
125  friend class GridDefaultImplementation<
126  GridImp::dimension, GridImp::dimensionworld,
127  typename GridImp::ctype,
128  typename GridImp::GridFamily> ;
129 #endif
130  // type of underlying implementation, for internal use only
131  typedef IteratorImp Implementation;
132 
134  Implementation &impl () { return realIterator; }
136  const Implementation &impl () const { return realIterator; }
137 
138  protected:
139  Implementation realIterator;
140 
141  public:
143  enum { codimension = IteratorImp::codimension };
144 
146  typedef typename IteratorImp::Entity Entity;
147 
149  typedef typename std::conditional<
150  std::is_lvalue_reference<
151  decltype(realIterator.dereference())
152  >::value,
153  const Entity&,
154  Entity
156 
157  //===========================================================
161  //===========================================================
162 
169  template< class ItImp >
171  : realIterator( ep.realIterator )
172  {}
173 
176  {}
177 
184  DUNE_ENTITYPOINTER_DEPRECATED_MSG
185  EntityPointer(const Entity& entity)
186  : realIterator( entity.impl() )
187  {}
188 
194  EntityPointer ( const typename Entity::Implementation &entityImp )
195  : realIterator( entityImp )
196  {}
197 
198  template< class ItImp >
199  DUNE_ENTITYPOINTER_DEPRECATED_MSG
200  inline EntityPointer & operator= ( const EntityPointer< GridImp, ItImp > &ep )
201  {
202  realIterator = ep.realIterator;
203  return *this;
204  }
205 
207 
208  //===========================================================
212  //===========================================================
213 
214  // The behavior when dereferencing the EntityPointer facade depends on
215  // the way the grid implementation handles returning entities. The implementation
216  // may either return a reference to an entity stored inside the EntityPointer
217  // implementation or a temporary Entity object. This object has to be forwarded through
218  // the facade to the user, which requires a little trickery, especially for operator->().
219  //
220  // In order to avoid confusing users reading the Doxygen documentation, we provide "clean"
221  // function signatures to Doxygen and hide the actual implementations.
222 
223 #ifdef DOXYGEN
224 
227  DUNE_ENTITYPOINTER_DEPRECATED_MSG;
228 
229 
231  const Entity* operator->() const
232  DUNE_ENTITYPOINTER_DEPRECATED_MSG;
233 
234 #else // DOXYGEN
235 
237  Reference
238  operator*() const
239  DUNE_ENTITYPOINTER_DEPRECATED_MSG
240  {
241  return realIterator.dereference();
242  }
243 
245  decltype(handle_proxy_member_access(realIterator.dereference()))
246  operator->() const
247  DUNE_ENTITYPOINTER_DEPRECATED_MSG
248  {
249  return handle_proxy_member_access(realIterator.dereference());
250  }
251 
252  template<typename T>
253  // this construction, where the deprecation warning is triggered by a separate function,
254  // is slightly convoluted, but I could not get the warning to trigger reliably when attached
255  // directly to the cast operator.
256  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!")
257  void trigger_entity_cast_warning() const
258  {}
259 
260  template<typename T, typename std::enable_if<std::is_same<T,Entity>::value,int>::type = 0>
261  operator const T&() const
262  {
263  static_assert(std::is_same<T,Entity>::value,"invalid cast");
264  trigger_entity_cast_warning<T>();
265  return realIterator.dereference();
266  }
267 
268 #endif // DOXYGEN
269 
271 
272  //===========================================================
276  //===========================================================
277 
283  template< class ItImp >
285  {
286  return equals( rhs );
287  }
288 
294  template< class ItImp >
296  {
297  return !equals( rhs );
298  }
300 
306  DUNE_ENTITYPOINTER_DEPRECATED_MSG
307  bool operator==(const Entity& rhs) const
308  {
309  return (**this) == rhs;
310  }
311 
317  DUNE_ENTITYPOINTER_DEPRECATED_MSG
318  bool operator!=(const Entity& rhs) const
319  {
320  return (**this) != rhs;
321  }
322 
323 
324  //===========================================================
328  //===========================================================
329 
339  int level () const
340  DUNE_ENTITYPOINTER_DEPRECATED_MSG
341  {
342  return realIterator.level();
343  }
344 
346 
347 
348  //===========================================================
352  //===========================================================
353 
359  EntityPointer(const IteratorImp & i) :
360  realIterator(i) {}
361 
363  template< class ItImp >
364  bool equals ( const EntityPointer< GridImp, ItImp > &rhs ) const
365  {
366  return realIterator.equals( rhs.realIterator );
367  }
369 
370  //===========================================================
374  //===========================================================
375 
377  typedef typename GridImp::template Codim<codimension>::Geometry Geometry;
378 
380  typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed;
381 
389  typedef typename GridImp::template Codim<codimension>::LocalGeometry LocalGeometry;
390 
392  template <int cd>
393  struct Codim
394  {
395  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
396  typedef typename GridImp::template Codim<cd>::Entity Entity;
397  };
398 
400  // typedef typename Entity::EntityPointer EntityPointer;
401 
403  typedef typename GridImp::HierarchicIterator HierarchicIterator;
404 
405  enum {
408  };
409  enum {
412  };
413 
415  PartitionType partitionType () const { return realIterator.dereference().partitionType(); }
416 
429  Geometry geometry () const { return realIterator.dereference().geometry(); }
430 
434  GeometryType type () const { return realIterator.dereference().type(); }
435 
439  EntitySeed seed () const { return realIterator.dereference().seed(); }
440 
441 #define CHECK_CODIM0 int ecodim = codimension, typename std::enable_if<ecodim == 0,int>::type = 0
442 #define ONLY_CODIM0 template<int ecodim = codimension, typename std::enable_if<ecodim == 0,int>::type = 0>
443 
444  template< int codim, CHECK_CODIM0 >
445  typename Codim<codim>::Entity
446  subEntity ( int i ) const
447  {
448  return realIterator.dereference().template subEntity< codim >(i);
449  }
450 
454  ONLY_CODIM0
455  bool hasFather () const
456  {
457  return realIterator.dereference().hasFather();
458  }
459 
461  ONLY_CODIM0
462  bool isLeaf () const
463  {
464  return realIterator.dereference().isLeaf();
465  }
466 
470  ONLY_CODIM0
471  bool isRegular() const { return realIterator.dereference().isRegular(); }
472 
498  ONLY_CODIM0
499  LocalGeometry geometryInFather () const { return realIterator.dereference().geometryInFather(); }
500 
512  ONLY_CODIM0
513  HierarchicIterator hbegin (int maxLevel) const
514  {
515  return realIterator.dereference().hbegin(maxLevel);
516  }
517 
525  ONLY_CODIM0
526  HierarchicIterator hend (int maxLevel) const
527  {
528  return realIterator.dereference().hend(maxLevel);
529  }
530 
533  ONLY_CODIM0
534  bool isNew () const { return realIterator.dereference().isNew(); }
535 
540  ONLY_CODIM0
541  bool mightVanish () const { return realIterator.dereference().mightVanish(); }
542 
545  ONLY_CODIM0
546  bool hasBoundaryIntersections () const { return realIterator.dereference().hasBoundaryIntersections(); }
548 
549  };
550 
551 
552 
553 #ifndef DOXYEN
554 
555  // DefaultEntityPointer
556  // --------------------
557 
558  /* The EntityPointer class defined above has been deprecated. Unitil its
559  final removal valid Dune grids still have to provide at least a suitable
560  EntityPointer typedef. This class provides a default implementation of an
561  entity pointer from a given Dune::Entity type:
562  \code
563  struct GridFamily
564  {
565  ...
566  typedef ImplementationDefined Entity;
567  typedef DefaultEntityPointer<Entity> EntityPointer;
568  ...
569  };
570  \endcode
571 
572  This class will retain a possible compatibility support with the
573  deprecated interface behavior if the iterator classes in the grid
574  implementation provide the following two additional methods:
575  \code
576  class Iterator
577  {
578  // dereference() method required by Dune::EntityIterator
579  typedef ImplemenatationDefined Entity;
580  Entity dereference () const;
581 
582  // allow for (deprecated) construction/assignment of EntityPointer from a given iterator
583  operator Dune::DefaultEntityPointer<Entity>() const
584  {
585  return Dune::DefaultEntityPointer<Entity>(dereference());
586  }
587 
588  // allow for (deprecated) comparison of an iterator with an entity pointer
589  bool equals(const Dune::DefaultEntityPointer<Entity> &rhs) const
590  {
591  return dereference() == rhs.dereference();
592  }
593  };
594  \endcode
595  */
596  template< class E >
597  class DefaultEntityPointer;
598 
599  template< int codim, int dim, class Grid, template< int, int, class > class EntityImp >
600  class DefaultEntityPointer< Dune::Entity< codim, dim, Grid, EntityImp > >
601  {
602  public:
603  static const int codimension = codim;
604 
606 
607  DefaultEntityPointer () {}
608 
609  explicit DefaultEntityPointer ( Entity entity )
610  : entity_( std::move( entity ) )
611  {}
612 
613  explicit DefaultEntityPointer ( EntityImp< codim, dim, Grid > entity )
614  : entity_( std::move( entity ) )
615  {}
616 
617  const Entity &dereference () const { return entity_; }
618 
619  bool equals ( const DefaultEntityPointer &rhs ) const
620  {
621  return entity_ == rhs.entity_;
622  }
623 
624  int level () const { return entity_.level(); }
625 
626  private:
627  Entity entity_;
628  };
629 
630 #endif // #ifndef DOXYEN
631 
632 }
633 #undef DUNE_ENTITYPOINTER_DEPRECATED_MSG
634 
635 #endif // DUNE_GRID_ENTITYPOINTER_HH
Wrapper class for pointers to entities.
Definition: entitypointer.hh:115
@ dimension
Know the grid's dimension.
Definition: entitypointer.hh:407
ONLY_CODIM0 bool isRegular() const
Returns true if element is of regular type in red/green type refinement. In bisection or hanging node...
Definition: entitypointer.hh:471
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: entitypointer.hh:439
ONLY_CODIM0 bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary.
Definition: entitypointer.hh:546
const Implementation & impl() const
return reference to the real implementation
Definition: entitypointer.hh:136
bool operator==(const EntityPointer< GridImp, ItImp > &rhs) const
Checks for equality. Only works for EntityPointers and iterators on the same grid....
Definition: entitypointer.hh:284
ONLY_CODIM0 HierarchicIterator hend(int maxLevel) const
Returns iterator to one past the last son element.
Definition: entitypointer.hh:526
Geometry geometry() const
obtain geometric realization of the entity
Definition: entitypointer.hh:429
EntityPointer()
Default constructor of an empty (undefined) EntityPointer.
Definition: entitypointer.hh:175
DUNE_ENTITYPOINTER_DEPRECATED_MSG bool operator==(const Entity &rhs) const
Compares an EntityPointer with an Entity for equality.
Definition: entitypointer.hh:307
GridImp::HierarchicIterator HierarchicIterator
The codim==0 EntityPointer type.
Definition: entitypointer.hh:403
ONLY_CODIM0 bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). If the method returns false,...
Definition: entitypointer.hh:541
DUNE_ENTITYPOINTER_DEPRECATED_MSG EntityPointer(const Entity &entity)
Templatized constructor from type of entity that this entity pointer points to. This constructor can ...
Definition: entitypointer.hh:185
ONLY_CODIM0 bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: entitypointer.hh:534
DUNE_ENTITYPOINTER_DEPRECATED_MSG bool operator!=(const Entity &rhs) const
Compares an EntityPointer with an Entity for inequality.
Definition: entitypointer.hh:318
EntityPointer(const IteratorImp &i)
Copy Constructor from an Iterator implementation.
Definition: entitypointer.hh:359
Implementation & impl()
return reference to the real implementation
Definition: entitypointer.hh:134
IteratorImp::Entity Entity
The Entity that this EntityPointer can point to.
Definition: entitypointer.hh:146
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entitypointer.hh:434
EntityPointer(const EntityPointer< GridImp, ItImp > &ep)
Templatized copy constructor from arbitrary IteratorImp. This enables that an EntityPointer can be co...
Definition: entitypointer.hh:170
GridImp::template Codim< codimension >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: entitypointer.hh:380
ONLY_CODIM0 LocalGeometry geometryInFather() const
Provides information how this element has been subdivided from its father element.
Definition: entitypointer.hh:499
@ mydimension
Know dimension of the entity.
Definition: entitypointer.hh:411
GridImp::template Codim< codimension >::LocalGeometry LocalGeometry
The geometry type of this entity when the geometry is expressed embedded in the father element.
Definition: entitypointer.hh:389
GridImp::template Codim< codimension >::Geometry Geometry
The geometry type of this entity.
Definition: entitypointer.hh:377
EntityPointer(const typename Entity::Implementation &entityImp)
Constructor from type of entity implementation that this entity pointer points to....
Definition: entitypointer.hh:194
bool equals(const EntityPointer< GridImp, ItImp > &rhs) const
Forward equality check to realIterator.
Definition: entitypointer.hh:364
Entity operator*() const DUNE_ENTITYPOINTER_DEPRECATED_MSG
Dereferencing operator.
bool operator!=(const EntityPointer< GridImp, ItImp > &rhs) const
Checks for inequality. Only works for EntityPointers and iterators on the same grid....
Definition: entitypointer.hh:295
ONLY_CODIM0 HierarchicIterator hbegin(int maxLevel) const
Inter-level access to elements that resulted from (recursive) subdivision of this element.
Definition: entitypointer.hh:513
PartitionType partitionType() const
Partition type of this entity.
Definition: entitypointer.hh:415
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: entitypointer.hh:155
int level() const DUNE_ENTITYPOINTER_DEPRECATED_MSG
Ask for level of entity.
Definition: entitypointer.hh:339
ONLY_CODIM0 bool hasFather() const
Return true if entity has a father entity which can be accessed using the father() method.
Definition: entitypointer.hh:455
ONLY_CODIM0 bool isLeaf() const
Returns true if the entity is contained in the leaf grid.
Definition: entitypointer.hh:462
@ dimension
Know the grid dimension.
Definition: entity.hh:111
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:268
Definition: grid.hh:920
Wrapper and interface classes for element geometries.
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
struct DUNE_DEPRECATED_MSG("Use <type_traits> instead!") ConstantVolatileTraits
Determines whether a type is const or volatile and provides the unqualified types.
Definition: typetraits.hh:57
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:441
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:11
pointer_or_proxy_holder handle_proxy_member_access(T &&t)
Transparent support for providing member access to both lvalues and rvalues (temporary proxies).
infrastructure for supporting operator->() on both references and proxies
Static tag representing a codimension.
Definition: dimension.hh:22
EntityPointer types of the different codimensions.
Definition: entitypointer.hh:394
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 15, 22:30, 2024)