UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
container_iterator.hpp
1
42#ifndef UFO_CONTAINER_TREE_CONTAINER_ITERATOR_HPP
43#define UFO_CONTAINER_TREE_CONTAINER_ITERATOR_HPP
44
45// STL
46#include <iterator>
47#include <type_traits>
48
49namespace ufo
50{
51// Forward declare
52template <class... Ts>
53class TreeContainer;
54
55template <class T, bool Const, class... Ts>
57{
58 private:
59 //
60 // Friends
61 //
62
63 friend class TreeContainterIterator<T, !Const, Ts...>;
64
65 friend class TreeContainer<Ts...>;
66
67 public:
68 //
69 // Tags
70 //
71
72 using iterator_category = std::random_access_iterator_tag;
73 using difference_type = std::ptrdiff_t;
74 using value_type = T;
75 using pointer = std::conditional_t<Const, T const*, T*>;
76 using reference = std::conditional_t<Const, T const&, T&>;
77
78 TreeContainterIterator() = default;
79
81
82 template <bool Const2, class = std::enable_if_t<Const && !Const2>>
84 : container_(other.container_), idx_(other.idx_)
85 {
86 }
87
88 TreeContainterIterator& operator++()
89 {
90 ++idx_;
91 return *this;
92 }
93
94 TreeContainterIterator& operator--()
95 {
96 --idx_;
97 return *this;
98 }
99
100 TreeContainterIterator operator++(int)
101 {
102 TreeContainterIterator tmp(*this);
103 ++*this;
104 return tmp;
105 }
106
107 TreeContainterIterator operator--(int)
108 {
109 TreeContainterIterator tmp(*this);
110 --*this;
111 return tmp;
112 }
113
114 TreeContainterIterator& operator+=(difference_type n)
115 {
116 idx_ += n;
117 return *this;
118 }
119
120 TreeContainterIterator& operator-=(difference_type n)
121 {
122 idx_ -= n;
123 return *this;
124 }
125
126 TreeContainterIterator operator+(difference_type n)
127 {
128 TreeContainterIterator tmp(*this);
129 tmp += n;
130 return tmp;
131 }
132
133 TreeContainterIterator operator-(difference_type n)
134 {
135 TreeContainterIterator tmp(*this);
136 tmp -= n;
137 return tmp;
138 }
139
140 reference operator[](difference_type pos) const
141 {
142 return container_->template get<T>(idx_ + pos);
143 }
144
145 reference operator*() const { return container_->template get<T>(idx_); }
146
147 pointer operator->() const { return &(container_->template get<T>(idx_)); }
148
149 template <bool Const1, bool Const2>
150 friend difference_type operator-(TreeContainterIterator<T, Const1, Ts...> const& lhs,
152 {
153 return lhs.idx_ - rhs.idx_;
154 }
155
156 template <bool Const1, bool Const2>
157 friend bool operator==(TreeContainterIterator<T, Const1, Ts...> const& lhs,
159 {
160 return lhs.idx_ == rhs.idx_;
161 }
162
163 template <bool Const1, bool Const2>
164 friend bool operator!=(TreeContainterIterator<T, Const1, Ts...> const& lhs,
166 {
167 return lhs.idx_ != rhs.idx_;
168 }
169
170 template <bool Const1, bool Const2>
171 friend bool operator<(TreeContainterIterator<T, Const1, Ts...> const& lhs,
173 {
174 return lhs.idx_ < rhs.idx_;
175 }
176
177 template <bool Const1, bool Const2>
178 friend bool operator<=(TreeContainterIterator<T, Const1, Ts...> const& lhs,
180 {
181 return lhs.idx_ <= rhs.idx_;
182 }
183
184 template <bool Const1, bool Const2>
185 friend bool operator>(TreeContainterIterator<T, Const1, Ts...> const& lhs,
187 {
188 return lhs.idx_ > rhs.idx_;
189 }
190
191 template <bool Const1, bool Const2>
192 friend bool operator>=(TreeContainterIterator<T, Const1, Ts...> const& lhs,
194 {
195 return lhs.idx_ >= rhs.idx_;
196 }
197
198 protected:
199 TreeContainterIterator(TreeContainer<Ts...>* container, difference_type idx)
200 : container_(container), idx_(idx)
201 {
202 }
203
204 TreeContainterIterator(TreeContainer<Ts...>& container, difference_type idx)
205 : TreeContainterIterator(&container, idx)
206 {
207 }
208
209 private:
210 TreeContainer<Ts...>* container_ = nullptr;
211
212 difference_type idx_;
213};
214} // namespace ufo
215
216#endif // UFO_CONTAINER_TREE_CONTAINER_ITERATOR_HPP
All vision-related classes and functions.
Definition cloud.hpp:49