1 #ifndef DUNE_POLYGONGRID_IDSET_HH 2 #define DUNE_POLYGONGRID_IDSET_HH 3 4 #include <type_traits> 5 6 #include <dune/geometry/dimension.hh> 7 8 #include <dune/grid/common/indexidset.hh> 9 10 #include <dune/polygongrid/declaration.hh> 11 #include <dune/polygongrid/entity.hh> 12 #include <dune/polygongrid/meshobjects.hh> 13 14 namespace Dune 15 { 16 17 namespace __PolygonGrid 18 { 19 20 // IdSet 21 // ----- 22 23 template< class ct > 24 class IdSet 25 : public Dune::IdSet< const PolygonGrid< ct >, IdSet< ct >, std::size_t > 26 { 27 typedef IdSet< ct > This; 28 typedef Dune::IdSet< const PolygonGrid< ct >, This, std::size_t > Base; 29 30 public: 31 typedef std::size_t Id; 32 33 static const int dimension = 2; 34 35 template< int codim > 36 struct Codim 37 { 38 typedef Dune::Entity< codim, 2, const PolygonGrid< ct >, __PolygonGrid::Entity > Entity; 39 }; 40 41 public: 42 template< class Entity > id(const Entity & entity) const43 Id id ( const Entity &entity ) const 44 { 45 return id< Entity::codimension >( entity ); 46 } 47 48 template< int codim > id(const typename Codim<codim>::Entity & entity) const49 Id id ( const typename Codim< codim >::Entity &entity ) const 50 { 51 return id( entity.impl().index(), codim ); 52 } 53 54 template< class Entity > subId(const Entity & entity,int i,int codim) const55 Id subId ( const Entity &entity, int i, int codim ) const 56 { 57 return subId< Entity::codimension >( entity, i, codim ); 58 } 59 60 template< int cd > subId(const typename Codim<cd>::Entity & entity,int i,int codim) const61 Id subId ( const typename Codim< cd >::Entity &entity, int i, int codim ) const 62 { 63 return id( entity.impl().subIndex( codim, i ), codim ); 64 } 65 66 private: id(std::size_t index,std::size_t codim)67 static constexpr Id id ( std::size_t index, std::size_t codim ) noexcept { return (index << 2) | codim; } 68 }; 69 70 } // namespace __PolygonGrid 71 72 } // namespace Dune 73 74 #endif // #ifndef DUNE_POLYGONGRID_IDSET_HH 75