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 
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_ */
boost::optional< ValueT > insert(HandleT key, const ValueT &value) final
Inserts the given value at the given key position.
void reserve(size_t newCap)
Allocates space for at least newCap more elements.
A simple implementation of AttributeMap for a small number of values.
Definition: ListMap.hpp:65
Simple convinience wrapper for unique_ptr<AttributeMapHandleIterator>
Iterator over keys of an attribute map.
void clear() final
Removes all values from the map.
vector< pair< HandleT, ValueT > >::const_iterator keyIterator(HandleT key) const
vector< pair< HandleT, ValueT > > m_list
Definition: ListMap.hpp:117
Interface for attribute maps.
AttributeMapHandleIteratorPtr< HandleT > end() const final
Returns an iterator to the end of all keys.
size_t numValues() const final
Returns the number of values in this map.
bool containsKey(HandleT key) const final
Returns true iff the map contains a value associated with the given key.
boost::optional< ValueT > erase(HandleT key) final
Removes the value associated with the given key.
vector< pair< HandleT, ValueT > >::const_iterator m_iter
Definition: ListMap.hpp:140
boost::optional< ValueT > m_default
Definition: ListMap.hpp:118
AttributeMapHandleIteratorPtr< HandleT > begin() const final
Returns an iterator over all keys of this map. The order of iteration is unspecified.
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
ListMap()
Creates an empty map without default element set.
Definition: ListMap.hpp:71


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 Mon Feb 28 2022 22:46:08