HashMap.hpp
Go to the documentation of this file.
1 
28 /*
29  * HashMap.hpp
30  *
31  * @date 27.07.2017
32  */
33 
34 #ifndef LVR2_ATTRMAPS_HASHMAP_H_
35 #define LVR2_ATTRMAPS_HASHMAP_H_
36 
37 #include <unordered_map>
38 
40 
41 using std::unordered_map;
42 
43 namespace lvr2
44 {
45 
46 template<typename HandleT, typename ValueT>
47 class HashMap : public AttributeMap<HandleT, ValueT>
48 {
49 public:
53  HashMap() {}
54 
69  HashMap(const ValueT& defaultValue);
70 
77  HashMap(size_t countElements, const ValueT& defaultValue);
78 
79  // =======================================================================
80  // Implemented methods from the interface (check interface for docs)
81  // =======================================================================
82  bool containsKey(HandleT key) const final;
83  boost::optional<ValueT> insert(HandleT key, const ValueT& value) final;
84  boost::optional<ValueT> erase(HandleT key) final;
85  void clear() final;
86  boost::optional<ValueT&> get(HandleT key) final;
87  boost::optional<const ValueT&> get(HandleT key) const final;
88  size_t numValues() const final;
89 
90  AttributeMapHandleIteratorPtr<HandleT> begin() const final;
91  AttributeMapHandleIteratorPtr<HandleT> end() const final;
92 
96  void reserve(size_t newCap);
97 
98 private:
99  unordered_map<HandleT, ValueT> m_map;
100  boost::optional<ValueT> m_default;
101 };
102 
103 template<typename HandleT, typename ValueT>
105 {
106 public:
107  HashMapIterator(typename unordered_map<HandleT, ValueT>::const_iterator iter);
108 
109  AttributeMapHandleIterator<HandleT>& operator++() final;
110  bool operator==(const AttributeMapHandleIterator<HandleT>& other) const final;
111  bool operator!=(const AttributeMapHandleIterator<HandleT>& other) const final;
112  HandleT operator*() const final;
113  std::unique_ptr<AttributeMapHandleIterator<HandleT>> clone() const final;
114 
115 private:
116  typename unordered_map<HandleT, ValueT>::const_iterator m_iter;
117 };
118 
119 } // namespace lvr2
120 
121 #include "lvr2/attrmaps/HashMap.tcc"
122 
123 #endif /* LVR2_ATTRMAPS_HASHMAP_H_ */
lvr2::HashMap::reserve
void reserve(size_t newCap)
Allocates space for at least newCap more elements.
lvr2::HashMap::m_default
boost::optional< ValueT > m_default
Definition: HashMap.hpp:100
lvr2::HashMap
Definition: HashMap.hpp:47
lvr2::HashMap::get
boost::optional< ValueT & > get(HandleT key) final
Returns the value associated with the given key or None if there is no associated value.
lvr2::AttributeMap
Interface for attribute maps.
Definition: AttributeMap.hpp:75
lvr2::HashMap::containsKey
bool containsKey(HandleT key) const final
Returns true iff the map contains a value associated with the given key.
lvr2::HashMap::erase
boost::optional< ValueT > erase(HandleT key) final
Removes the value associated with the given key.
lvr2::HashMap::clear
void clear() final
Removes all values from the map.
lvr2::AttributeMapHandleIterator
Iterator over keys of an attribute map.
Definition: AttributeMap.hpp:187
lvr2::HashMapIterator
Definition: HashMap.hpp:104
AttributeMap.hpp
lvr2::HashMap::begin
AttributeMapHandleIteratorPtr< HandleT > begin() const final
Returns an iterator over all keys of this map. The order of iteration is unspecified.
lvr2::HashMap::end
AttributeMapHandleIteratorPtr< HandleT > end() const final
Returns an iterator to the end of all keys.
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::HashMap::HashMap
HashMap()
Creates an empty map without default element set.
Definition: HashMap.hpp:53
lvr2::HashMap::insert
boost::optional< ValueT > insert(HandleT key, const ValueT &value) final
Inserts the given value at the given key position.
lvr2::HashMapIterator::m_iter
unordered_map< HandleT, ValueT >::const_iterator m_iter
Definition: HashMap.hpp:116
lvr2::HashMap::numValues
size_t numValues() const final
Returns the number of values in this map.
lvr2::AttributeMapHandleIteratorPtr
Simple convinience wrapper for unique_ptr<AttributeMapHandleIterator>
Definition: AttributeMap.hpp:46
lvr2::operator*
BaseVector< CoordType > operator*(const Eigen::Matrix< Scalar, 4, 4 > &mat, const BaseVector< CoordType > &normal)
Multiplication operator to support transformation with Eigen matrices. Rotates the normal,...
Definition: BaseVector.hpp:249
lvr2::HashMap::m_map
unordered_map< HandleT, ValueT > m_map
Definition: HashMap.hpp:99


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23