VectorMap.hpp
Go to the documentation of this file.
1 
28 /*
29  * VectorMap.hpp
30  *
31  * @date 08.06.2017
32  * @author Johan M. von Behren <johan@vonbehren.eu>
33  */
34 
35 #ifndef LVR2_ATTRMAPS_VECTORMAP_H_
36 #define LVR2_ATTRMAPS_VECTORMAP_H_
37 
38 #include <vector>
39 #include <boost/optional.hpp>
40 
44 #include "lvr2/util/Cluster.hpp"
45 
46 using std::vector;
47 
48 
49 namespace lvr2
50 {
51 
59 template<typename HandleT, typename ValueT>
60 class VectorMap : public AttributeMap<HandleT, ValueT>
61 {
62 public:
66  VectorMap() {}
67 
82  VectorMap(const ValueT& defaultValue);
83 
90  VectorMap(size_t countElements, const ValueT& defaultValue);
91 
92  VectorMap(size_t countElements, const boost::shared_array<ValueT>& values);
93 
94  // =======================================================================
95  // Implemented methods from the interface (check interface for docs)
96  // =======================================================================
97  bool containsKey(HandleT key) const final;
98  boost::optional<ValueT> insert(HandleT key, const ValueT& value) final;
99  boost::optional<ValueT> erase(HandleT key) final;
100  void clear() final;
101  boost::optional<ValueT&> get(HandleT key) final;
102  boost::optional<const ValueT&> get(HandleT key) const final;
103  size_t numValues() const final;
104 
105  AttributeMapHandleIteratorPtr<HandleT> begin() const final;
106  AttributeMapHandleIteratorPtr<HandleT> end() const final;
107 
108 
112  void reserve(size_t newCap);
113 
114 private:
116  StableVector<HandleT, ValueT> m_vec;
117  boost::optional<ValueT> m_default;
118 };
119 
120 template<typename HandleT, typename ValueT>
122 {
123  static_assert(
124  std::is_base_of<BaseHandle<Index>, HandleT>::value,
125  "HandleT must inherit from BaseHandle!"
126  );
127 
128 public:
130 
131  AttributeMapHandleIterator<HandleT>& operator++() final;
132  bool operator==(const AttributeMapHandleIterator<HandleT>& other) const final;
133  bool operator!=(const AttributeMapHandleIterator<HandleT>& other) const final;
134  HandleT operator*() const final;
135  std::unique_ptr<AttributeMapHandleIterator<HandleT>> clone() const final;
136 
137 private:
139 };
140 
141 } // namespace lvr2
142 
143 #include "lvr2/attrmaps/VectorMap.tcc"
144 
145 #endif /* LVR2_ATTRMAPS_VECTORMAP_H_ */
Handles.hpp
lvr2::VectorMap::erase
boost::optional< ValueT > erase(HandleT key) final
Removes the value associated with the given key.
lvr2::StableVectorIterator< HandleT, ValueT >
lvr2::VectorMap::numValues
size_t numValues() const final
Returns the number of values in this map.
lvr2::AttributeMap
Interface for attribute maps.
Definition: AttributeMap.hpp:75
lvr2::BaseHandle< Index >
Cluster.hpp
lvr2::VectorMap::containsKey
bool containsKey(HandleT key) const final
Returns true iff the map contains a value associated with the given key.
lvr2::VectorMap::end
AttributeMapHandleIteratorPtr< HandleT > end() const final
Returns an iterator to the end of all keys.
lvr2::VectorMap::m_vec
StableVector< HandleT, ValueT > m_vec
The underlying storage.
Definition: VectorMap.hpp:116
lvr2::VectorMapIterator::m_iter
StableVectorIterator< HandleT, ValueT > m_iter
Definition: VectorMap.hpp:138
lvr2::VectorMap
A map with constant lookup overhead using small-ish integer-keys.
Definition: VectorMap.hpp:60
lvr2::VectorMap::m_default
boost::optional< ValueT > m_default
Definition: VectorMap.hpp:117
lvr2::AttributeMapHandleIterator
Iterator over keys of an attribute map.
Definition: AttributeMap.hpp:187
lvr2::StableVector
A vector which guarantees stable indices and features O(1) deletion.
Definition: StableVector.hpp:104
lvr2::VectorMap::VectorMap
VectorMap()
Creates an empty map without default element set.
Definition: VectorMap.hpp:66
lvr2::VectorMap::begin
AttributeMapHandleIteratorPtr< HandleT > begin() const final
Returns an iterator over all keys of this map. The order of iteration is unspecified.
StableVector.hpp
scripts.create_png.values
values
Definition: create_png.py:26
AttributeMap.hpp
lvr2::VectorMap::clear
void clear() final
Removes all values from the map.
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::VectorMap::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::VectorMap::insert
boost::optional< ValueT > insert(HandleT key, const ValueT &value) final
Inserts the given value at the given key position.
lvr2::VectorMap::reserve
void reserve(size_t newCap)
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::VectorMapIterator
Definition: VectorMap.hpp:121


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:25