Dune Core Modules (2.4.1)

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
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.")
18namespace 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
132 Implementation &impl () { return realIterator; }
134 const Implementation &impl () const { return realIterator; }
135
136 protected:
137 Implementation realIterator;
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
182 DUNE_ENTITYPOINTER_DEPRECATED_MSG
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 >
197 DUNE_ENTITYPOINTER_DEPRECATED_MSG
198 inline EntityPointer & operator= ( const EntityPointer< GridImp, ItImp > &ep )
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
225 DUNE_ENTITYPOINTER_DEPRECATED_MSG;
226
227
229 const Entity* operator->() const
230 DUNE_ENTITYPOINTER_DEPRECATED_MSG;
231
232#else // DOXYGEN
233
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
452 ONLY_CODIM0
453 bool hasFather () const
454 {
455 return realIterator.dereference().hasFather();
456 }
457
459 ONLY_CODIM0
460 bool isLeaf () const
461 {
462 return realIterator.dereference().isLeaf();
463 }
464
468 ONLY_CODIM0
469 bool isRegular() const { return realIterator.dereference().isRegular(); }
470
496 ONLY_CODIM0
497 LocalGeometry geometryInFather () const { return realIterator.dereference().geometryInFather(); }
498
510 ONLY_CODIM0
511 HierarchicIterator hbegin (int maxLevel) const
512 {
513 return realIterator.dereference().hbegin(maxLevel);
514 }
515
523 ONLY_CODIM0
524 HierarchicIterator hend (int maxLevel) const
525 {
526 return realIterator.dereference().hend(maxLevel);
527 }
528
531 ONLY_CODIM0
532 bool isNew () const { return realIterator.dereference().isNew(); }
533
538 ONLY_CODIM0
539 bool mightVanish () const { return realIterator.dereference().mightVanish(); }
540
543 ONLY_CODIM0
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 >
595 class DefaultEntityPointer;
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
605 DefaultEntityPointer () {}
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
Wrapper class for pointers to entities.
Definition: entitypointer.hh:113
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:469
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: entitypointer.hh:437
@ dimension
Know the grid's dimension.
Definition: entitypointer.hh:405
ONLY_CODIM0 bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary.
Definition: entitypointer.hh:544
std::conditional< std::is_lvalue_reference< decltype(realIterator.dereference())>::value, constEntity &, Entity >::type Reference
Tpy of the reference used when derefencing the Ptr.
Definition: entitypointer.hh:153
@ mydimension
Know dimension of the entity.
Definition: entitypointer.hh:409
bool operator==(const EntityPointer< GridImp, ItImp > &rhs) const
Checks for equality. Only works for EntityPointers and iterators on the same grid....
Definition: entitypointer.hh:282
ONLY_CODIM0 HierarchicIterator hend(int maxLevel) const
Returns iterator to one past the last son element.
Definition: entitypointer.hh:524
Geometry geometry() const
obtain geometric realization of the entity
Definition: entitypointer.hh:427
EntityPointer()
Default constructor of an empty (undefined) EntityPointer.
Definition: entitypointer.hh:173
DUNE_ENTITYPOINTER_DEPRECATED_MSG bool operator==(const Entity &rhs) const
Compares an EntityPointer with an Entity for equality.
Definition: entitypointer.hh:305
GridImp::HierarchicIterator HierarchicIterator
The codim==0 EntityPointer type.
Definition: entitypointer.hh:401
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:539
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:183
ONLY_CODIM0 bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: entitypointer.hh:532
DUNE_ENTITYPOINTER_DEPRECATED_MSG bool operator!=(const Entity &rhs) const
Compares an EntityPointer with an Entity for inequality.
Definition: entitypointer.hh:316
EntityPointer(const IteratorImp &i)
Copy Constructor from an Iterator implementation.
Definition: entitypointer.hh:357
IteratorImp::Entity Entity
The Entity that this EntityPointer can point to.
Definition: entitypointer.hh:144
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entitypointer.hh:432
EntityPointer(const EntityPointer< GridImp, ItImp > &ep)
Templatized copy constructor from arbitrary IteratorImp. This enables that an EntityPointer can be co...
Definition: entitypointer.hh:168
GridImp::template Codim< codimension >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: entitypointer.hh:378
ONLY_CODIM0 LocalGeometry geometryInFather() const
Provides information how this element has been subdivided from its father element.
Definition: entitypointer.hh:497
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:387
GridImp::template Codim< codimension >::Geometry Geometry
The geometry type of this entity.
Definition: entitypointer.hh:375
Implementation & impl()
return reference to the real implementation
Definition: entitypointer.hh:132
EntityPointer(const typename Entity::Implementation &entityImp)
Constructor from type of entity implementation that this entity pointer points to....
Definition: entitypointer.hh:192
bool equals(const EntityPointer< GridImp, ItImp > &rhs) const
Forward equality check to realIterator.
Definition: entitypointer.hh:362
const Implementation & impl() const
return reference to the real implementation
Definition: entitypointer.hh:134
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:293
ONLY_CODIM0 HierarchicIterator hbegin(int maxLevel) const
Inter-level access to elements that resulted from (recursive) subdivision of this element.
Definition: entitypointer.hh:511
PartitionType partitionType() const
Partition type of this entity.
Definition: entitypointer.hh:413
int level() const DUNE_ENTITYPOINTER_DEPRECATED_MSG
Ask for level of entity.
Definition: entitypointer.hh:337
ONLY_CODIM0 bool hasFather() const
Return true if entity has a father entity which can be accessed using the father() method.
Definition: entitypointer.hh:453
ONLY_CODIM0 bool isLeaf() const
Returns true if the entity is contained in the leaf grid.
Definition: entitypointer.hh:460
@ dimension
Know the grid dimension.
Definition: entity.hh:108
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Definition: grid.hh:1030
Different resources needed by all grid implementations.
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:10
pointer_or_proxy_holder handle_proxy_member_access(T &&t)
Transparent support for providing member access to both lvalues and rvalues (temporary proxies).
STL namespace.
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:392
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)