ListMap.hpp
Go to the documentation of this file.
1 
28 /*
29  * ListMap.hpp
30  *
31  * @date 27.07.2017
32  */
33 
34 #ifndef LVR2_ATTRMAPS_LISTMAP_H_
35 #define LVR2_ATTRMAPS_LISTMAP_H_
36 
37 #include <utility>
38 #include <vector>
39 
41 
42 using std::vector;
43 using std::pair;
44 
45 namespace lvr2
46 {
47 
48 
64 template<typename HandleT, typename ValueT>
65 class ListMap : public AttributeMap<HandleT, ValueT>
66 {
67 public:
71  ListMap() {}
72 
87  ListMap(const ValueT& defaultValue);
88 
95  ListMap(size_t countElements, const ValueT& defaultValue);
96 
97  // =======================================================================
98  // Implemented methods from the interface (check interface for docs)
99  // =======================================================================
100  bool containsKey(HandleT key) const final;
101  boost::optional<ValueT> insert(HandleT key, const ValueT& value) final;
102  boost::optional<ValueT> erase(HandleT key) final;
103  void clear() final;
104  boost::optional<ValueT&> get(HandleT key) final;
105  boost::optional<const ValueT&> get(HandleT key) const final;
106  size_t numValues() const final;
107 
108  AttributeMapHandleIteratorPtr<HandleT> begin() const final;
109  AttributeMapHandleIteratorPtr<HandleT> end() const final;
110 
114  void reserve(size_t newCap);
115 
116 private:
117  vector<pair<HandleT, ValueT>> m_list;
118  boost::optional<ValueT> m_default;
119 
120  // Internal helper method
121  typename vector<pair<HandleT, ValueT>>::const_iterator keyIterator(HandleT key) const;
122  typename vector<pair<HandleT, ValueT>>::iterator keyIterator(HandleT key);
123 
124  template<typename, typename> friend class ListMap;
125 };
126 
127 template<typename HandleT, typename ValueT>
129 {
130 public:
131  ListMapIterator(typename vector<pair<HandleT, ValueT>>::const_iterator iter);
132 
133  AttributeMapHandleIterator<HandleT>& operator++() final;
134  bool operator==(const AttributeMapHandleIterator<HandleT>& other) const final;
135  bool operator!=(const AttributeMapHandleIterator<HandleT>& other) const final;
136  HandleT operator*() const final;
137  std::unique_ptr<AttributeMapHandleIterator<HandleT>> clone() const final;
138 
139 private:
140  typename vector<pair<HandleT, ValueT>>::const_iterator m_iter;
141 };
142 
143 } // namespace lvr2
144 
145 #include "lvr2/attrmaps/ListMap.tcc"
146 
147 #endif /* LVR2_ATTRMAPS_LISTMAP_H_ */
lvr2::ListMap::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::ListMap::reserve
void reserve(size_t newCap)
Allocates space for at least newCap more elements.
lvr2::ListMap::begin
AttributeMapHandleIteratorPtr< HandleT > begin() const final
Returns an iterator over all keys of this map. The order of iteration is unspecified.
lvr2::AttributeMap
Interface for attribute maps.
Definition: AttributeMap.hpp:75
lvr2::ListMap::ListMap
friend class ListMap
Definition: ListMap.hpp:124
lvr2::ListMap::erase
boost::optional< ValueT > erase(HandleT key) final
Removes the value associated with the given key.
lvr2::ListMapIterator
Definition: ListMap.hpp:128
lvr2::ListMap
A simple implementation of AttributeMap for a small number of values.
Definition: ListMap.hpp:65
lvr2::ListMap::insert
boost::optional< ValueT > insert(HandleT key, const ValueT &value) final
Inserts the given value at the given key position.
lvr2::ListMap::clear
void clear() final
Removes all values from the map.
lvr2::AttributeMapHandleIterator
Iterator over keys of an attribute map.
Definition: AttributeMap.hpp:187
lvr2::ListMap::numValues
size_t numValues() const final
Returns the number of values in this map.
lvr2::ListMap::ListMap
ListMap()
Creates an empty map without default element set.
Definition: ListMap.hpp:71
lvr2::ListMap::m_list
vector< pair< HandleT, ValueT > > m_list
Definition: ListMap.hpp:117
lvr2::ListMap::end
AttributeMapHandleIteratorPtr< HandleT > end() const final
Returns an iterator to the end of all keys.
AttributeMap.hpp
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ListMap::containsKey
bool containsKey(HandleT key) const final
Returns true iff the map contains a value associated with the given key.
lvr2::ListMap::m_default
boost::optional< ValueT > m_default
Definition: ListMap.hpp:118
lvr2::ListMap::keyIterator
vector< pair< HandleT, ValueT > >::const_iterator keyIterator(HandleT key) const
lvr2::ListMapIterator::m_iter
vector< pair< HandleT, ValueT > >::const_iterator m_iter
Definition: ListMap.hpp:140
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
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:24