dune-grid  2.2.1
geometrygrid/indexsets.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOGRID_INDEXSETS_HH
2 #define DUNE_GEOGRID_INDEXSETS_HH
3 
4 #include <vector>
5 
6 #include <dune/common/typetraits.hh>
7 
10 
12 
13 namespace Dune
14 {
15 
16  namespace GeoGrid
17  {
18 
19  // IndexSet
20  // --------
21 
22  template< class Grid, class HostIndexSet >
23  class IndexSet
24  : public Dune::IndexSet< Grid, IndexSet< Grid, HostIndexSet >, typename HostIndexSet::IndexType >
25  {
28 
29  typedef typename remove_const< Grid >::type::Traits Traits;
30 
31  typedef typename Traits::HostGrid HostGrid;
32 
33  public:
34  static const int dimension = Traits::dimension;
35 
36  typedef typename Base::IndexType IndexType;
37 
39  : hostIndexSet_( 0 )
40  {}
41 
42  explicit IndexSet ( const HostIndexSet &hostIndexSet )
43  : hostIndexSet_( &hostIndexSet )
44  {}
45 
46  IndexSet ( const This &other )
47  : hostIndexSet_( other.hostIndexSet_ )
48  {}
49 
50  const This &operator= ( const This &other )
51  {
52  hostIndexSet_ = other.hostIndexSet_;
53  return *this;
54  }
55 
56  using Base::index;
57  using Base::subIndex;
58 
59  template< int cc >
60  IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
61  {
62  return Grid::getRealImplementation( entity ).index( hostIndexSet() );
63  }
64 
65  template< int cc >
66  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
67  {
68  return Grid::getRealImplementation( entity ).subIndex( hostIndexSet(), i, codim );
69  }
70 
71  IndexType size ( GeometryType type ) const
72  {
73  return hostIndexSet().size( type );
74  }
75 
76  int size ( int codim ) const
77  {
78  return hostIndexSet().size( codim );
79  }
80 
81  template< class Entity >
82  bool contains ( const Entity &entity ) const
83  {
84  return Grid::getRealImplementation( entity ).isContained( hostIndexSet() );
85  }
86 
87  const std::vector< GeometryType > &geomTypes ( int codim ) const
88  {
89  return hostIndexSet().geomTypes( codim );
90  }
91 
92  operator bool () const { return bool( hostIndexSet_ ); }
93 
94  private:
95  const HostIndexSet &hostIndexSet () const
96  {
97  assert( *this );
98  return *hostIndexSet_;
99  }
100 
101  const HostIndexSet *hostIndexSet_;
102  };
103 
104  } // namespace GeoGrid
105 
106 } // namespace Dune
107 
108 #endif // #ifndef DUNE_GEOGRID_INDEXSETS_HH