dune-grid  2.2.0
geometrygrid/indexsets.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GEOGRID_INDEXSETS_HH
00002 #define DUNE_GEOGRID_INDEXSETS_HH
00003 
00004 #include <vector>
00005 
00006 #include <dune/common/typetraits.hh>
00007 
00008 #include <dune/grid/common/gridenums.hh>
00009 #include <dune/grid/common/indexidset.hh>
00010 
00011 #include <dune/grid/geometrygrid/declaration.hh>
00012 
00013 namespace Dune
00014 {
00015 
00016   namespace GeoGrid
00017   {
00018 
00019     // IndexSet
00020     // --------
00021 
00022     template< class Grid, class HostIndexSet >
00023     class IndexSet
00024     : public Dune::IndexSet< Grid, IndexSet< Grid, HostIndexSet >, typename HostIndexSet::IndexType >
00025     {
00026       typedef IndexSet< Grid, HostIndexSet > This;
00027       typedef Dune::IndexSet< Grid, This, typename HostIndexSet::IndexType > Base;
00028 
00029       typedef typename remove_const< Grid >::type::Traits Traits;
00030 
00031       typedef typename Traits::HostGrid HostGrid;
00032 
00033     public:
00034       static const int dimension = Traits::dimension;
00035 
00036       typedef typename Base::IndexType IndexType;
00037 
00038       IndexSet ()
00039       : hostIndexSet_( 0 )
00040       {}
00041 
00042       explicit IndexSet ( const HostIndexSet &hostIndexSet )
00043       : hostIndexSet_( &hostIndexSet )
00044       {}
00045 
00046       IndexSet ( const This &other )
00047       : hostIndexSet_( other.hostIndexSet_ )
00048       {}
00049 
00050       const This &operator= ( const This &other )
00051       {
00052         hostIndexSet_ = other.hostIndexSet_;
00053         return *this;
00054       }
00055 
00056       using Base::index;
00057       using Base::subIndex;
00058 
00059       template< int cc >
00060       IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
00061       {
00062         return Grid::getRealImplementation( entity ).index( hostIndexSet() );
00063       }
00064 
00065       template< int cc >
00066       IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
00067       {
00068         return Grid::getRealImplementation( entity ).subIndex( hostIndexSet(), i, codim );
00069       }
00070 
00071       IndexType size ( GeometryType type ) const
00072       {
00073         return hostIndexSet().size( type );
00074       }
00075            
00076       int size ( int codim ) const
00077       {
00078         return hostIndexSet().size( codim );
00079       }
00080 
00081       template< class Entity >
00082       bool contains ( const Entity &entity ) const
00083       {
00084         return Grid::getRealImplementation( entity ).isContained( hostIndexSet() );
00085       }
00086 
00087       const std::vector< GeometryType > &geomTypes ( int codim ) const
00088       {
00089         return hostIndexSet().geomTypes( codim );
00090       }
00091     
00092       operator bool () const { return bool( hostIndexSet_ ); }
00093 
00094     private:
00095       const HostIndexSet &hostIndexSet () const
00096       {
00097         assert( *this );
00098         return *hostIndexSet_;
00099       }
00100 
00101       const HostIndexSet *hostIndexSet_;
00102     };
00103 
00104   } // namespace GeoGrid
00105 
00106 } // namespace Dune
00107 
00108 #endif // #ifndef DUNE_GEOGRID_INDEXSETS_HH