indexidset.hh

Go to the documentation of this file.
00001 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=4 sw=2 sts=2:
00003 // $Id$
00004 
00005 #ifndef DUNE_INDEXIDSET_HH
00006 #define DUNE_INDEXIDSET_HH
00007 
00008 #include <iostream>
00009 #include <vector>
00010 #include <dune/common/exceptions.hh>
00011 #include <dune/common/forloop.hh>
00012 #include <dune/grid/common/grid.hh>
00013 
00014 
00020 namespace Dune
00021 {
00022 
00023 #include <dune/common/bartonnackmanifcheck.hh>
00024 
00076   template<class GridImp, class IndexSetImp, class IndexTypeImp>
00077   class IndexSet
00078   {
00079     /* We use the remove_const to extract the Type from the mutable class,
00080        because the const class is not instantiated yet. */
00081     typedef typename remove_const< GridImp >::type::Traits Traits;
00082 
00083   public:
00085     typedef IndexTypeImp IndexType;
00086 
00088     static const int dimension = remove_const< GridImp >::type::dimension;
00089 
00090         //===========================================================
00094         //===========================================================
00095 
00102     /*
00103       We use the remove_const to extract the Type from the mutable class,
00104       because the const class is not instantiated yet.
00105     */
00106         template<int cc>
00107         IndexType index (const typename remove_const<GridImp>::type::
00108                Traits::template Codim<cc>::Entity& e) const 
00109         {
00110       CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00111       return asImp().template index<cc>(e);
00112         }
00113 
00123     template<class EntityType>
00124     IndexType index (const EntityType& e) const
00125     {
00126       enum { cc = EntityType::codimension };
00127       CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00128       return asImp().template index<cc>(e);
00129     }
00130 
00145     template< int cc >
00146     IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
00147                          int i, unsigned int codim ) const
00148     {
00149       CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
00150       return asImp().template subIndex< cc >(e,i,codim);
00151     }
00152 
00171     template< class Entity >
00172     IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
00173     {
00174       static const int cc = Entity::codimension;
00175       return asImp().template subIndex< cc >( e, i, codim );
00176     }
00178 
00179 
00180         //===========================================================
00184         //===========================================================
00185 
00193         const std::vector<GeometryType>& geomTypes (int codim) const
00194         {
00195       CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
00196           return asImp().geomTypes(codim);
00197         }
00198 
00204         IndexType size (GeometryType type) const
00205         {
00206       CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
00207       return asImp().size(type);
00208         }
00209 
00216     IndexType size (int codim) const
00217     {
00218       CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
00219       return asImp().size(codim);
00220     }
00221 
00227     template<class EntityType>
00228     bool contains (const EntityType& e) const
00229     {
00230       CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
00231       return asImp().contains(e);
00232     }
00233 
00234         // Must be explicitely defined although this class should get a default constructor.
00235     IndexSet() {}
00236 
00237   private:
00239     IndexSet(const IndexSet&);
00241     IndexSet& operator=(const IndexSet&);
00242 
00244         IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00246         const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00247   };
00248 
00249 #undef CHECK_INTERFACE_IMPLEMENTATION
00250 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00251 
00252 
00253 
00257   template<class GridImp, class IndexSetImp>
00258   class IndexSetDefaultImplementation
00259   : public IndexSet< GridImp, IndexSetImp >
00260   {
00261     typedef IndexSet< GridImp, IndexSetImp > Base;
00262     typedef typename remove_const< GridImp >::type::Traits Traits;
00263 
00264   public:
00266     typedef typename Base::IndexType IndexType;
00267 
00269     static const int dimension = Base::dimension;
00270    
00271     using Base::index;
00272     using Base::subIndex;
00273 
00274         //===========================================================
00278         //===========================================================
00279 
00288     template< int cc >
00289     IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim ) const
00290     {
00291       return index( *(e.subEntity( i, codim )) );
00292     }
00294 
00295         //===========================================================
00299         //===========================================================
00300 
00307     IndexType size ( const int codim ) const
00308     {
00309       IndexType s( 0 );
00310       const std::vector< GeometryType > &geomTs = Base::geomTypes( codim ); 
00311       typedef typename std::vector< GeometryType >::const_iterator Iterator;
00312       const Iterator end = geomTs.end();
00313       for( Iterator it = geomTs.begin(); it != end; ++it )
00314         s += Base::size( *it );
00315       return s;
00316     }
00318   };
00319 
00320 
00399   template<class GridImp, class IdSetImp, class IdTypeImp>
00400   class IdSet
00401   {
00402   public:
00404         typedef IdTypeImp IdType;
00405 
00407     template<class EntityType>
00408     IdType id (const EntityType& e) const
00409     {
00410       enum { cc = EntityType::codimension };
00411       return asImp().template id<cc>(e);
00412     }
00413 
00415     /*
00416       We use the remove_const to extract the Type from the mutable class,
00417       because the const class is not instantiated yet.
00418     */
00419     template<int cc>
00420     IdType id (const typename remove_const<GridImp>::type::
00421                  Traits::template Codim<cc>::Entity& e) const 
00422     {
00423       return asImp().template id<cc>(e);
00424     }
00425 
00428     IdType subId (const typename remove_const<GridImp>::type::
00429       Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
00430     {
00431       return asImp().subId(e,i,codim);
00432     }
00433 
00434     // Default constructor (is not provided automatically because copy constructor is private)
00435     IdSet() {}
00436 
00437   private:
00439     IdSet(const IdSet&);
00441     IdSet& operator=(const IdSet&);
00442 
00444     IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
00446     const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
00447   };
00448 
00449 }
00450 
00451 #endif

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].