dune-common 2.9.0
Loading...
Searching...
No Matches
propertymap.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_PROPERTYMAP_HH
6#define DUNE_PROPERTYMAP_HH
7
8#include <cstddef>
9#include <iterator>
10#include <type_traits>
11
12namespace Dune
13{
14
15 template<class PM>
17 {
21 typedef typename PM::KeyType KeyType;
25 typedef typename PM::ValueType ValueType;
29 typedef typename PM::Reference Reference;
33 typedef typename PM::Category Category;
34 };
35
39
43
51
58
59 template<class T>
61 {
62 typedef T ValueType;
64 typedef std::ptrdiff_t KeyType;
66 };
67
68
69 template<class T>
70 struct PropertyMapTraits<const T*>
71 {
72 typedef T ValueType;
73 typedef const ValueType& Reference;
74 typedef std::ptrdiff_t KeyType;
76 };
77
78 template<class Reference, class PropertyMap>
80 {};
81
82 template<class Reference, class PropertyMap, class Key>
83 inline Reference
85 const Key& key)
86 {
87 return static_cast<const PropertyMap&>(pmap)[key];
88 }
89
90 template<class Reference, class PropertyMap, class Key, class Value>
91 inline void
93 const Key& key, const Value& value)
94 {
95 static_assert(std::is_convertible<typename PropertyMap::Category,WritablePropertyMapTag>::value,
96 "WritablePropertyMapTag required!");
97 static_cast<const PropertyMap&>(pmap)[key] = value;
98 }
99
103 template<class RAI, class IM,
104 class T = typename std::iterator_traits<RAI>::value_type,
105 class R = typename std::iterator_traits<RAI>::reference>
107 : public RAPropertyMapHelper<R,IteratorPropertyMap<RAI,IM,T,R> >
108 {
109 public:
114
120 typedef IM IndexMap;
121
125 typedef typename IndexMap::KeyType KeyType;
126
130 typedef T ValueType;
131
135 typedef R Reference;
136
141
150 const IndexMap& im=IndexMap())
151 : iter_(iter), indexMap_(im)
152 {}
153
156 : iter_(), indexMap_()
157 {}
158
160 inline Reference operator[](KeyType key) const
161 {
162 return *(iter_ + get(indexMap_, key));
163 }
164
165 private:
169 IndexMap indexMap_;
170 };
171
176 template<typename T>
178 : RAPropertyMapHelper<typename T::value_type::second_type&,
179 AssociativePropertyMap<T> >
180 {
184 typedef T UniqueAssociativeContainer;
185
189 typedef typename UniqueAssociativeContainer::value_type::first_type
190 KeyType;
191
195 typedef typename UniqueAssociativeContainer::value_type::second_type
196 ValueType;
197
201 typedef ValueType& Reference;
202
207
210 : map_(0)
211 {}
212
214 inline AssociativePropertyMap(UniqueAssociativeContainer& map)
215 : map_(&map)
216 {}
217
222 inline Reference operator[](KeyType key) const
223 {
224 return map_->find(key)->second;
225 }
226 private:
227 UniqueAssociativeContainer* map_;
228 };
229
234 template<typename T>
236 : RAPropertyMapHelper<const typename T::value_type::second_type&,
237 ConstAssociativePropertyMap<T> >
238 {
242 typedef T UniqueAssociativeContainer;
243
247 typedef typename UniqueAssociativeContainer::value_type::first_type
248 KeyType;
249
253 typedef typename UniqueAssociativeContainer::value_type::second_type
254 ValueType;
255
259 typedef const ValueType& Reference;
260
265
268 : map_(0)
269 {}
270
272 inline ConstAssociativePropertyMap(const UniqueAssociativeContainer& map)
273 : map_(&map)
274 {}
275
280 inline Reference operator[](KeyType key) const
281 {
282 return map_->find(key)->second;
283 }
284 private:
285 const UniqueAssociativeContainer* map_;
286 };
287
292 : public RAPropertyMapHelper<std::size_t, IdentityMap>
293 {
295 typedef std::size_t KeyType;
296
298 typedef std::size_t ValueType;
299
301 typedef std::size_t Reference;
302
305
306 inline ValueType operator[](const KeyType& key) const
307 {
308 return key;
309 }
310 };
311
312
318 template<typename T, typename C>
320 {
324 typedef T Tag;
329 typedef C Container;
330 };
331
332}
333
334#endif
Dune namespace.
Definition alignedallocator.hh:13
void put(const RAPropertyMapHelper< Reference, PropertyMap > &pmap, const Key &key, const Value &value)
Definition propertymap.hh:92
Reference get(const RAPropertyMapHelper< Reference, PropertyMap > &pmap, const Key &key)
Definition propertymap.hh:84
Definition propertymap.hh:17
PM::ValueType ValueType
The type of the values of the property map.
Definition propertymap.hh:25
PM::Category Category
The category the property map belongs to.
Definition propertymap.hh:33
PM::Reference Reference
The type of the reference to the values.
Definition propertymap.hh:29
PM::KeyType KeyType
The type of the key of the property map.
Definition propertymap.hh:21
Tag for the category of readable property maps.
Definition propertymap.hh:38
Tag for the category of writable property maps.
Definition propertymap.hh:42
Tag for the category of readable and writable property maps.
Definition propertymap.hh:50
Tag for the category of lvalue property maps.
Definition propertymap.hh:57
ValueType & Reference
Definition propertymap.hh:63
std::ptrdiff_t KeyType
Definition propertymap.hh:64
T ValueType
Definition propertymap.hh:62
LvaluePropertyMapTag Category
Definition propertymap.hh:65
std::ptrdiff_t KeyType
Definition propertymap.hh:74
const ValueType & Reference
Definition propertymap.hh:73
T ValueType
Definition propertymap.hh:72
LvaluePropertyMapTag Category
Definition propertymap.hh:75
Definition propertymap.hh:80
Adapter to turn a random access iterator into a property map.
Definition propertymap.hh:108
IndexMap::KeyType KeyType
The key type of the property map.
Definition propertymap.hh:125
R Reference
The reference type of the property map.
Definition propertymap.hh:135
T ValueType
The value type of the property map.
Definition propertymap.hh:130
Reference operator[](KeyType key) const
Access the a value by reference.
Definition propertymap.hh:160
IteratorPropertyMap(RandomAccessIterator iter, const IndexMap &im=IndexMap())
Constructor.
Definition propertymap.hh:149
IteratorPropertyMap()
Constructor.
Definition propertymap.hh:155
IM IndexMap
The type of the index map.
Definition propertymap.hh:120
RAI RandomAccessIterator
The type of the random access iterator.
Definition propertymap.hh:113
LvaluePropertyMapTag Category
The category of this property map.
Definition propertymap.hh:140
An adapter to turn an unique associative container into a property map.
Definition propertymap.hh:180
An adaptor to turn an unique associative container into a property map.
Definition propertymap.hh:238
A property map that applies the identity function to integers.
Definition propertymap.hh:293
std::size_t ValueType
The value type of the map.
Definition propertymap.hh:298
std::size_t KeyType
The key type of the map.
Definition propertymap.hh:295
ValueType operator[](const KeyType &key) const
Definition propertymap.hh:306
std::size_t Reference
The reference type of the map.
Definition propertymap.hh:301
ReadablePropertyMapTag Category
The category of the map.
Definition propertymap.hh:304
Selector for the property map type.
Definition propertymap.hh:320
T Tag
the tag identifying the property.
Definition propertymap.hh:324
C Container
The container type to whose entries the properties are attached.
Definition propertymap.hh:329