Dune Core Modules (2.4.2)

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
9#include "typetraits.hh"
10
11namespace Dune
12{
13
14 template<class PM>
15 struct PropertyMapTraits
16 {
20 typedef typename PM::KeyType KeyType;
24 typedef typename PM::ValueType ValueType;
28 typedef typename PM::Reference Reference;
32 typedef typename PM::Category Category;
33 };
34
37 {};
38
41 {};
42
49 {};
50
56 {};
57
58 template<class T>
59 struct PropertyMapTraits<T*>
60 {
61 typedef T ValueType;
62 typedef ValueType& Reference;
63 typedef std::ptrdiff_t KeyType;
64 typedef LvaluePropertyMapTag Category;
65 };
66
67
68 template<class T>
69 struct PropertyMapTraits<const T*>
70 {
71 typedef T ValueType;
72 typedef const ValueType& Reference;
73 typedef std::ptrdiff_t KeyType;
74 typedef LvaluePropertyMapTag Category;
75 };
76
77 template<class Reference, class PropertyMap>
78 struct RAPropertyMapHelper
79 {};
80
81 template<class Reference, class PropertyMap, class Key>
82 inline Reference
83 get(const RAPropertyMapHelper<Reference,PropertyMap>& pmap,
84 const Key& key)
85 {
86 return static_cast<const PropertyMap&>(pmap)[key];
87 }
88
89 template<class Reference, class PropertyMap, class Key, class Value>
90 inline void
91 put(const RAPropertyMapHelper<Reference,PropertyMap>& pmap,
92 const Key& key, const Value& value)
93 {
94 static_assert((Conversion<typename PropertyMap::Category,WritablePropertyMapTag>
95 ::exists), "WritablePropertyMapTag required!");
96 static_cast<const PropertyMap&>(pmap)[key] = value;
97 }
98
102 template<class RAI, class IM,
103 class T = typename std::iterator_traits<RAI>::value_type,
104 class R = typename std::iterator_traits<RAI>::reference>
106 : public RAPropertyMapHelper<R,IteratorPropertyMap<RAI,IM,T,R> >
107 {
108 public:
113
119 typedef IM IndexMap;
120
124 typedef typename IndexMap::KeyType KeyType;
125
129 typedef T ValueType;
130
134 typedef R Reference;
135
140
149 const IndexMap& im=IndexMap())
150 : iter_(iter), indexMap_(im)
151 {}
152
155 : iter_(), indexMap_()
156 {}
157
159 inline Reference operator[](KeyType key) const
160 {
161 return *(iter_ + get(indexMap_, key));
162 }
163
164 private:
168 IndexMap indexMap_;
169 };
170
175 template<typename T>
177 : RAPropertyMapHelper<typename T::value_type::second_type&,
178 AssociativePropertyMap<T> >
179 {
183 typedef T UniqueAssociativeContainer;
184
188 typedef typename UniqueAssociativeContainer::value_type::first_type
189 KeyType;
190
194 typedef typename UniqueAssociativeContainer::value_type::second_type
195 ValueType;
196
200 typedef ValueType& Reference;
201
206
209 : map_(0)
210 {}
211
213 inline AssociativePropertyMap(UniqueAssociativeContainer& map)
214 : map_(&map)
215 {}
216
221 inline Reference operator[](KeyType key) const
222 {
223 return map_->find(key)->second;
224 }
225 private:
226 UniqueAssociativeContainer* map_;
227 };
228
233 template<typename T>
235 : RAPropertyMapHelper<const typename T::value_type::second_type&,
236 ConstAssociativePropertyMap<T> >
237 {
241 typedef T UniqueAssociativeContainer;
242
246 typedef typename UniqueAssociativeContainer::value_type::first_type
247 KeyType;
248
252 typedef typename UniqueAssociativeContainer::value_type::second_type
253 ValueType;
254
258 typedef const ValueType& Reference;
259
264
267 : map_(0)
268 {}
269
271 inline ConstAssociativePropertyMap(const UniqueAssociativeContainer& map)
272 : map_(&map)
273 {}
274
279 inline Reference operator[](KeyType key) const
280 {
281 return map_->find(key)->second;
282 }
283 private:
284 const UniqueAssociativeContainer* map_;
285 };
286
291 : public RAPropertyMapHelper<std::size_t, IdentityMap>
292 {
294 typedef std::size_t KeyType;
295
297 typedef std::size_t ValueType;
298
300 typedef std::size_t Reference;
301
304
305 inline ValueType operator[](const KeyType& key) const
306 {
307 return key;
308 }
309 };
310
311
317 template<typename T, typename C>
319 {
323 typedef T Tag;
328 typedef C Container;
329 };
330
331}
332
333#endif
An adapter to turn an unique associative container into a property map.
Definition: propertymap.hh:179
An adaptor to turn an unique associative container into a property map.
Definition: propertymap.hh:237
Adapter to turn a random access iterator into a property map.
Definition: propertymap.hh:107
IndexMap::KeyType KeyType
The key type of the property map.
Definition: propertymap.hh:124
R Reference
The reference type of the property map.
Definition: propertymap.hh:134
T ValueType
The value type of the property map.
Definition: propertymap.hh:129
Reference operator[](KeyType key) const
Access the a value by reference.
Definition: propertymap.hh:159
IteratorPropertyMap(RandomAccessIterator iter, const IndexMap &im=IndexMap())
Constructor.
Definition: propertymap.hh:148
IteratorPropertyMap()
Constructor.
Definition: propertymap.hh:154
IM IndexMap
The type of the index map.
Definition: propertymap.hh:119
RAI RandomAccessIterator
The type of the random access iterator.
Definition: propertymap.hh:112
LvaluePropertyMapTag Category
The category of this property map.
Definition: propertymap.hh:139
Dune namespace.
Definition: alignment.hh:10
A property map that applies the identity function to integers.
Definition: propertymap.hh:292
std::size_t ValueType
The value type of the map.
Definition: propertymap.hh:297
std::size_t KeyType
The key type of the map.
Definition: propertymap.hh:294
std::size_t Reference
The reference type of the map.
Definition: propertymap.hh:300
ReadablePropertyMapTag Category
The category of the map.
Definition: propertymap.hh:303
Tag for the category of lvalue property maps.
Definition: propertymap.hh:56
Selector for the property map type.
Definition: propertymap.hh:319
T Tag
the tag identifying the property.
Definition: propertymap.hh:323
C Container
The container type to whose entries the properties are attached.
Definition: propertymap.hh:328
Tag for the category of readable and writable property maps.
Definition: propertymap.hh:49
Tag for the category of readable property maps.
Definition: propertymap.hh:37
Tag for the category of writable property maps.
Definition: propertymap.hh:41
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)