dune-grid  2.3.1
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$
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  // this does not work, since subEntity is a template method requiring codim to be
292  // a template parameter
293  // return index( *(e.subEntity( i, codim )) );
294  DUNE_THROW(NotImplemented,"subIndex for entities is not is not implemented");
295  return -1;
296  }
298 
299  //===========================================================
303  //===========================================================
304 
311  IndexType size ( const int codim ) const
312  {
313  IndexType s( 0 );
314  const std::vector< GeometryType > &geomTs = Base::geomTypes( codim );
315  typedef typename std::vector< GeometryType >::const_iterator Iterator;
316  const Iterator end = geomTs.end();
317  for( Iterator it = geomTs.begin(); it != end; ++it )
318  s += Base::size( *it );
319  return s;
320  }
322  };
323 
324 
401  template<class GridImp, class IdSetImp, class IdTypeImp>
402  class IdSet
403  {
404  public:
406  typedef IdTypeImp IdType;
407 
409  template<class EntityType>
410  IdType id (const EntityType& e) const
411  {
412  enum { cc = EntityType::codimension };
413  return asImp().template id<cc>(e);
414  }
415 
417  /*
418  We use the remove_const to extract the Type from the mutable class,
419  because the const class is not instantiated yet.
420  */
421  template<int cc>
422  IdType id (const typename remove_const<GridImp>::type::
423  Traits::template Codim<cc>::Entity& e) const
424  {
425  return asImp().template id<cc>(e);
426  }
427 
430  IdType subId (const typename remove_const<GridImp>::type::
431  Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
432  {
433  return asImp().subId(e,i,codim);
434  }
435 
436  // Default constructor (is not provided automatically because copy constructor is private)
437  IdSet() {}
438 
439  private:
441  IdSet(const IdSet&);
443  IdSet& operator=(const IdSet&);
444 
446  IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
448  const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
449  };
450 
451 }
452 
453 #endif