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

Carsten Gräser graeser at math.fu-berlin.de
Sat Dec 4 21:11:23 CET 2010


Am 04.12.2010 18:14, schrieb Martin Nolte:
> 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 be an even better solution. The only thing I would change
is to use Begin and End instead of first and last with End pointing
behinf the last element. Consequently I'd start with an empty tuple
for Begin==End.

> 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.
I don't see any problem. Neither with the dune tuple nor with the std or tr1 one.
It only uses PushBackTuple that shpuld work in any case.

The only drawback in using tuples is that their length is restricted to 9 currently.
For PushBackTuple this can only be prevented by using variadic templates.
On the otherhand dim<9 is not to restrictive.

BTW: While looking where CodimTable is used I found a using statement
refering to it in albertagrid/misc.hh but no actual use of it. Do I
miss something?

Best,
Carsten


> 
> 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;
>> +    };
>> +
>>    }
>>    
>>  }



-- 
----------------------------------------------------------------------
Carsten Gräser           | phone: +49-30 / 838-75349
Freie Universität Berlin | fax  : +49-30 / 838-54977
Institut für Mathematik  | email: graeser at math.fu-berlin.de
Arnimallee 6             |
14195 Berlin, Germany    | URL  : http://page.mi.fu-berlin.de/graeser
----------------------------------------------------------------------




More information about the Dune mailing list