dune-grid  2.2.0
indexidset.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // $Id: indexidset.hh 7328 2011-01-20 14:25:22Z graeser $
4 
5 #ifndef DUNE_INDEXIDSET_HH
6 #define DUNE_INDEXIDSET_HH
7 
8 #include <iostream>
9 #include <vector>
10 #include <dune/common/exceptions.hh>
11 #include <dune/common/forloop.hh>
12 #include <dune/grid/common/grid.hh>
13 
14 
20 namespace Dune
21 {
22 
23 #include <dune/common/bartonnackmanifcheck.hh>
24 
76  template<class GridImp, class IndexSetImp, class IndexTypeImp>
77  class IndexSet
78  {
79  /* We use the remove_const to extract the Type from the mutable class,
80  because the const class is not instantiated yet. */
81  typedef typename remove_const< GridImp >::type::Traits Traits;
82 
83  public:
85  typedef IndexTypeImp IndexType;
86 
88  static const int dimension = remove_const< GridImp >::type::dimension;
89 
90  //===========================================================
94  //===========================================================
95 
102  /*
103  We use the remove_const to extract the Type from the mutable class,
104  because the const class is not instantiated yet.
105  */
106  template<int cc>
107  IndexType index (const typename remove_const<GridImp>::type::
108  Traits::template Codim<cc>::Entity& e) const
109  {
110  CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
111  return asImp().template index<cc>(e);
112  }
113 
123  template<class EntityType>
124  IndexType index (const EntityType& e) const
125  {
126  enum { cc = EntityType::codimension };
127  CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
128  return asImp().template index<cc>(e);
129  }
130 
145  template< int cc >
146  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
147  int i, unsigned int codim ) const
148  {
149  CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
150  return asImp().template subIndex< cc >(e,i,codim);
151  }
152 
171  template< class Entity >
172  IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
173  {
174  static const int cc = Entity::codimension;
175  return asImp().template subIndex< cc >( e, i, codim );
176  }
178 
179 
180  //===========================================================
184  //===========================================================
185 
193  const std::vector<GeometryType>& geomTypes (int codim) const
194  {
195  CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
196  return asImp().geomTypes(codim);
197  }
198 
205  {
206  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
207  return asImp().size(type);
208  }
209 
216  IndexType size (int codim) const
217  {
218  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
219  return asImp().size(codim);
220  }
221 
227  template<class EntityType>
228  bool contains (const EntityType& e) const
229  {
230  CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
231  return asImp().contains(e);
232  }
233 
234  // Must be explicitely defined although this class should get a default constructor.
235  IndexSet() {}
236 
237  private:
239  IndexSet(const IndexSet&);
241  IndexSet& operator=(const IndexSet&);
242 
244  IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
246  const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
247  };
248 
249 #undef CHECK_INTERFACE_IMPLEMENTATION
250 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
251 
252 
253 
257  template<class GridImp, class IndexSetImp>
259  : public IndexSet< GridImp, IndexSetImp >
260  {
262  typedef typename remove_const< GridImp >::type::Traits Traits;
263 
264  public:
266  typedef typename Base::IndexType IndexType;
267 
269  static const int dimension = Base::dimension;
270 
271  using Base::index;
272  using Base::subIndex;
273 
274  //===========================================================
278  //===========================================================
279 
288  template< int cc >
289  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim ) const
290  {
291  return index( *(e.subEntity( i, codim )) );
292  }
294 
295  //===========================================================
299  //===========================================================
300 
307  IndexType size ( const int codim ) const
308  {
309  IndexType s( 0 );
310  const std::vector< GeometryType > &geomTs = Base::geomTypes( codim );
311  typedef typename std::vector< GeometryType >::const_iterator Iterator;
312  const Iterator end = geomTs.end();
313  for( Iterator it = geomTs.begin(); it != end; ++it )
314  s += Base::size( *it );
315  return s;
316  }
318  };
319 
320 
399  template<class GridImp, class IdSetImp, class IdTypeImp>
400  class IdSet
401  {
402  public:
404  typedef IdTypeImp IdType;
405 
407  template<class EntityType>
408  IdType id (const EntityType& e) const
409  {
410  enum { cc = EntityType::codimension };
411  return asImp().template id<cc>(e);
412  }
413 
415  /*
416  We use the remove_const to extract the Type from the mutable class,
417  because the const class is not instantiated yet.
418  */
419  template<int cc>
420  IdType id (const typename remove_const<GridImp>::type::
421  Traits::template Codim<cc>::Entity& e) const
422  {
423  return asImp().template id<cc>(e);
424  }
425 
428  IdType subId (const typename remove_const<GridImp>::type::
429  Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
430  {
431  return asImp().subId(e,i,codim);
432  }
433 
434  // Default constructor (is not provided automatically because copy constructor is private)
435  IdSet() {}
436 
437  private:
439  IdSet(const IdSet&);
441  IdSet& operator=(const IdSet&);
442 
444  IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
446  const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
447  };
448 
449 }
450 
451 #endif