dune-fem  2.8-git
typemap.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOMETRY_TYPEMAP_HH
2 #define DUNE_GEOMETRY_TYPEMAP_HH
3 
4 #include <array>
5 #include <utility>
6 
7 #include <dune/geometry/type.hh>
8 
9 #include "typeindexset.hh"
10 
11 namespace Dune
12 {
13 
14  namespace Fem {
15 
16  namespace hpDG {
17 
18  // GeometryTypeMap
19  // ---------------
20 
45  template< class T, class TypeIndexSet >
47  : private TypeIndexSet
48  {
50  typedef std::array< T, TypeIndexSet::size() > Container;
51 
52  using TypeIndexSet::index;
53 
54  public:
56  typedef typename Container::value_type value_type;
58  typedef typename Container::reference reference;
60  typedef typename Container::const_reference const_reference;
62  typedef typename Container::pointer pointer;
64  typedef typename Container::const_pointer const_pointer;
66  typedef typename Container::iterator iterator;
68  typedef typename Container::const_iterator const_iterator;
70  typedef typename Container::size_type size_type;
72  typedef typename Container::difference_type difference_type;
73 
75  typedef value_type Value;
77  typedef iterator Iterator;
81  typedef size_type Size;
82 
88  Iterator begin () noexcept { return container_.begin(); }
90  Iterator end () noexcept { return container_.end(); }
92  ConstIterator begin () const noexcept { return container_.begin(); }
94  ConstIterator end () const noexcept { return container_.end(); }
95 
97  ConstIterator cbegin () const noexcept { return container_.cbegin(); }
99  ConstIterator cend () const noexcept { return container_.cend(); }
100 
109  GeometryType type ( Iterator iterator ) const
110  {
111  return type( static_cast< ConstIterator >( iterator ) );
112  }
113 
115  GeometryType type ( ConstIterator iterator ) const
116  {
117  return TypeIndexSet::type( iterator - begin() );
118  }
119 
127  static constexpr Size size () noexcept { return TypeIndexSet::size(); }
129  static constexpr Size max_size () noexcept { return size(); }
131  static constexpr bool empty () noexcept { return (size() > 0); }
132 
140  Value &operator[] ( const GeometryType &type ) { return container_[ index( type ) ]; }
142  const Value &operator[] ( const GeometryType &type ) const { return container_[ index( type ) ]; }
143 
145  Value &at ( const GeometryType &type ) { return container_.at( index( type ) ); }
147  const Value &at ( const GeometryType &type ) const { return container_.at( index( type ) ); }
148 
150  Value &front () { return container_.front(); }
152  const Value &front () const { return container_.front(); }
153 
155  Value &back () { return container_.back(); }
157  const Value &back () const { return container_.back(); }
158 
160  Value *data () noexcept { return container_.data(); }
162  const Value *data () const noexcept { return container_.data(); }
163 
171  void fill ( const Value &value ) { container_.fill( value ); }
172 
174  void swap ( This &other ) noexcept(noexcept(swap(std::declval<Value &>(), std::declval<Value &>())))
175  {
176  container_.swap( other.container_ );
177  }
178 
181  private:
182  Container container_;
183  };
184 
185 
186 
187  // LocalGeometryTypeMap
188  // --------------------
189 
198  template< class T, int dim, bool regular = false >
200  : public GeometryTypeMap< T, LocalGeometryTypeIndexSet< dim, regular > >
201  {};
202 
203 
204 
205  // GlobalGeometryTypeMap
206  // ---------------------
207 
216  template< class T, int maxdim, bool regular = false >
218  : public GeometryTypeMap< T, GlobalGeometryTypeIndexSet< maxdim, regular > >
219  {};
220 
221 } // namespace hpDG
222 } // namespace Fem
223 } // namespace Dune
224 
225 #endif // #ifndef DUNE_GEOMETRY_TYPEMAP_HH
Definition: bindguard.hh:11
associative container assigning values to each GeometryType
Definition: typemap.hh:48
Container::value_type value_type
value type
Definition: typemap.hh:56
static constexpr Size max_size() noexcept
return maximum size
Definition: typemap.hh:129
static constexpr Size size() noexcept
return size
Definition: typemap.hh:127
void fill(const Value &value)
fill container with value
Definition: typemap.hh:171
Container::const_pointer const_pointer
const pointer type
Definition: typemap.hh:64
GeometryType type(ConstIterator iterator) const
return geometry type from given iterator
Definition: typemap.hh:115
Container::iterator iterator
iterator type
Definition: typemap.hh:66
size_type Size
size type
Definition: typemap.hh:81
Value * data() noexcept
get pointer to data
Definition: typemap.hh:160
ConstIterator begin() const noexcept
return iterator to beginning
Definition: typemap.hh:92
Container::size_type size_type
size type
Definition: typemap.hh:70
Value & back()
access last element
Definition: typemap.hh:155
Container::const_iterator const_iterator
const iterator type
Definition: typemap.hh:68
void swap(This &other) noexcept(noexcept(swap(std::declval< Value & >(), std::declval< Value & >())))
swap content
Definition: typemap.hh:174
Iterator end() noexcept
return iterator to end
Definition: typemap.hh:90
Value & at(const GeometryType &type)
access element
Definition: typemap.hh:145
Container::pointer pointer
pointer type
Definition: typemap.hh:62
iterator Iterator
iterator type
Definition: typemap.hh:77
const Value & at(const GeometryType &type) const
access element
Definition: typemap.hh:147
Iterator begin() noexcept
return iterator to beginning
Definition: typemap.hh:88
const Value * data() const noexcept
get pointer to data
Definition: typemap.hh:162
GeometryType type(Iterator iterator) const
return geometry type from given iterator
Definition: typemap.hh:109
Container::const_reference const_reference
const reference type
Definition: typemap.hh:60
Value & operator[](const GeometryType &type)
access element
Definition: typemap.hh:140
Value & front()
access first element
Definition: typemap.hh:150
value_type Value
value type
Definition: typemap.hh:75
static constexpr bool empty() noexcept
test whether container is empty
Definition: typemap.hh:131
ConstIterator cbegin() const noexcept
return const_iterator to beginning
Definition: typemap.hh:97
Container::reference reference
reference type
Definition: typemap.hh:58
Container::difference_type difference_type
difference type
Definition: typemap.hh:72
const Value & front() const
access first element
Definition: typemap.hh:152
const Value & back() const
access last element
Definition: typemap.hh:157
ConstIterator end() const noexcept
return iterator to end
Definition: typemap.hh:94
ConstIterator cend() const noexcept
return const_iterator to end
Definition: typemap.hh:99
const_iterator ConstIterator
iterator type
Definition: typemap.hh:79
Please doc me.
Definition: typemap.hh:201
Please doc me.
Definition: typemap.hh:219