/usr/include/dune/common/propertymap.hh is in libdune-common-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | // $Id: propertymap.hh 6003 2010-05-14 09:12:39Z sander $
#ifndef DUNE_PROPERTYMAP_HH
#define DUNE_PROPERTYMAP_HH
#include <cstddef>
#include <iterator>
#include"static_assert.hh"
#include"typetraits.hh"
namespace Dune
{
template<class PM>
struct PropertyMapTraits
{
/**
* @brief The type of the key of the property map.
*/
typedef typename PM::KeyType KeyType;
/**
* @brief The type of the values of the property map.
*/
typedef typename PM::ValueType ValueType;
/**
* @brief The type of the reference to the values.
*/
typedef typename PM::Reference Reference;
/**
* @brief The category the property map belongs to.
*/
typedef typename PM::Category Category;
};
/** @brief Tag for the category of readable property maps. */
struct ReadablePropertyMapTag
{};
/** @brief Tag for the category of writable property maps. */
struct WritablePropertyMapTag
{};
/**
* @brief Tag for the category of readable and writable property
* maps.
*/
struct ReadWritePropertyMapTag
: public ReadablePropertyMapTag, public WritablePropertyMapTag
{};
/**
* @brief Tag for the category of lvalue property maps.
*/
struct LvaluePropertyMapTag
: public ReadWritePropertyMapTag
{};
template<class T>
struct PropertyMapTraits<T*>
{
typedef T ValueType;
typedef ValueType& Reference;
typedef std::ptrdiff_t KeyType;
typedef LvaluePropertyMapTag Category;
};
template<class T>
struct PropertyMapTraits<const T*>
{
typedef T ValueType;
typedef const ValueType& Reference;
typedef std::ptrdiff_t KeyType;
typedef LvaluePropertyMapTag Category;
};
template<class Reference, class PropertyMap>
struct RAPropertyMapHelper
{};
template<class Reference, class PropertyMap, class Key>
inline Reference
get(const RAPropertyMapHelper<Reference,PropertyMap>& pmap,
const Key& key)
{
return static_cast<const PropertyMap&>(pmap)[key];
}
template<class Reference, class PropertyMap, class Key, class Value>
inline void
put(const RAPropertyMapHelper<Reference,PropertyMap>& pmap,
const Key& key, const Value& value)
{
dune_static_assert((Conversion<typename PropertyMap::Category,WritablePropertyMapTag>
::exists), "WritablePropertyMapTag required!");
static_cast<const PropertyMap&>(pmap)[key] = value;
}
/**
* @brief Adapter to turn a random access iterator into a property map.
*/
template<class RAI, class IM,
class T = typename std::iterator_traits<RAI>::value_type,
class R = typename std::iterator_traits<RAI>::reference>
class IteratorPropertyMap
: public RAPropertyMapHelper<R,IteratorPropertyMap<RAI,IM,T,R> >
{
public:
/**
* @brief The type of the random access iterator.
*/
typedef RAI RandomAccessIterator;
/**
* @brief The type of the index map.
*
* This will convert the KeyType to std::ptrdiff_t via operator[]().
*/
typedef IM IndexMap;
/**
* @brief The key type of the property map.
*/
typedef typename IndexMap::KeyType KeyType;
/**
* @brief The value type of the property map.
*/
typedef T ValueType;
/**
* @brief The reference type of the property map.
*/
typedef R Reference;
/**
* @brief The category of this property map.
*/
typedef LvaluePropertyMapTag Category;
/**
* @brief Constructor.
* @param iter The random access iterator that
* provides the mapping.
* @param im The index map that maps the KeyType
* to the difference_type of the iterator.
*/
inline IteratorPropertyMap(RandomAccessIterator iter,
const IndexMap& im=IndexMap())
:iter_(iter), indexMap_(im)
{}
/** @brief Constructor. */
inline IteratorPropertyMap()
: iter_(), indexMap_()
{}
/** @brief Access the a value by reference. */
inline Reference operator[](KeyType key) const
{
return *(iter_ + get(indexMap_, key));
}
private:
/** @brief The underlying iterator. */
RandomAccessIterator iter_;
/** @brief The index map to use for the lookup. */
IndexMap indexMap_;
};
/**
* @brief An adapter to turn an unique associative container
* into a property map.
*/
template<typename T>
class AssociativePropertyMap
: RAPropertyMapHelper<typename T::value_type::second_type&,
AssociativePropertyMap<T> >
{
/**
* @brief The type of the unique associative container.
*/
typedef T UniqueAssociativeContainer;
/**
* @brief The key type of the property map.
*/
typedef typename UniqueAssociativeContainer::value_type::first_type
KeyType;
/**
* @brief The value type of the property map.
*/
typedef typename UniqueAssociativeContainer::value_type::second_type
ValueType;
/**
* @brief The reference type of the property map.
*/
typedef ValueType& Reference;
/**
* @brief The category of the property map.
*/
typedef LvaluePropertyMapTag Category;
/** @brief Constructor */
inline AssociativePropertyMap()
: map_(0)
{}
/** @brief Constructor. */
inline AssociativePropertyMap(UniqueAssociativeContainer& map)
: map_(&map)
{}
/**
* @brief Access a property.
* @param key The key of the property.
*/
inline Reference operator[](KeyType key)const
{
return map_->find(key)->second;
}
private:
UniqueAssociativeContainer* map_;
};
/**
* @brief An adaptor to turn an unique associative container
* into a property map.
*/
template<typename T>
class ConstAssociativePropertyMap
: RAPropertyMapHelper<const typename T::value_type::second_type&,
ConstAssociativePropertyMap<T> >
{
/**
* @brief The type of the unique associative container.
*/
typedef T UniqueAssociativeContainer;
/**
* @brief The key type of the property map.
*/
typedef typename UniqueAssociativeContainer::value_type::first_type
KeyType;
/**
* @brief The value type of the property map.
*/
typedef typename UniqueAssociativeContainer::value_type::second_type
ValueType;
/**
* @brief The reference type of the property map.
*/
typedef const ValueType& Reference;
/**
* @brief The category of the property map.
*/
typedef LvaluePropertyMapTag Category;
/** @brief Constructor */
inline ConstAssociativePropertyMap()
: map_(0)
{}
/** @brief Constructor. */
inline ConstAssociativePropertyMap(const UniqueAssociativeContainer& map)
: map_(&map)
{}
/**
* @brief Access a property.
* @param key The key of the property.
*/
inline Reference operator[](KeyType key)const
{
return map_->find(key)->second;
}
private:
const UniqueAssociativeContainer* map_;
};
/**
* @brief A property map that applies the identity function to integers.
*/
struct IdentityMap
: public RAPropertyMapHelper<std::size_t, IdentityMap>
{
/** @brief The key type of the map. */
typedef std::size_t KeyType;
/** @brief The value type of the map. */
typedef std::size_t ValueType;
/** @brief The reference type of the map. */
typedef std::size_t Reference;
/** @brief The category of the map. */
typedef ReadablePropertyMapTag Category;
inline ValueType operator[](const KeyType& key) const
{
return key;
}
};
/**
* @brief Selector for the property map type.
*
* If present the type of the property map is accessible via the typedef Type.
*/
template<typename T, typename C>
struct PropertyMapTypeSelector
{
/**
* @brief the tag identifying the property.
*/
typedef T Tag;
/**
* @brief The container type to whose entries the properties
* are attached.
*/
typedef C Container;
};
}
#endif
|