indexidset.hh
Go to the documentation of this file.00001
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 #include <dune/common/bartonnackmanifcheck.hh>
00011
00012 #include <dune/grid/common/grid.hh>
00013
00014 #if DUNE_ENABLE_INDEXSET_ITERATORS
00015 #define INDEXSET_HAS_ITERATORS
00016 #warning "You enabled iterators on index sets. This feature has been deprecated and will be removed from future releases."
00017 #endif
00018
00024 namespace Dune
00025 {
00079 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00080 class IndexSet {
00081 public:
00082 #ifdef INDEXSET_HAS_ITERATORS
00083
00085 template <int cd>
00086 struct Codim
00087 {
00088
00090 template <PartitionIteratorType pitype>
00091 struct Partition
00092 {
00095 typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00096 };
00097 } DUNE_DEPRECATED;
00098 #endif
00099
00101 typedef unsigned int IndexType;
00102
00103
00107
00108
00115
00116
00117
00118
00119 template<int cc>
00120 IndexType index (const typename remove_const<GridImp>::type::
00121 Traits::template Codim<cc>::Entity& e) const
00122 {
00123 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00124 return asImp().template index<cc>(e);
00125 }
00126
00136 template<class EntityType>
00137 IndexType index (const EntityType& e) const
00138 {
00139 enum { cc = EntityType::codimension };
00140 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00141 return asImp().template index<cc>(e);
00142 }
00143
00152
00153
00154
00155
00156 template<int cc>
00157 IndexType subIndex (const typename remove_const<GridImp>::type::
00158 Traits::template Codim<0>::Entity& e, int i) const
00159 {
00160 CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex<cc>(e,i)));
00161 return asImp().template subIndex<cc>(e,i);
00162 }
00164
00165
00166
00170
00171
00179 const std::vector<GeometryType>& geomTypes (int codim) const
00180 {
00181 CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
00182 return asImp().geomTypes(codim);
00183 }
00184
00190 IndexType size (GeometryType type) const
00191 {
00192 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
00193 return asImp().size(type);
00194 }
00195
00202 IndexType size (int codim) const
00203 {
00204 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
00205 return asImp().size(codim);
00206 }
00207
00210 template<class EntityType>
00211 bool contains (const EntityType& e) const
00212 {
00213 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
00214 return asImp().contains(e);
00215 }
00216
00217 #ifdef INDEXSET_HAS_ITERATORS
00218
00221 template<int cd, PartitionIteratorType pitype>
00222 typename Codim<cd>::template Partition<pitype>::Iterator begin ()const DUNE_DEPRECATED;
00223
00227 template<int cd, PartitionIteratorType pitype>
00228 typename Codim<cd>::template Partition<pitype>::Iterator end () const DUNE_DEPRECATED;
00230 #endif
00231
00232 IndexSet() {}
00233
00234 private:
00236 IndexSet(const IndexSet&);
00238 IndexSet& operator=(const IndexSet&);
00239
00241 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00243 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00244 };
00245
00246 #ifdef INDEXSET_HAS_ITERATORS
00247 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00248 template<int cd, PartitionIteratorType pitype>
00249 DUNE_DEPRECATED
00250 typename IndexSet<GridImp,IndexSetImp,IndexSetTypes>::template Codim<cd>::template Partition<pitype>::Iterator
00251 IndexSet<GridImp,IndexSetImp,IndexSetTypes>::begin() const
00252 {
00253 CHECK_INTERFACE_IMPLEMENTATION((asImp().begin<cd,pitype>()));
00254 return asImp().begin<cd,pitype>();
00255 }
00256
00257 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00258 template<int cd, PartitionIteratorType pitype>
00259 DUNE_DEPRECATED
00260 typename IndexSet<GridImp,IndexSetImp,IndexSetTypes>::template Codim<cd>::template Partition<pitype>::Iterator
00261 IndexSet<GridImp,IndexSetImp,IndexSetTypes>::end() const
00262 {
00263 CHECK_INTERFACE_IMPLEMENTATION((asImp().begin<cd,pitype>()));
00264 return asImp().end<cd,pitype>();
00265 }
00266 #endif
00267
00268 #undef CHECK_INTERFACE_IMPLEMENTATION
00269 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00270
00274 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00275 class IndexSetDefaultImplementation :
00276 public IndexSet<GridImp,IndexSetImp,IndexSetTypes>
00277 {
00278 public:
00281 template <int cd>
00282 struct Codim
00283 {
00284
00286 template <PartitionIteratorType pitype>
00287 struct Partition
00288 {
00291 typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00292 };
00293 } DUNE_DEPRECATED;
00294
00295 typedef typename IndexSet<GridImp,IndexSetImp,IndexSetTypes>::IndexType IndexType;
00296
00309 template<int cc>
00310 IndexType subIndex (const typename remove_const<GridImp>::type::
00311 Traits::template Codim<0>::Entity& e, int i) const
00312 {
00313 return this->index( *(e.template entity<cc>(i) ));
00314 }
00315
00323 IndexType size (int codim) const
00324 {
00325 int s=0;
00326 const std::vector<GeometryType>& geomTs = asImp().geomTypes(codim);
00327 for (unsigned int i=0; i<geomTs.size(); ++i)
00328 s += asImp().size(geomTs[i]);
00329 return s;
00330 }
00331
00334 template<class EntityType>
00335 bool contains (const EntityType& e) const
00336 {
00337 #ifdef INDEXSET_HAS_ITERATORS
00338 enum { cd = EntityType::codimension };
00339 typedef typename Codim<cd>::template Partition<All_Partition>::Iterator IteratorType;
00340 IteratorType iend = asImp().template end<cd,All_Partition>();
00341 for (IteratorType it = asImp().template begin<cd,All_Partition>();
00342 it != iend; ++it)
00343 {
00345 if (it->level() == e.level() && this->index(*it) == this->index(e)) return true;
00346 }
00347 return false;
00348 #else
00349 #ifdef DUNE_DEVEL_MODE
00350 std::cerr << "Warning: method IndexSet::conatins not implemented correctly!" << std::endl;
00351 #endif
00352 return true;
00353 #endif // #ifdef INDEXSET_HAS_ITERATORS
00354 }
00355
00356 private:
00358 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00360 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00361 };
00362
00363
00431 template<class GridImp, class IdSetImp, class IdTypeImp>
00432 class IdSet
00433 {
00434 public:
00436 typedef IdTypeImp IdType;
00437
00439 template<class EntityType>
00440 IdType id (const EntityType& e) const
00441 {
00442 enum { cc = EntityType::codimension };
00443 return asImp().template id<cc>(e);
00444 }
00445
00447
00448
00449
00450
00451 template<int cc>
00452 IdType id (const typename remove_const<GridImp>::type::
00453 Traits::template Codim<cc>::Entity& e) const
00454 {
00455 return asImp().template id<cc>(e);
00456 }
00457
00459
00460
00461
00462
00463 template<int cc>
00464 IdType subId (const typename remove_const<GridImp>::type::
00465 Traits::template Codim<0>::Entity& e, int i) const
00466 {
00467 return asImp().template subId<cc>(e,i);
00468 }
00469
00470
00471 IdSet() {}
00472
00473 private:
00475 IdSet(const IdSet&);
00477 IdSet& operator=(const IdSet&);
00478
00480 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
00482 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
00483 };
00484
00498 template<class GridImp, class IdSetImp, class IdTypeImp>
00499 class IdSetDefaultImplementation : public IdSet<GridImp,IdSetImp,IdTypeImp>
00500 {
00501 public:
00503 typedef IdTypeImp IdType;
00504
00506
00507
00508
00509
00510
00511
00512 template<int cc>
00513 IdType subId (const typename remove_const<GridImp>::type::
00514 Traits::template Codim<0>::Entity& e, int i) const
00515 {
00516 return this->id( *(e.template entity<cc>(i)) );
00517 }
00518 };
00519
00520
00521 }
00522 #endif