#include <HashMap.hpp>
Public Member Functions | |
AttributeMapHandleIteratorPtr< HandleT > | begin () const final |
Returns an iterator over all keys of this map. The order of iteration is unspecified. More... | |
void | clear () final |
Removes all values from the map. More... | |
bool | containsKey (HandleT key) const final |
Returns true iff the map contains a value associated with the given key. More... | |
AttributeMapHandleIteratorPtr< HandleT > | end () const final |
Returns an iterator to the end of all keys. More... | |
boost::optional< ValueT > | erase (HandleT key) final |
Removes the value associated with the given key. More... | |
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. More... | |
boost::optional< ValueT & > | get (HandleT key) final |
Returns the value associated with the given key or None if there is no associated value. More... | |
HashMap () | |
Creates an empty map without default element set. More... | |
HashMap (const ValueT &defaultValue) | |
Creates a map with a given default value. More... | |
HashMap (size_t countElements, const ValueT &defaultValue) | |
Creates a map with a given default value and calls reserve. More... | |
boost::optional< ValueT > | insert (HandleT key, const ValueT &value) final |
Inserts the given value at the given key position. More... | |
size_t | numValues () const final |
Returns the number of values in this map. More... | |
void | reserve (size_t newCap) |
Allocates space for at least newCap more elements. More... | |
Public Member Functions inherited from lvr2::AttributeMap< HandleT, ValueT > | |
ValueT & | operator[] (HandleT key) |
Returns the value associated with the given key or panics if there is no associated value. More... | |
const ValueT & | operator[] (HandleT key) const |
Returns the value associated with the given key or panics if there is no associated value. More... | |
Private Attributes | |
boost::optional< ValueT > | m_default |
unordered_map< HandleT, ValueT > | m_map |
Additional Inherited Members | |
Public Types inherited from lvr2::AttributeMap< HandleT, ValueT > | |
typedef HandleT | HandleType |
The type of the handle used as key in this map. More... | |
typedef ValueT | ValueType |
The type of the value stored in this map. More... | |
Definition at line 47 of file HashMap.hpp.
|
inline |
Creates an empty map without default element set.
Definition at line 53 of file HashMap.hpp.
lvr2::HashMap< HandleT, ValueT >::HashMap | ( | 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()
nor clear()
will do it. Calls to get()
will always return a non-none value and operator[]
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.
lvr2::HashMap< HandleT, ValueT >::HashMap | ( | size_t | countElements, |
const ValueT & | defaultValue | ||
) |
Creates a map with a given default value and calls reserve.
This works exactly as the HashMap(const Value&)
constructor, but also calls reserve(countElements)
immediately afterwards.
|
finalvirtual |
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:
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
Removes all values from the map.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
Returns true iff the map contains a value associated with the given key.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
Returns an iterator to the end of all keys.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
Removes the value associated with the given key.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
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.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
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.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
Inserts the given value at the given key position.
Implements lvr2::AttributeMap< HandleT, ValueT >.
|
finalvirtual |
Returns the number of values in this map.
Implements lvr2::AttributeMap< HandleT, ValueT >.
void lvr2::HashMap< HandleT, ValueT >::reserve | ( | size_t | newCap | ) |
Allocates space for at least newCap
more elements.
|
private |
Definition at line 100 of file HashMap.hpp.
|
private |
Definition at line 99 of file HashMap.hpp.