indexidset.hh

Go to the documentation of this file.
00001 // $Id: indexidset.hh 4106 2008-04-08 09:27:17Z robertk $
00002 
00003 #ifndef DUNE_INDEXIDSET_HH
00004 #define DUNE_INDEXIDSET_HH
00005 
00006 #include <iostream>
00007 #include <vector>
00008 #include <dune/common/exceptions.hh>
00009 #include <dune/common/helpertemplates.hh>
00010 
00011 #include <dune/common/bartonnackmanifcheck.hh>
00012 
00018 namespace Dune
00019 {
00073   template<class GridImp, class IndexSetImp, class IndexSetTypes>
00074   class IndexSet {
00075   public:
00078         template <int cd>
00079         struct Codim
00080         {
00081 
00083           template <PartitionIteratorType pitype>
00084           struct Partition
00085           {
00088                 typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00089           };
00090         };
00091 
00093   typedef int IndexType;
00094 
00095         //===========================================================
00099         //===========================================================
00100 
00107     /*
00108       We use the remove_const to extract the Type from the mutable class,
00109       because the const class is not instatiated yet.
00110     */
00111         template<int cc>
00112         int index (const typename remove_const<GridImp>::type::
00113                Traits::template Codim<cc>::Entity& e) const 
00114         {
00115     CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00116     return asImp().template index<cc>(e);
00117         }
00118 
00128     template<class EntityType>
00129     int index (const EntityType& e) const
00130     {
00131       enum { cc = EntityType::codimension };
00132       CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00133       return asImp().template index<cc>(e);
00134     }
00135 
00144     /*
00145       We use the remove_const to extract the Type from the mutable class,
00146       because the const class is not instatiated yet.
00147     */
00148         template<int cc>
00149         int subIndex (const typename remove_const<GridImp>::type::
00150                   Traits::template Codim<0>::Entity& e, int i) const
00151         {
00152     CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex<cc>(e,i)));
00153     return asImp().template subIndex<cc>(e,i);
00154         }
00156 
00157 
00158         //===========================================================
00162         //===========================================================
00163 
00171         const std::vector<GeometryType>& geomTypes (int codim) const
00172         {
00173       CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
00174           return asImp().geomTypes(codim);
00175         }
00176 
00182         int size (GeometryType type) const
00183         {
00184     CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
00185     return asImp().size(type);
00186         }
00187 
00194     int size (int codim) const
00195     {
00196       CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
00197       return asImp().size(codim);
00198     }
00199 
00202     template<class EntityType>
00203     bool contains (const EntityType& e) const
00204     {
00205       CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
00206       return asImp().contains(e);
00207     }
00208 
00212         template<int cd, PartitionIteratorType pitype>
00213         typename Codim<cd>::template Partition<pitype>::Iterator begin () const
00214         {
00215     CHECK_INTERFACE_IMPLEMENTATION((asImp().begin<cd,pitype>()));
00216           return asImp().begin<cd,pitype>();
00217         }
00218   
00222         template<int cd, PartitionIteratorType pitype>
00223         typename Codim<cd>::template Partition<pitype>::Iterator end () const
00224         {
00225     CHECK_INTERFACE_IMPLEMENTATION((asImp().end<cd,pitype>()));
00226           return asImp().end<cd,pitype>();
00227         }
00229 
00230         // Must be explicitely defined although this class should get a default constructor.
00231     IndexSet() {}
00232 
00233   private:
00235     IndexSet(const IndexSet&);
00237     IndexSet& operator=(const IndexSet&);
00238 
00240           IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00242           const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00243   };
00244 
00245 #undef CHECK_INTERFACE_IMPLEMENTATION
00246 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00247 
00251   template<class GridImp, class IndexSetImp, class IndexSetTypes>
00252   class IndexSetDefaultImplementation : 
00253     public IndexSet<GridImp,IndexSetImp,IndexSetTypes> 
00254   {
00255   public:
00258     template <int cd>
00259     struct Codim
00260     {
00261 
00263       template <PartitionIteratorType pitype>
00264       struct Partition
00265       {
00268       typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00269       };
00270     };
00271 
00284     template<int cc>
00285     int subIndex (const typename remove_const<GridImp>::type::
00286                     Traits::template Codim<0>::Entity& e, int i) const
00287     {
00288       return this->index( *(e.template entity<cc>(i) ));
00289     }
00290 
00298     int size (int codim) const
00299     {
00300       int s=0;
00301       const std::vector<GeometryType>& geomTs = asImp().geomTypes(codim); 
00302       for (unsigned int i=0; i<geomTs.size(); ++i)
00303       s += asImp().size(geomTs[i]);
00304       return s;
00305     }
00306 
00309     template<class EntityType>
00310     bool contains (const EntityType& e) const
00311     {
00312       enum { cd = EntityType::codimension };
00313       typedef typename Codim<cd>::template Partition<All_Partition>::Iterator IteratorType; 
00314       IteratorType iend = asImp().template end<cd,All_Partition>();
00315       for (IteratorType it = asImp().template begin<cd,All_Partition>();
00316            it != iend; ++it)
00317       {
00319         if (it->level() == e.level() && this->index(*it) == this->index(e)) return true;
00320       }
00321       return false;
00322     }
00323 
00324   private:
00326           IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00328           const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00329   };
00330 
00331 
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 instatiated 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 
00427     /*
00428       We use the remove_const to extract the Type from the mutable class,
00429       because the const class is not instatiated yet.
00430     */
00431     template<int cc>
00432     IdType subId (const typename remove_const<GridImp>::type::
00433                     Traits::template Codim<0>::Entity& e, int i) const
00434     {
00435       return asImp().template subId<cc>(e,i);
00436     }
00437 
00438     // Default constructor (is not provided automatically because copy constructor is private)
00439     IdSet() {}
00440 
00441    private:
00443     IdSet(const IdSet&);
00445     IdSet& operator=(const IdSet&);
00446 
00448           IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
00450           const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
00451   };
00452 
00466   template<class GridImp, class IdSetImp, class IdTypeImp>
00467   class IdSetDefaultImplementation : public IdSet<GridImp,IdSetImp,IdTypeImp>
00468   {
00469   public:
00471           typedef IdTypeImp IdType;
00472 
00474     /*
00475       We use the remove_const to extract the Type from the mutable class,
00476       because the const class is not instatiated yet.
00477       This default implementation uses the entity's entity() method. This is
00478       slow but works by default for ervery id set implementation.
00479     */
00480     template<int cc>
00481     IdType subId (const typename remove_const<GridImp>::type::
00482                     Traits::template Codim<0>::Entity& e, int i) const
00483     {
00484       return this->id( *(e.template entity<cc>(i)) );
00485     }
00486   };
00487 
00488 
00489 }
00490 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].