Loading...
Searching...
No Matches
propertymap.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_PROPERTYMAP_HH
#define DUNE_PROPERTYMAP_HH
#include <cstddef>
#include <iterator>
#include <type_traits>
namespace Dune
{
template<class PM>
struct PropertyMapTraits
{
typedef typename PM::KeyType KeyType;
typedef typename PM::ValueType ValueType;
typedef typename PM::Reference Reference;
typedef typename PM::Category Category;
};
struct ReadablePropertyMapTag
{};
struct WritablePropertyMapTag
{};
struct ReadWritePropertyMapTag
: public ReadablePropertyMapTag, public WritablePropertyMapTag
{};
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)
{
static_assert(std::is_convertible<typename PropertyMap::Category,WritablePropertyMapTag>::value,
"WritablePropertyMapTag required!");
static_cast<const PropertyMap&>(pmap)[key] = value;
}
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:
typedef RAI RandomAccessIterator;
typedef IM IndexMap;
typedef typename IndexMap::KeyType KeyType;
typedef T ValueType;
typedef R Reference;
typedef LvaluePropertyMapTag Category;
inline IteratorPropertyMap(RandomAccessIterator iter,
const IndexMap& im=IndexMap())
: iter_(iter), indexMap_(im)
{}
inline IteratorPropertyMap()
: iter_(), indexMap_()
{}
inline Reference operator[](KeyType key) const
{
return *(iter_ + get(indexMap_, key));
}
private:
RandomAccessIterator iter_;
IndexMap indexMap_;
};
template<typename T>
class AssociativePropertyMap
: RAPropertyMapHelper<typename T::value_type::second_type&,
AssociativePropertyMap<T> >
{
typedef T UniqueAssociativeContainer;
typedef typename UniqueAssociativeContainer::value_type::first_type
KeyType;
typedef typename UniqueAssociativeContainer::value_type::second_type
ValueType;
typedef ValueType& Reference;
typedef LvaluePropertyMapTag Category;
inline AssociativePropertyMap()
: map_(0)
{}
inline AssociativePropertyMap(UniqueAssociativeContainer& map)
: map_(&map)
{}
inline Reference operator[](KeyType key) const
{
return map_->find(key)->second;
}
private:
UniqueAssociativeContainer* map_;
};
template<typename T>
class ConstAssociativePropertyMap
: RAPropertyMapHelper<const typename T::value_type::second_type&,
ConstAssociativePropertyMap<T> >
{
typedef T UniqueAssociativeContainer;
typedef typename UniqueAssociativeContainer::value_type::first_type
KeyType;
typedef typename UniqueAssociativeContainer::value_type::second_type
ValueType;
typedef const ValueType& Reference;
typedef LvaluePropertyMapTag Category;
inline ConstAssociativePropertyMap()
: map_(0)
{}
inline ConstAssociativePropertyMap(const UniqueAssociativeContainer& map)
: map_(&map)
{}
inline Reference operator[](KeyType key) const
{
return map_->find(key)->second;
}
private:
const UniqueAssociativeContainer* map_;
};
struct IdentityMap
: public RAPropertyMapHelper<std::size_t, IdentityMap>
{
typedef std::size_t KeyType;
typedef std::size_t ValueType;
typedef std::size_t Reference;
typedef ReadablePropertyMapTag Category;
inline ValueType operator[](const KeyType& key) const
{
return key;
}
};
template<typename T, typename C>
struct PropertyMapTypeSelector
{
typedef T Tag;
typedef C Container;
};
}
#endif
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::put
void put(const RAPropertyMapHelper< Reference, PropertyMap > &pmap, const Key &key, const Value &value)
Definition propertymap.hh:92
Dune::get
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition integersequence.hh:22
Dune::PropertyMapTraits
Definition propertymap.hh:17
Dune::PropertyMapTraits::ValueType
PM::ValueType ValueType
The type of the values of the property map.
Definition propertymap.hh:25
Dune::PropertyMapTraits::Category
PM::Category Category
The category the property map belongs to.
Definition propertymap.hh:33
Dune::PropertyMapTraits::Reference
PM::Reference Reference
The type of the reference to the values.
Definition propertymap.hh:29
Dune::PropertyMapTraits::KeyType
PM::KeyType KeyType
The type of the key of the property map.
Definition propertymap.hh:21
Dune::ReadablePropertyMapTag
Tag for the category of readable property maps.
Definition propertymap.hh:38
Dune::WritablePropertyMapTag
Tag for the category of writable property maps.
Definition propertymap.hh:42
Dune::ReadWritePropertyMapTag
Tag for the category of readable and writable property maps.
Definition propertymap.hh:50
Dune::LvaluePropertyMapTag
Tag for the category of lvalue property maps.
Definition propertymap.hh:57
Dune::PropertyMapTraits< T * >::Reference
ValueType & Reference
Definition propertymap.hh:63
Dune::PropertyMapTraits< T * >::KeyType
std::ptrdiff_t KeyType
Definition propertymap.hh:64
Dune::PropertyMapTraits< T * >::ValueType
T ValueType
Definition propertymap.hh:62
Dune::PropertyMapTraits< T * >::Category
LvaluePropertyMapTag Category
Definition propertymap.hh:65
Dune::PropertyMapTraits< const T * >::KeyType
std::ptrdiff_t KeyType
Definition propertymap.hh:74
Dune::PropertyMapTraits< const T * >::Reference
const ValueType & Reference
Definition propertymap.hh:73
Dune::PropertyMapTraits< const T * >::ValueType
T ValueType
Definition propertymap.hh:72
Dune::PropertyMapTraits< const T * >::Category
LvaluePropertyMapTag Category
Definition propertymap.hh:75
Dune::RAPropertyMapHelper
Definition propertymap.hh:80
Dune::IteratorPropertyMap::KeyType
IndexMap::KeyType KeyType
The key type of the property map.
Definition propertymap.hh:125
Dune::IteratorPropertyMap::Reference
R Reference
The reference type of the property map.
Definition propertymap.hh:135
Dune::IteratorPropertyMap::ValueType
T ValueType
The value type of the property map.
Definition propertymap.hh:130
Dune::IteratorPropertyMap::operator[]
Reference operator[](KeyType key) const
Access the a value by reference.
Definition propertymap.hh:160
Dune::IteratorPropertyMap::IteratorPropertyMap
IteratorPropertyMap(RandomAccessIterator iter, const IndexMap &im=IndexMap())
Constructor.
Definition propertymap.hh:149
Dune::IteratorPropertyMap::IteratorPropertyMap
IteratorPropertyMap()
Constructor.
Definition propertymap.hh:155
Dune::IteratorPropertyMap::IndexMap
IM IndexMap
The type of the index map.
Definition propertymap.hh:120
Dune::IteratorPropertyMap::RandomAccessIterator
RAI RandomAccessIterator
The type of the random access iterator.
Definition propertymap.hh:113
Dune::IteratorPropertyMap::Category
LvaluePropertyMapTag Category
The category of this property map.
Definition propertymap.hh:140
Dune::IdentityMap
A property map that applies the identity function to integers.
Definition propertymap.hh:293
Dune::IdentityMap::ValueType
std::size_t ValueType
The value type of the map.
Definition propertymap.hh:298
Dune::IdentityMap::KeyType
std::size_t KeyType
The key type of the map.
Definition propertymap.hh:295
Dune::IdentityMap::operator[]
ValueType operator[](const KeyType &key) const
Definition propertymap.hh:306
Dune::IdentityMap::Reference
std::size_t Reference
The reference type of the map.
Definition propertymap.hh:301
Dune::IdentityMap::Category
ReadablePropertyMapTag Category
The category of the map.
Definition propertymap.hh:304
Dune::PropertyMapTypeSelector
Selector for the property map type.
Definition propertymap.hh:320
Dune::PropertyMapTypeSelector::Tag
T Tag
the tag identifying the property.
Definition propertymap.hh:324
Dune::PropertyMapTypeSelector::Container
C Container
The container type to whose entries the properties are attached.
Definition propertymap.hh:329