Template Class VectorMap
Defined in File VectorMap.hpp
Inheritance Relationships
Base Type
public lvr2::AttributeMap< HandleT, ValueT >(Template Class AttributeMap)
Class Documentation
-
template<typename HandleT, typename ValueT>
class VectorMap : public lvr2::AttributeMap<HandleT, ValueT> A map with constant lookup overhead using small-ish integer-keys.
It stores the given values in a vector, they key is simply the index within the vector. This means that the space requirement is O(largest_key). See StableVector for more information.
Public Functions
-
inline VectorMap()
Creates an empty map without default element set.
-
VectorMap(const ValueT &defaultValue)
Creates a map with a given default value.
Whenever you request a value for a key and there isn’t a value associated with that key, the default value is returned. Note that if you set a default value (which you do by calling this constructor), you can’t remove it. Neither
erase()norclear()will do it. Calls toget()will always return a non-none value andoperator[]won’t ever panic.One additional important detail: if you call
get()to obtain a mutable reference, the default value is inserted into the map. This is the only sane way to return a mutably reference.
-
VectorMap(size_t countElements, const ValueT &defaultValue)
Creates a map with a given default value and calls reserve.
This works exactly as the
VectorMap(const Value&)constructor, but also callsreserve(countElements)immediately afterwards.
-
virtual bool containsKey(HandleT key) const final
Returns true iff the map contains a value associated with the given key.
-
virtual boost::optional<ValueT> insert(HandleT key, const ValueT &value) final
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) final
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() final
Removes all values from the map.
-
virtual boost::optional<ValueT&> get(HandleT key) final
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 final
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 final
Returns the number of values in this map.
-
virtual AttributeMapHandleIteratorPtr<HandleT> begin() const final
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 final
Returns an iterator to the end of all keys.
-
void reserve(size_t newCap)
See also
-
inline VectorMap()