Template Class AttributeMap

Inheritance Relationships

Derived Types

Class Documentation

template<typename HandleT, typename ValueT>
class AttributeMap

Interface for attribute maps.

Attribute maps are associative containers which map from a handle to a value. A simple and obvious implementation of this interface is a hash map.

Attribute maps are used a lot in this library and are widely useful. A good example is an algorithm that needs to visit every face by traversing a mesh, but has to make sure to visit every face only once. In that algorithm, the best idea is to use an attribute map which maps from face to bool. This means that we associate a boolean value with each face. This boolean value can be used to store whether or not we already visited that face. Such a map would have the form AttributeMap<FaceHandle, bool>.

Attribute maps are also used to store non-temporary data, like face-normals, vertex-colors, and much more. It’s pretty simple, really: if you want to associate a value of type T with a, say, vertex, simply create an AttributeMap<VertexHandle, T>.

There are different implementations of this interface. The most important ones have a type alias in AttrMaps.hpp. Please read the documentation in that file to learn more about different implementations.

Template Parameters:
  • HandleT – Key type of this map. Has to inherit from BaseHandle!

  • ValueT – The type to map to.

Subclassed by lvr2::HashMap< pmp::Face, std::pair< float, float > >, lvr2::HashMap< pmp::Vertex, double >, lvr2::VectorMap< HandleT, lvr2::ClusterHandle >, lvr2::VectorMap< lvr2::Material >, lvr2::HashMap< HandleT, ValueT >, lvr2::ListMap< HandleT, ValueT >, lvr2::VectorMap< HandleT, ValueT >

Public Types

typedef HandleT HandleType

The type of the handle used as key in this map.

typedef ValueT ValueType

The type of the value stored in this map.

Public Functions

virtual bool containsKey(HandleT key) const = 0

Returns true iff the map contains a value associated with the given key.

virtual boost::optional<ValueT> insert(HandleT key, const ValueT &value) = 0

Inserts the given value at the given key position.

Returns:

If there was a value associated with the given key before inserting the new value, the old value is returned. None otherwise.

virtual boost::optional<ValueT> erase(HandleT key) = 0

Removes the value associated with the given key.

Returns:

If there was a value associated with the key, it is returned. None otherwise.

virtual void clear() = 0

Removes all values from the map.

virtual boost::optional<ValueT&> get(HandleT key) = 0

Returns the value associated with the given key or None if there is no associated value.

Note: this method can not be used to insert a new value. It only allows reading and modifying an already inserted value.

virtual boost::optional<const ValueT&> get(HandleT key) const = 0

Returns the value associated with the given key or None if there is no associated value.

Note: this method can not be used to insert a new value. It only allows reading an already inserted value.

virtual size_t numValues() const = 0

Returns the number of values in this map.

virtual AttributeMapHandleIteratorPtr<HandleT> begin() const = 0

Returns an iterator over all keys of this map. The order of iteration is unspecified.

You can simply iterate over all keys of this map with a range-based for-loop:

for (auto handle: attributeMap) { ... }
virtual AttributeMapHandleIteratorPtr<HandleT> end() const = 0

Returns an iterator to the end of all keys.

ValueT &operator[](HandleT key)

Returns the value associated with the given key or panics if there is no associated value.

Note: since this method panics, if there is no associated value, it cannot be used to insert new values. Use insert() if you want to insert new values.

const ValueT &operator[](HandleT key) const

Returns the value associated with the given key or panics if there is no associated value.

Note: since this method panics, if there is no associated value, it cannot be used to insert new values. Use insert() if you want to insert new values.