Dune Core Modules (2.6.0)

propertymap.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_PROPERTYMAP_HH
4#define DUNE_PROPERTYMAP_HH
5
6#include <cstddef>
7#include <iterator>
8#include <type_traits>
9
10namespace Dune
11{
12
13 template<class PM>
14 struct PropertyMapTraits
15 {
19 typedef typename PM::KeyType KeyType;
23 typedef typename PM::ValueType ValueType;
27 typedef typename PM::Reference Reference;
31 typedef typename PM::Category Category;
32 };
33
36 {};
37
40 {};
41
48 {};
49
55 {};
56
57 template<class T>
58 struct PropertyMapTraits<T*>
59 {
60 typedef T ValueType;
61 typedef ValueType& Reference;
62 typedef std::ptrdiff_t KeyType;
63 typedef LvaluePropertyMapTag Category;
64 };
65
66
67 template<class T>
68 struct PropertyMapTraits<const T*>
69 {
70 typedef T ValueType;
71 typedef const ValueType& Reference;
72 typedef std::ptrdiff_t KeyType;
73 typedef LvaluePropertyMapTag Category;
74 };
75
76 template<class Reference, class PropertyMap>
77 struct RAPropertyMapHelper
78 {};
79
80 template<class Reference, class PropertyMap, class Key>
81 inline Reference
82 get(const RAPropertyMapHelper<Reference,PropertyMap>& pmap,
83 const Key& key)
84 {
85 return static_cast<const PropertyMap&>(pmap)[key];
86 }
87
88 template<class Reference, class PropertyMap, class Key, class Value>
89 inline void
90 put(const RAPropertyMapHelper<Reference,PropertyMap>& pmap,
91 const Key& key, const Value& value)
92 {
93 static_assert(std::is_convertible<typename PropertyMap::Category,WritablePropertyMapTag>::value,
94 "WritablePropertyMapTag required!");
95 static_cast<const PropertyMap&>(pmap)[key] = value;
96 }
97
101 template<class RAI, class IM,
102 class T = typename std::iterator_traits<RAI>::value_type,
103 class R = typename std::iterator_traits<RAI>::reference>
105 : public RAPropertyMapHelper<R,IteratorPropertyMap<RAI,IM,T,R> >
106 {
107 public:
112
118 typedef IM IndexMap;
119
123 typedef typename IndexMap::KeyType KeyType;
124
128 typedef T ValueType;
129
133 typedef R Reference;
134
139
148 const IndexMap& im=IndexMap())
149 : iter_(iter), indexMap_(im)
150 {}
151
154 : iter_(), indexMap_()
155 {}
156
158 inline Reference operator[](KeyType key) const
159 {
160 return *(iter_ + get(indexMap_, key));
161 }
162
163 private:
167 IndexMap indexMap_;
168 };
169
174 template<typename T>
176 : RAPropertyMapHelper<typename T::value_type::second_type&,
177 AssociativePropertyMap<T> >
178 {
182 typedef T UniqueAssociativeContainer;
183
187 typedef typename UniqueAssociativeContainer::value_type::first_type
188 KeyType;
189
193 typedef typename UniqueAssociativeContainer::value_type::second_type
194 ValueType;
195
199 typedef ValueType& Reference;
200
205
208 : map_(0)
209 {}
210
212 inline AssociativePropertyMap(UniqueAssociativeContainer& map)
213 : map_(&map)
214 {}
215
220 inline Reference operator[](KeyType key) const
221 {
222 return map_->find(key)->second;
223 }
224 private:
225 UniqueAssociativeContainer* map_;
226 };
227
232 template<typename T>
234 : RAPropertyMapHelper<const typename T::value_type::second_type&,
235 ConstAssociativePropertyMap<T> >
236 {
240 typedef T UniqueAssociativeContainer;
241
245 typedef typename UniqueAssociativeContainer::value_type::first_type
246 KeyType;
247
251 typedef typename UniqueAssociativeContainer::value_type::second_type
252 ValueType;
253
257 typedef const ValueType& Reference;
258
263
266 : map_(0)
267 {}
268
270 inline ConstAssociativePropertyMap(const UniqueAssociativeContainer& map)
271 : map_(&map)
272 {}
273
278 inline Reference operator[](KeyType key) const
279 {
280 return map_->find(key)->second;
281 }
282 private:
283 const UniqueAssociativeContainer* map_;
284 };
285
290 : public RAPropertyMapHelper<std::size_t, IdentityMap>
291 {
293 typedef std::size_t KeyType;
294
296 typedef std::size_t ValueType;
297
299 typedef std::size_t Reference;
300
303
304 inline ValueType operator[](const KeyType& key) const
305 {
306 return key;
307 }
308 };
309
310
316 template<typename T, typename C>
318 {
322 typedef T Tag;
327 typedef C Container;
328 };
329
330}
331
332#endif
An adapter to turn an unique associative container into a property map.
Definition: propertymap.hh:178
An adaptor to turn an unique associative container into a property map.
Definition: propertymap.hh:236
Adapter to turn a random access iterator into a property map.
Definition: propertymap.hh:106
IndexMap::KeyType KeyType
The key type of the property map.
Definition: propertymap.hh:123
R Reference
The reference type of the property map.
Definition: propertymap.hh:133
T ValueType
The value type of the property map.
Definition: propertymap.hh:128
Reference operator[](KeyType key) const
Access the a value by reference.
Definition: propertymap.hh:158
IteratorPropertyMap(RandomAccessIterator iter, const IndexMap &im=IndexMap())
Constructor.
Definition: propertymap.hh:147
IteratorPropertyMap()
Constructor.
Definition: propertymap.hh:153
IM IndexMap
The type of the index map.
Definition: propertymap.hh:118
RAI RandomAccessIterator
The type of the random access iterator.
Definition: propertymap.hh:111
LvaluePropertyMapTag Category
The category of this property map.
Definition: propertymap.hh:138
Dune namespace.
Definition: alignedallocator.hh:10
A property map that applies the identity function to integers.
Definition: propertymap.hh:291
std::size_t ValueType
The value type of the map.
Definition: propertymap.hh:296
std::size_t KeyType
The key type of the map.
Definition: propertymap.hh:293
std::size_t Reference
The reference type of the map.
Definition: propertymap.hh:299
ReadablePropertyMapTag Category
The category of the map.
Definition: propertymap.hh:302
Tag for the category of lvalue property maps.
Definition: propertymap.hh:55
Selector for the property map type.
Definition: propertymap.hh:318
T Tag
the tag identifying the property.
Definition: propertymap.hh:322
C Container
The container type to whose entries the properties are attached.
Definition: propertymap.hh:327
Tag for the category of readable and writable property maps.
Definition: propertymap.hh:48
Tag for the category of readable property maps.
Definition: propertymap.hh:36
Tag for the category of writable property maps.
Definition: propertymap.hh:40
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)