dune-grid  2.2beta1
dynamicsubindexid.hh
Go to the documentation of this file.
00001 #ifndef DUNE_DYNAMICCODIMSUBINDEXID_HH
00002 #define DUNE_DYNAMICCODIMSUBINDEXID_HH
00003 
00004 #include <dune/common/forloop.hh>
00005 #include <dune/common/typetraits.hh>
00006 #include <dune/geometry/genericgeometry/conversion.hh>
00007 
00008 #warning This file is deprecated and will be removed after the release of dune-grid 2.2.
00009 
00010 namespace Dune
00011 {
00012 
00013   // DynamicSubIndex
00014   // ---------------
00015 
00016   template< class Grid, class IndexSet >
00017   class DynamicSubIndex
00018   {
00019     typedef DynamicSubIndex< Grid, IndexSet > This;
00020 
00021     typedef typename remove_const< Grid >::type::Traits Traits;
00022 
00023     static const unsigned int dimension = remove_const< Grid >::type::dimension;
00024 
00025     typedef typename Traits::template Codim< 0 >::Entity Element;
00026 
00027   public:
00028     typedef typename IndexSet::IndexType IndexType;
00029 
00030   private:
00031     struct Caller
00032     {
00033       virtual ~Caller ()
00034       {}
00035 
00036       virtual IndexType
00037       subIndex ( const IndexSet &indexSet, const Element &e, int i ) const = 0;
00038     };
00039 
00040     template< int codim >
00041     struct CallerImpl
00042     : public Caller
00043     {
00044       virtual IndexType
00045       subIndex ( const IndexSet &indexSet, const Element &e, int i ) const
00046       {
00047         typedef GenericGeometry::MapNumberingProvider< dimension > Numbering;
00048         const unsigned int tid = GenericGeometry::topologyId( e.type() );
00049         const int j = Numbering::template generic2dune< codim >( tid, i );
00050         return indexSet.template subIndex< codim >( e, j );
00051       }
00052 
00053       static void apply ( const Caller *(&caller)[ dimension+1 ] )
00054       {
00055         caller[ codim ] = new CallerImpl< codim >;
00056       }
00057     };
00058 
00059     // prohibit copying and assignment
00060     DynamicSubIndex ( const This & );
00061     This &operator= ( const This & );
00062 
00063   public:
00064     explicit DynamicSubIndex ( const IndexSet &indexSet )
00065     : indexSet_( indexSet )
00066     {
00067       Dune::ForLoop< CallerImpl, 0, dimension >::apply( caller_ );
00068     }
00069 
00070     ~DynamicSubIndex ()
00071     {
00072       for( unsigned int codim = 0; codim <= dimension; ++codim )
00073         delete caller_[ codim ];
00074     }
00075 
00076     IndexType operator() ( const Element &e, int i, unsigned int codim ) const
00077     {
00078       assert( codim <= dimension );
00079       return caller_[ codim ]->subIndex( indexSet_, e, i );
00080     }
00081 
00082   private:
00083     const IndexSet &indexSet_;
00084     const Caller *caller_[ dimension+1 ];
00085   };
00086 
00087 
00088 
00089   // DynamicSubId
00090   // ------------
00091 
00092   template< class Grid, class IdSet >
00093   class DynamicSubId
00094   {
00095     typedef DynamicSubId< Grid, IdSet > This;
00096 
00097     typedef typename remove_const< Grid >::type::Traits Traits;
00098 
00099     static const unsigned int dimension = remove_const< Grid >::type::dimension;
00100 
00101     typedef typename Traits::template Codim< 0 >::Entity Element;
00102 
00103   public:
00104     typedef typename IdSet::IdType IdType;
00105 
00106   private:
00107     struct Caller
00108     {
00109       virtual ~Caller ()
00110       {}
00111 
00112       virtual IdType
00113       subId ( const IdSet &idSet, const Element &e, int i ) const = 0;
00114     };
00115 
00116     template< int codim >
00117     struct CallerImpl
00118     : public Caller
00119     {
00120       virtual IdType
00121       subId ( const IdSet &idSet, const Element &e, int i ) const
00122       {
00123         typedef GenericGeometry::MapNumberingProvider< dimension > Numbering;
00124         const unsigned int tid = GenericGeometry::topologyId( e.type() );
00125         const int j = Numbering::template generic2dune< codim >( tid, i );
00126         return idSet.template subId< codim >( e, j );
00127       }
00128 
00129       static void apply ( const Caller *(&caller)[ dimension+1 ] )
00130       {
00131         caller[ codim ] = new CallerImpl< codim >;
00132       }
00133     };
00134 
00135     // prohibit copying and assignment
00136     DynamicSubId ( const This & );
00137     This &operator= ( const This & );
00138 
00139   public:
00140     explicit DynamicSubId ( const IdSet &idSet )
00141     : idSet_( idSet )
00142     {
00143       Dune::ForLoop< CallerImpl, 0, dimension >::apply( caller_ );
00144     }
00145 
00146     ~DynamicSubId ()
00147     {
00148       for( unsigned int codim = 0; codim <= dimension; ++codim )
00149         delete caller_[ codim ];
00150     }
00151 
00152     IdType operator() ( const Element &e, int i, unsigned int codim ) const
00153     {
00154       assert( codim <= dimension );
00155       return caller_[ codim ]->subId( idSet_, e, i );
00156     }
00157 
00158   private:
00159     const IdSet &idSet_;
00160     const Caller *caller_[ dimension+1 ];
00161   };
00162 
00163 }
00164 
00165 #endif // #ifndef DUNE_DYNAMICCODIMSUBINDEXID_HH