[Dune] [Dune-Commit] dune-grid r7214 - trunk/dune/grid/genericgeometry

Martin Nolte nolte at mathematik.uni-freiburg.de
Sat Dec 4 18:14:38 CET 2010


Maybe we could replace the CodimTable on the whole by a class in
tupleutility.hh. The implementation could look somewhat as follows:

template< class Int, template < Int > class Element, Int first, Int last >
TupleFromIntegralTemplate
{
  typedef typename PushBackTuple< Element< first >, TupleFromTemplate< Int,
Element, first+1, last > >::type type;
};

template< class Int, template < Int > class Element, Int last >
TupleFromIntegralTemplate< Int, Element, last, last >
{
  typedef typename tuple< Element< Last > > type;
};

This would completely replace the CodimTable, since its major functionality has
always been the generation of this type. But, since I don't know anything about
Dune's tuple implementation, I would like to delegate such a task to qualified
hands.

Best,

Martin



On 12/04/2010 12:50 AM, graeser at dune-project.org wrote:
> Author: graeser
> Date: 2010-12-04 00:50:47 +0100 (Sat, 04 Dec 2010)
> New Revision: 7214
> 
> Modified:
>    trunk/dune/grid/genericgeometry/codimtable.hh
> Log:
> Simplify implementation
> 
> CodimTable is just a multi-type container that now
> wraps a tuple<Element<0>, ...,Element<dim> > and
> the associated get<>() functions.
> 
> Since this is an internal class it could even be removed
> in favor of directly using the tuple.
> 
> 
> Modified: trunk/dune/grid/genericgeometry/codimtable.hh
> ===================================================================
> --- trunk/dune/grid/genericgeometry/codimtable.hh	2010-12-03 15:33:46 UTC (rev 7213)
> +++ trunk/dune/grid/genericgeometry/codimtable.hh	2010-12-03 23:50:47 UTC (rev 7214)
> @@ -5,6 +5,7 @@
>  #define DUNE_GENERICGEOMETRY_CODIMTABLE_HH
>  
>  #include <dune/common/typetraits.hh>
> +#include <dune/common/tupleutility.hh>
>  
>  namespace Dune
>  {
> @@ -12,128 +13,42 @@
>    namespace GenericGeometry
>    {
>  
> -    template< template< int > class Element, int codim >
> -    class CodimTableStorage
> -    {
> -      CodimTableStorage< Element, codim - 1 > map_;
> -      Element< codim > element_;
> -
> -    public:
> -      CodimTableStorage ()
> -      : map_(),
> -        element_()
> -      {}
> -
> -      CodimTableStorage ( const CodimTableStorage &other )
> -      : map_( other.map_ ),
> -        element_( other.element_ )
> -      {}
> -
> -      const CodimTableStorage &operator= ( const CodimTableStorage &other )
> -      {
> -        map_ = other.map_;
> -        element_ = other.element_;
> -        return *this;
> -      }
> -
> -      template< int cd >
> -      const Element< cd > &
> -      operator[] ( const integral_constant< int, cd > codimVariable ) const
> -      {
> -        return map_[ codimVariable ];
> -      }
> -
> -      template< int cd >
> -      Element< cd > &
> -      operator[] ( const integral_constant< int, cd > &codimVariable )
> -      {
> -        return map_[ codimVariable ];
> -      }
> -      
> -      const Element< codim > &
> -      operator[] ( const integral_constant< int, codim > &codimVariable ) const
> -      {
> -        return element_;
> -      }
> -
> -      Element< codim > &
> -      operator[] ( const integral_constant< int, codim > &codimVariable )
> -      {
> -        return element_;
> -      }
> -    };
> -
> -
> -    
> -    template< template< int > class Element >
> -    class CodimTableStorage< Element, 0 >
> -    {
> -      Element< 0 > element_;
> -     
> -    public:
> -      CodimTableStorage ()
> -      : element_()
> -      {}
> -
> -      CodimTableStorage ( const CodimTableStorage &other )
> -      : element_( other.element_ )
> -      {}
> -
> -      CodimTableStorage &operator= ( const CodimTableStorage &other )
> -      {
> -        element_ = other.element_;
> -        return *this;
> -      }
> -
> -      const Element< 0 > &
> -      operator[] ( const integral_constant< int, 0 > codimVaraible ) const
> -      {
> -        return element_;
> -      }
> -
> -      Element< 0 > &
> -      operator[] ( const integral_constant< int, 0 > codimVaraible )
> -      {
> -        return element_;
> -      }
> -    };
> -
> -
> -    
>      template< template< int > class Element, int dim >
>      class CodimTable
>      {
> -      CodimTableStorage< Element, dim > map_;
> +      friend class CodimTable< Element, dim+1 >;
>  
> -    public:
> -      CodimTable ()
> -      {}
> +      typedef typename PushBackTuple<
> +        typename CodimTable< Element, dim-1 >::ElementTuple,
> +        Element< dim > >::type ElementTuple;
>  
> -      CodimTable ( const CodimTable &other )
> -      : map_( other.map_ )
> -      {}
> +      ElementTuple map_;
>  
> -      const CodimTable &operator= ( const CodimTable &other )
> -      {
> -        map_ = other.map_;
> -        return *this;
> -      }
> +    public:
>  
>        template< int codim >
>        const Element< codim > &
>        operator[] ( const integral_constant< int, codim > codimVariable ) const
>        {
> -        return map_[ codimVariable ];
> +        return Dune::get<codim>(map_);
>        }
>  
>        template< int codim >
>        Element< codim > &
>        operator[] ( const integral_constant< int, codim > codimVariable )
>        {
> -        return map_[ codimVariable ];
> +        return Dune::get<codim>(map_);
>        }
>      };
>  
> +
> +    template< template< int > class Element>
> +    class CodimTable< Element, -1 >
> +    {
> +      friend class CodimTable< Element, 0 >;
> +      typedef typename Dune::tuple<> ElementTuple;
> +    };
> +
>    }
>    
>  }
> 
> 
> _______________________________________________
> Dune-Commit mailing list
> Dune-Commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-commit

-- 
Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5642
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune mailing list