dune-grid  2.2.1
dynamicsubindexid.hh
Go to the documentation of this file.
1 #ifndef DUNE_DYNAMICCODIMSUBINDEXID_HH
2 #define DUNE_DYNAMICCODIMSUBINDEXID_HH
3 
4 #include <dune/common/forloop.hh>
5 #include <dune/common/typetraits.hh>
6 #include <dune/geometry/genericgeometry/conversion.hh>
7 
8 #warning This file is deprecated and will be removed after the release of dune-grid 2.2.
9 
10 namespace Dune
11 {
12 
13  // DynamicSubIndex
14  // ---------------
15 
16  template< class Grid, class IndexSet >
18  {
20 
21  typedef typename remove_const< Grid >::type::Traits Traits;
22 
23  static const unsigned int dimension = remove_const< Grid >::type::dimension;
24 
25  typedef typename Traits::template Codim< 0 >::Entity Element;
26 
27  public:
28  typedef typename IndexSet::IndexType IndexType;
29 
30  private:
31  struct Caller
32  {
33  virtual ~Caller ()
34  {}
35 
36  virtual IndexType
37  subIndex ( const IndexSet &indexSet, const Element &e, int i ) const = 0;
38  };
39 
40  template< int codim >
41  struct CallerImpl
42  : public Caller
43  {
44  virtual IndexType
45  subIndex ( const IndexSet &indexSet, const Element &e, int i ) const
46  {
47  typedef GenericGeometry::MapNumberingProvider< dimension > Numbering;
48  const unsigned int tid = GenericGeometry::topologyId( e.type() );
49  const int j = Numbering::template generic2dune< codim >( tid, i );
50  return indexSet.template subIndex< codim >( e, j );
51  }
52 
53  static void apply ( const Caller *(&caller)[ dimension+1 ] )
54  {
55  caller[ codim ] = new CallerImpl< codim >;
56  }
57  };
58 
59  // prohibit copying and assignment
60  DynamicSubIndex ( const This & );
61  This &operator= ( const This & );
62 
63  public:
64  explicit DynamicSubIndex ( const IndexSet &indexSet )
65  : indexSet_( indexSet )
66  {
67  Dune::ForLoop< CallerImpl, 0, dimension >::apply( caller_ );
68  }
69 
71  {
72  for( unsigned int codim = 0; codim <= dimension; ++codim )
73  delete caller_[ codim ];
74  }
75 
76  IndexType operator() ( const Element &e, int i, unsigned int codim ) const
77  {
78  assert( codim <= dimension );
79  return caller_[ codim ]->subIndex( indexSet_, e, i );
80  }
81 
82  private:
83  const IndexSet &indexSet_;
84  const Caller *caller_[ dimension+1 ];
85  };
86 
87 
88 
89  // DynamicSubId
90  // ------------
91 
92  template< class Grid, class IdSet >
94  {
96 
97  typedef typename remove_const< Grid >::type::Traits Traits;
98 
99  static const unsigned int dimension = remove_const< Grid >::type::dimension;
100 
101  typedef typename Traits::template Codim< 0 >::Entity Element;
102 
103  public:
104  typedef typename IdSet::IdType IdType;
105 
106  private:
107  struct Caller
108  {
109  virtual ~Caller ()
110  {}
111 
112  virtual IdType
113  subId ( const IdSet &idSet, const Element &e, int i ) const = 0;
114  };
115 
116  template< int codim >
117  struct CallerImpl
118  : public Caller
119  {
120  virtual IdType
121  subId ( const IdSet &idSet, const Element &e, int i ) const
122  {
123  typedef GenericGeometry::MapNumberingProvider< dimension > Numbering;
124  const unsigned int tid = GenericGeometry::topologyId( e.type() );
125  const int j = Numbering::template generic2dune< codim >( tid, i );
126  return idSet.template subId< codim >( e, j );
127  }
128 
129  static void apply ( const Caller *(&caller)[ dimension+1 ] )
130  {
131  caller[ codim ] = new CallerImpl< codim >;
132  }
133  };
134 
135  // prohibit copying and assignment
136  DynamicSubId ( const This & );
137  This &operator= ( const This & );
138 
139  public:
140  explicit DynamicSubId ( const IdSet &idSet )
141  : idSet_( idSet )
142  {
143  Dune::ForLoop< CallerImpl, 0, dimension >::apply( caller_ );
144  }
145 
147  {
148  for( unsigned int codim = 0; codim <= dimension; ++codim )
149  delete caller_[ codim ];
150  }
151 
152  IdType operator() ( const Element &e, int i, unsigned int codim ) const
153  {
154  assert( codim <= dimension );
155  return caller_[ codim ]->subId( idSet_, e, i );
156  }
157 
158  private:
159  const IdSet &idSet_;
160  const Caller *caller_[ dimension+1 ];
161  };
162 
163 }
164 
165 #endif // #ifndef DUNE_DYNAMICCODIMSUBINDEXID_HH