From 7a1ea87e19d6f3c4d746c962497cdb8b75009393 Mon Sep 17 00:00:00 2001
From: Marco Agnese <m.agnese13@imperial.ac.uk>
Date: Tue, 21 Mar 2017 22:18:09 +0100
Subject: [PATCH] Remove AlbertaGridEntityPointer

---
 dune/grid/albertagrid/CMakeLists.txt        |   1 -
 dune/grid/albertagrid/agrid.hh              |   3 +-
 dune/grid/albertagrid/entity.hh             |   6 +-
 dune/grid/albertagrid/entitypointer.hh      | 177 --------------------
 dune/grid/albertagrid/hierarchiciterator.hh |  54 ++++--
 dune/grid/albertagrid/treeiterator.hh       |  56 +++++--
 6 files changed, 88 insertions(+), 209 deletions(-)
 delete mode 100644 dune/grid/albertagrid/entitypointer.hh

diff --git a/dune/grid/albertagrid/CMakeLists.txt b/dune/grid/albertagrid/CMakeLists.txt
index 9980d717f6..25e5de60bc 100644
--- a/dune/grid/albertagrid/CMakeLists.txt
+++ b/dune/grid/albertagrid/CMakeLists.txt
@@ -37,7 +37,6 @@ set(HEADERS
   undefine-3.0.hh
   entity.hh
   entity.cc
-  entitypointer.hh
   entityseed.hh
   hierarchiciterator.hh
   algebra.hh
diff --git a/dune/grid/albertagrid/agrid.hh b/dune/grid/albertagrid/agrid.hh
index 9293a842f4..b008a068ba 100644
--- a/dune/grid/albertagrid/agrid.hh
+++ b/dune/grid/albertagrid/agrid.hh
@@ -50,7 +50,6 @@
 #include "indexsets.hh"
 #include "geometry.hh"
 #include "entity.hh"
-#include "entitypointer.hh"
 #include "hierarchiciterator.hh"
 #include "treeiterator.hh"
 #include "leveliterator.hh"
@@ -144,9 +143,9 @@ namespace Dune
     Base;
 
     template< int, int, class > friend class AlbertaGridEntity;
-    template< int, class > friend class AlbertaGridEntityPointer;
     template< class > friend class AlbertaLevelGridView;
     template< class > friend class AlbertaLeafGridView;
+    template< int, class, bool > friend class AlbertaGridTreeIterator;
 
     friend class GridFactory< This >;
     friend struct DGFGridFactory< This >;
diff --git a/dune/grid/albertagrid/entity.hh b/dune/grid/albertagrid/entity.hh
index 86d03b4d49..ba1474be72 100644
--- a/dune/grid/albertagrid/entity.hh
+++ b/dune/grid/albertagrid/entity.hh
@@ -17,9 +17,6 @@ namespace Dune
   // Forward Declarations
   // --------------------
 
-  template< int codim, class Grid >
-  class AlbertaGridEntityPointer;
-
   template< int codim, class Grid, bool leafIterator >
   class AlbertaGridTreeIterator;
 
@@ -51,8 +48,8 @@ namespace Dune
     friend class AlbertaGrid< dim, dimworld >;
     friend class AlbertaGridEntity< 0, dim, Grid >;
 
+    friend class AlbertaGridHierarchicIterator< Grid >;
     template< int, class, bool > friend class AlbertaGridTreeIterator;
-    friend class AlbertaGridEntityPointer< codim, Grid >;
 
   public:
     static const int dimension = dim;
@@ -192,7 +189,6 @@ namespace Dune
     friend class AlbertaGridLeafIntersection< Grid >;
     friend class AlbertaGridHierarchicIterator< Grid >;
     template< int, class, bool > friend class AlbertaGridTreeIterator;
-    friend class AlbertaGridEntityPointer< 0, Grid >;
 
   public:
     static const int dimension = dim;
diff --git a/dune/grid/albertagrid/entitypointer.hh b/dune/grid/albertagrid/entitypointer.hh
deleted file mode 100644
index 220c5e683d..0000000000
--- a/dune/grid/albertagrid/entitypointer.hh
+++ /dev/null
@@ -1,177 +0,0 @@
-// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-// vi: set et ts=4 sw=2 sts=2:
-#ifndef DUNE_ALBERTA_ENTITYPOINTER_HH
-#define DUNE_ALBERTA_ENTITYPOINTER_HH
-
-#include <dune/grid/albertagrid/elementinfo.hh>
-
-#if HAVE_ALBERTA
-
-namespace Dune
-{
-
-  // External Forward Declarations
-  // -----------------------------
-
-  template< int dim, int dimworld >
-  class AlbertaGrid;
-
-
-
-  /** \class   AlbertaGridEntityPointer
-   *  \ingroup AlbertaGrid
-   *  \brief   EntityPointer implementation for AlbertaGrid
-   */
-  template< int codim, class GridImp >
-  class AlbertaGridEntityPointer
-  {
-    typedef AlbertaGridEntityPointer< codim, GridImp > This;
-
-    friend class AlbertaGrid< GridImp::dimension, GridImp::dimensionworld >;
-
-  public:
-    static const int dimension = GridImp::dimension;
-    static const int codimension = codim;
-    static const int mydimension = dimension - codimension;
-    static const int dimensionworld = GridImp::dimensionworld;
-
-    typedef typename GridImp::template Codim< codimension >::Entity Entity;
-
-  protected:
-    typedef MakeableInterfaceObject< Entity > EntityObject;
-    typedef typename EntityObject::ImplementationType EntityImp;
-
-  public:
-    typedef AlbertaGridEntityPointer< codimension, GridImp > EntityPointerImp;
-
-    typedef typename EntityImp::ElementInfo ElementInfo;
-
-    AlbertaGridEntityPointer ();
-
-    //! make an EntityPointer that points to an element
-    AlbertaGridEntityPointer ( const GridImp &grid,
-                               const ElementInfo &elementInfo,
-                               int subEntity );
-
-    //! constructor for invalid EntityPointer
-    AlbertaGridEntityPointer ( const GridImp &grid );
-
-    //! make entity pointer from entity
-    AlbertaGridEntityPointer ( const EntityImp &entity );
-
-#if 0
-    //! Destructor
-    ~AlbertaGridEntityPointer();
-#endif
-
-    //! equality
-    bool equals ( const This &other ) const;
-
-    //! dereferencing
-    Entity &dereference () const;
-
-    //! ask for level of entities
-    int level () const;
-
-  protected:
-    //! obtain reference to internal entity implementation
-    EntityImp &entityImp ();
-
-    //! obtain const reference to internal entity implementation
-    const EntityImp &entityImp () const;
-
-    //! obtain a reference to the grid
-    const GridImp &grid () const;
-
-  private:
-    mutable Entity entity_;
-  };
-
-
-
-  template< int codim, class GridImp >
-  inline AlbertaGridEntityPointer< codim, GridImp >
-  ::AlbertaGridEntityPointer ()
-  {}
-
-
-  template< int codim, class GridImp >
-  inline AlbertaGridEntityPointer< codim, GridImp >
-  ::AlbertaGridEntityPointer ( const GridImp &grid,
-                               const ElementInfo &elementInfo,
-                               int subEntity )
-    : entity_( EntityImp( grid, elementInfo, subEntity ) )
-  {}
-
-
-  template<int codim, class GridImp >
-  inline AlbertaGridEntityPointer< codim, GridImp >
-  ::AlbertaGridEntityPointer ( const GridImp &grid )
-    : entity_( EntityImp( grid ) )
-  {}
-
-
-  template< int codim, class GridImp >
-  inline AlbertaGridEntityPointer< codim, GridImp >
-  ::AlbertaGridEntityPointer ( const EntityImp &entity )
-    : entity_( entity )
-  {}
-
-
-#if 0
-  template<int codim, class GridImp >
-  inline AlbertaGridEntityPointer< codim, GridImp >::~AlbertaGridEntityPointer ()
-  {}
-#endif
-
-
-  template<int codim, class GridImp >
-  inline bool
-  AlbertaGridEntityPointer< codim, GridImp >::equals ( const This &other ) const
-  {
-    return entityImp().equals( other.entityImp() );
-  }
-
-
-  template<int codim, class GridImp >
-  inline typename AlbertaGridEntityPointer< codim, GridImp >::Entity &
-  AlbertaGridEntityPointer< codim, GridImp >::dereference () const
-  {
-    return entity_;
-  }
-
-
-  template< int codim, class GridImp >
-  inline int AlbertaGridEntityPointer< codim, GridImp >::level () const
-  {
-    return entityImp().level();
-  }
-
-
-  template< int codim, class GridImp >
-  inline typename AlbertaGridEntityPointer< codim, GridImp >::EntityImp &
-  AlbertaGridEntityPointer< codim, GridImp >::entityImp ()
-  {
-    return GridImp::getRealImplementation( entity_ );
-  }
-
-
-  template< int codim, class GridImp >
-  inline const typename AlbertaGridEntityPointer< codim, GridImp >::EntityImp &
-  AlbertaGridEntityPointer< codim, GridImp >::entityImp () const
-  {
-    return GridImp::getRealImplementation( entity_ );
-  }
-
-
-  template< int codim, class GridImp >
-  inline const GridImp &AlbertaGridEntityPointer< codim, GridImp >::grid () const
-  {
-    return entityImp().grid();
-  }
-
-}
-
-#endif // #if HAVE_ALBERTA
-
-#endif // #ifndef DUNE_ALBERTA_ENTITYPOINTER_HH
diff --git a/dune/grid/albertagrid/hierarchiciterator.hh b/dune/grid/albertagrid/hierarchiciterator.hh
index d94cb93d1c..74a588edc1 100644
--- a/dune/grid/albertagrid/hierarchiciterator.hh
+++ b/dune/grid/albertagrid/hierarchiciterator.hh
@@ -3,10 +3,9 @@
 #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH
 #define DUNE_ALBERTA_HIERARCHICITERATOR_HH
 
+#include <dune/grid/albertagrid/elementinfo.hh>
 #include <dune/grid/common/entityiterator.hh>
 
-#include <dune/grid/albertagrid/entitypointer.hh>
-
 #if HAVE_ALBERTA
 
 namespace Dune
@@ -25,10 +24,8 @@ namespace Dune
    */
   template< class GridImp >
   class AlbertaGridHierarchicIterator
-    : public AlbertaGridEntityPointer< 0, GridImp >
   {
     typedef AlbertaGridHierarchicIterator< GridImp > This;
-    typedef AlbertaGridEntityPointer< 0, GridImp > Base;
 
   public:
     typedef typename GridImp::template Codim<0>::Entity Entity;
@@ -37,7 +34,7 @@ namespace Dune
     typedef MakeableInterfaceObject< Entity > EntityObject;
     typedef typename EntityObject::ImplementationType EntityImp;
 
-    typedef typename Base::ElementInfo ElementInfo;
+    typedef typename EntityImp::ElementInfo ElementInfo;
 
     AlbertaGridHierarchicIterator ()
     {}
@@ -59,14 +56,48 @@ namespace Dune
     //! increment
     void increment();
 
-    using Base::level;
+    //! equality
+    bool equals ( const This &other ) const
+    {
+      return entityImp().equals( other.entityImp() );
+    }
+
+    //! dereferencing
+    Entity &dereference () const
+    {
+      return entity_;
+    }
+
+    //! ask for level of entities
+    int level () const
+    {
+      return entityImp().level();
+    }
 
   protected:
-    using Base::entityImp;
+    //! obtain reference to internal entity implementation
+    EntityImp &entityImp ()
+    {
+      return GridImp::getRealImplementation( entity_ );
+    }
+
+    //! obtain const reference to internal entity implementation
+    const EntityImp &entityImp () const
+    {
+      return GridImp::getRealImplementation( entity_ );
+    }
+
+    //! obtain a reference to the grid
+    const GridImp &grid () const
+    {
+      return entityImp().grid();
+    }
 
   private:
     void increment ( ElementInfo elementInfo );
 
+    mutable  Entity entity_;
+
     // level on which the iterator was started
     int startLevel_;
 
@@ -78,7 +109,7 @@ namespace Dune
   template< class GridImp >
   inline AlbertaGridHierarchicIterator< GridImp >
   ::AlbertaGridHierarchicIterator( const GridImp &grid, int actLevel, int maxLevel )
-    : Base( grid ),
+    : entity_( EntityImp( grid ) ),
       startLevel_( actLevel ),
       maxlevel_( maxLevel )
   {}
@@ -89,7 +120,7 @@ namespace Dune
   ::AlbertaGridHierarchicIterator ( const GridImp &grid,
                                     const ElementInfo &elementInfo,
                                     int maxLevel )
-    : Base( grid ),
+    : entity_( EntityImp( grid ) ),
       startLevel_( elementInfo.level() ),
       maxlevel_( maxLevel )
   {
@@ -100,7 +131,7 @@ namespace Dune
   template< class GridImp >
   inline AlbertaGridHierarchicIterator< GridImp >
   ::AlbertaGridHierarchicIterator( const This &other )
-    : Base( other ),
+    : entity_( other.entity_ ),
       startLevel_( other.startLevel_ ),
       maxlevel_( other.maxlevel_ )
   {}
@@ -110,8 +141,7 @@ namespace Dune
   inline typename AlbertaGridHierarchicIterator< GridImp >::This &
   AlbertaGridHierarchicIterator< GridImp >::operator= ( const This &other )
   {
-    Base::operator=( other );
-
+    entity_ = other.entity_;
     startLevel_ = other.startLevel_;
     maxlevel_ = other.maxlevel_;
     return *this;
diff --git a/dune/grid/albertagrid/treeiterator.hh b/dune/grid/albertagrid/treeiterator.hh
index 9c10e1ee3a..d047982477 100644
--- a/dune/grid/albertagrid/treeiterator.hh
+++ b/dune/grid/albertagrid/treeiterator.hh
@@ -8,8 +8,8 @@
 #include <dune/common/std/utility.hh>
 #include <dune/common/typetraits.hh>
 
+#include <dune/grid/albertagrid/elementinfo.hh>
 #include <dune/grid/albertagrid/meshpointer.hh>
-#include <dune/grid/albertagrid/entitypointer.hh>
 
 #if HAVE_ALBERTA
 
@@ -181,10 +181,8 @@ namespace Dune
    */
   template< int codim, class GridImp, bool leafIterator >
   class AlbertaGridTreeIterator
-    : public AlbertaGridEntityPointer< codim, GridImp >
   {
     typedef AlbertaGridTreeIterator< codim, GridImp, leafIterator > This;
-    typedef AlbertaGridEntityPointer< codim, GridImp > Base;
 
   public:
     static const int dimension = GridImp::dimension;
@@ -198,13 +196,13 @@ namespace Dune
       = Alberta::NumSubEntities< dimension, codimension >::value;
 
   public:
-    typedef typename Base::ElementInfo ElementInfo;
     typedef Alberta::MeshPointer< dimension > MeshPointer;
     typedef typename MeshPointer::MacroIterator MacroIterator;
 
     typedef typename GridImp::template Codim< codim >::Entity Entity;
     typedef MakeableInterfaceObject< Entity > EntityObject;
     typedef typename EntityObject::ImplementationType EntityImp;
+    typedef typename EntityImp::ElementInfo ElementInfo;
 
     typedef AlbertaMarkerVector< dimension, dimensionworld > MarkerVector;
 
@@ -224,12 +222,45 @@ namespace Dune
                               const MarkerVector *marker,
                               int travLevel );
 
+    //! equality
+    bool equals ( const This &other ) const
+    {
+      return entityImp().equals( other.entityImp() );
+    }
+
+    //! dereferencing
+    Entity &dereference () const
+    {
+      return entity_;
+    }
+
+    //! ask for level of entities
+    int level () const
+    {
+      return entityImp().level();
+    }
+
     //! increment
     void increment();
 
   protected:
-    using Base::entityImp;
-    using Base::grid;
+    //! obtain reference to internal entity implementation
+    EntityImp &entityImp ()
+    {
+      return GridImp::getRealImplementation( entity_ );
+    }
+
+    //! obtain const reference to internal entity implementation
+    const EntityImp &entityImp () const
+    {
+      return GridImp::getRealImplementation( entity_ );
+    }
+
+    //! obtain a reference to the grid
+    const GridImp &grid () const
+    {
+      return entityImp().grid();
+    }
 
   private:
     void nextElement ( ElementInfo &elementInfo );
@@ -245,6 +276,8 @@ namespace Dune
     void goNext ( const std::integral_constant< int, cd > cdVariable,
                   ElementInfo &elementInfo );
 
+    mutable Entity entity_;
+
     //! current level
     int level_;
 
@@ -314,7 +347,7 @@ namespace Dune
   template< int codim, class GridImp, bool leafIterator >
   inline AlbertaGridTreeIterator< codim, GridImp, leafIterator >
   ::AlbertaGridTreeIterator ()
-    : Base(),
+    : entity_(),
       level_( -1 ),
       subEntity_( -1 ),
       macroIterator_(),
@@ -326,7 +359,7 @@ namespace Dune
   ::AlbertaGridTreeIterator ( const GridImp &grid,
                               const MarkerVector *marker,
                               int travLevel )
-    : Base( grid ),
+    : entity_( EntityImp( grid ) ),
       level_( travLevel ),
       subEntity_( (codim == 0 ? 0 : -1) ),
       macroIterator_( grid.meshPointer().begin() ),
@@ -346,7 +379,7 @@ namespace Dune
   inline AlbertaGridTreeIterator< codim, GridImp, leafIterator >
   ::AlbertaGridTreeIterator ( const GridImp &grid,
                               int travLevel )
-    : Base( grid ),
+    : entity_( EntityImp( grid ) ),
       level_( travLevel ),
       subEntity_( -1 ),
       macroIterator_( grid.meshPointer().end() ),
@@ -358,7 +391,7 @@ namespace Dune
   template< int codim, class GridImp, bool leafIterator >
   inline AlbertaGridTreeIterator< codim, GridImp, leafIterator >
   ::AlbertaGridTreeIterator( const This &other )
-    : Base( other ),
+    : entity_( other.entity_ ),
       level_( other.level_ ),
       subEntity_( other.subEntity_ ),
       macroIterator_( other.macroIterator_ ),
@@ -371,8 +404,7 @@ namespace Dune
   inline typename AlbertaGridTreeIterator< codim, GridImp, leafIterator >::This &
   AlbertaGridTreeIterator< codim, GridImp, leafIterator >::operator= ( const This &other )
   {
-    Base::operator=( other );
-
+    entity_ = other.entity_;
     level_ = other.level_;
     subEntity_ =  other.subEntity_;
     macroIterator_ = other.macroIterator_;
-- 
GitLab