Project
Loading...
Searching...
No Matches
iterator.h
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef RANS_INTERNAL_TRANSFORM_ITERATOR_H_
17#define RANS_INTERNAL_TRANSFORM_ITERATOR_H_
18
19#include <cstddef>
20#include <cassert>
21#include <cstdint>
22#include <type_traits>
23#include <iostream>
24#include <iterator>
25
26#include <fairlogger/Logger.h>
27
28namespace o2::rans
29{
30
31namespace internal
32{
33
34template <typename IT, typename tag_T>
35struct hasIteratorTag : public std::bool_constant<std::is_same_v<typename std::iterator_traits<IT>::iterator_category, tag_T>> {
36};
37template <typename IT>
39template <typename IT>
41
42template <typename iterA_T, typename iterB_T>
43inline constexpr bool areBothRandomAccessIterators_v = std::bool_constant<isRandomAccessIterator_v<iterA_T> && isRandomAccessIterator_v<iterB_T>>::value;
44
45template <typename iterA_T, typename iterB_T>
47};
48
49template <>
50struct getIteratorTag<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag> {
51 using value_type = std::bidirectional_iterator_tag;
52};
53
54template <>
55struct getIteratorTag<std::bidirectional_iterator_tag, std::random_access_iterator_tag> {
56 using value_type = std::bidirectional_iterator_tag;
57};
58
59template <>
60struct getIteratorTag<std::random_access_iterator_tag, std::bidirectional_iterator_tag> {
61 using value_type = std::bidirectional_iterator_tag;
62};
63
64template <>
65struct getIteratorTag<std::random_access_iterator_tag, std::random_access_iterator_tag> {
66 using value_type = std::random_access_iterator_tag;
67};
68
69template <typename iterA_T, typename iterB_T>
71
72} // namespace internal
73
74template <class iterA_T, class iterB_T, class F>
76{
77 public:
78 using difference_type = std::ptrdiff_t;
79 using value_type = std::invoke_result_t<F, iterA_T, iterB_T>;
82 using iterator_category = internal::getIteratorTag_t<typename std::iterator_traits<iterA_T>::iterator_category, typename std::iterator_traits<iterB_T>::iterator_category>;
83
85 CombinedInputIterator(iterA_T iterA, iterB_T iterB, F functor);
91
92 // pointer arithmetics
97
98 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
100
101 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
103
104 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
106
107 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
109
110 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
112
113 // comparison
114 bool operator==(const CombinedInputIterator& other) const;
115 bool operator!=(const CombinedInputIterator& other) const;
116
117 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
118 bool operator<(const CombinedInputIterator& other) const;
119
120 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
121 bool operator>(const CombinedInputIterator& other) const;
122
123 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
124 bool operator>=(const CombinedInputIterator& other) const;
125
126 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
127 bool operator<=(const CombinedInputIterator& other) const;
128
129 // dereference
130 auto operator*() const;
131
132 template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool> = true>
134
135 private:
136 iterA_T mIterA{};
137 iterB_T mIterB{};
138 F mFunctor{};
139
140 public:
141 friend std::ostream& operator<<(std::ostream& o, const CombinedInputIterator& iter)
142 {
143 o << "CombinedInputIterator{iterA: " << &(iter.mIterA) << ", iterB: " << &(iter.mIterB) << "}";
144 return o;
145 }
146
151};
152
153template <class input_T, class iterA_T, class iterB_T, class F>
155{
156
157 class Proxy
158 {
159 public:
160 Proxy(CombinedOutputIterator& iter);
161
162 Proxy& operator=(input_T value);
163
164 private:
165 CombinedOutputIterator* mIter{};
166 };
167
168 public:
169 using difference_type = std::ptrdiff_t;
170 using value_type = input_T;
173 using iterator_category = std::input_iterator_tag;
174
175 CombinedOutputIterator(iterA_T iterA, iterB_T iterB, F functor);
181
182 // pointer arithmetics
185
186 // dereference
187 Proxy& operator*();
188
189 private:
190 iterA_T mIterA{};
191 iterB_T mIterB{};
192 F mFunctor{};
193 Proxy mProxy{*this};
194
195 public:
196 friend std::ostream& operator<<(std::ostream& o, const CombinedOutputIterator& iter)
197 {
198 o << "CombinedOutputIterator{iterA: " << &(iter.mIterA) << ", iterB: " << &(iter.mIterB) << "}";
199 return o;
200 }
201};
202
203template <typename input_T>
205
206 template <class iterA_T, class iterB_T, class F>
207 static inline auto makeIter(iterA_T iterA, iterB_T iterB, F functor) -> CombinedOutputIterator<input_T, iterA_T, iterB_T, F>
208 {
209 return {iterA, iterB, functor};
210 }
211};
212
213template <class iterA_T, class iterB_T, class F>
214CombinedInputIterator<iterA_T, iterB_T, F>::CombinedInputIterator(iterA_T iterA, iterB_T iterB, F functor) : mIterA{iterA}, mIterB{iterB}, mFunctor{functor}
215{
216}
217
218template <class iterA_T, class iterB_T, class F>
220{
221 mIterA = other.mIterA;
222 mIterB = other.mIterB;
223 return *this;
224}
225
226template <class iterA_T, class iterB_T, class F>
228{
229 ++mIterA;
230 ++mIterB;
231 return *this;
232}
233
234template <class iterA_T, class iterB_T, class F>
236{
237 auto res = *this;
238 ++(*this);
239 return res;
240}
241
242template <class iterA_T, class iterB_T, class F>
244{
245 --mIterA;
246 --mIterB;
247 return *this;
248}
249
250template <class iterA_T, class iterB_T, class F>
252{
253 auto res = *this;
254 --(*this);
255 return res;
256}
257
258template <class iterA_T, class iterB_T, class F>
259template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
261{
262 mIterA += i;
263 mIterB += i;
264 return *this;
265}
266
267template <class iterA_T, class iterB_T, class F>
268template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
270{
271 auto tmp = *const_cast<CombinedInputIterator*>(this);
272 return tmp += i;
273}
274
275template <class iterA_T, class iterB_T, class F>
276template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
278{
279 mIterA -= i;
280 mIterB -= i;
281 return *this;
282}
283
284template <class iterA_T, class iterB_T, class F>
285template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
287{
288 auto tmp = *const_cast<CombinedInputIterator*>(this);
289 return tmp -= i;
290}
291
292template <class iterA_T, class iterB_T, class F>
293template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
295{
296 return this->mIterA - other.mIterA;
297}
298
299template <class iterA_T, class iterB_T, class F>
301{
302 return (mIterA == other.mIterA) && (mIterB == other.mIterB);
303}
304
305template <class iterA_T, class iterB_T, class F>
307{
308 return !(*this == other);
309}
310
311template <class iterA_T, class iterB_T, class F>
312template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
314{
315 return other - *this > 0;
316}
317
318template <class iterA_T, class iterB_T, class F>
319template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
321{
322 return other < *this;
323}
324
325template <class iterA_T, class iterB_T, class F>
326template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
328{
329 return !(*this < other);
330}
331
332template <class iterA_T, class iterB_T, class F>
333template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
335{
336 return !(*this > other);
337}
338
339template <class iterA_T, class iterB_T, class F>
341{
342 return mFunctor(mIterA, mIterB);
343}
344
345template <class iterA_T, class iterB_T, class F>
346template <std::enable_if_t<internal::areBothRandomAccessIterators_v<iterA_T, iterB_T>, bool>>
348{
349 return *(*this + i);
350}
351
352template <typename input_T, class iterA_T, class iterB_T, class F>
353CombinedOutputIterator<input_T, iterA_T, iterB_T, F>::CombinedOutputIterator(iterA_T iterA, iterB_T iterB, F functor) : mIterA{iterA},
354 mIterB{iterB},
355 mFunctor{functor}
356{
357}
358
359template <typename input_T, class iterA_T, class iterB_T, class F>
361{
362 mIterA = other.mIterA;
363 mIterB = other.mIterB;
364 return *this;
365}
366
367template <typename input_T, class iterA_T, class iterB_T, class F>
369{
370 ++mIterA;
371 ++mIterB;
372 return *this;
373}
374
375template <typename input_T, class iterA_T, class iterB_T, class F>
377{
378 auto res = *this;
379 ++(*this);
380 return res;
381}
382
383template <typename input_T, class iterA_T, class iterB_T, class F>
385{
386 mProxy = {*this};
387 return mProxy;
388}
389
390template <typename input_T, class iterA_T, class iterB_T, class F>
392{
393}
394
395template <typename input_T, class iterA_T, class iterB_T, class F>
396inline auto CombinedOutputIterator<input_T, iterA_T, iterB_T, F>::Proxy::operator=(input_T value) -> Proxy&
397{
398 mIter->mFunctor(mIter->mIterA, mIter->mIterB, value);
399 return *this;
400}
401
402} // namespace o2::rans
403
404#endif /* RANS_INTERNAL_TRANSFORM_ITERATOR_H_ */
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h internal
uint32_t res
Definition RawData.h:0
bool operator==(const CombinedInputIterator &other) const
Definition iterator.h:300
CombinedInputIterator & operator-=(difference_type i)
bool operator>(const CombinedInputIterator &other) const
Definition iterator.h:320
difference_type operator-(const CombinedInputIterator &other) const
CombinedInputIterator(const CombinedInputIterator &iter)=default
friend std::ostream & operator<<(std::ostream &o, const CombinedInputIterator &iter)
Definition iterator.h:141
CombinedInputIterator & operator--()
Definition iterator.h:243
bool operator<=(const CombinedInputIterator &other) const
Definition iterator.h:334
friend CombinedInputIterator operator+(CombinedInputIterator::difference_type i, const CombinedInputIterator &iter)
Definition iterator.h:147
CombinedInputIterator operator-(difference_type i) const
std::invoke_result_t< F, iterA_T, iterB_T > value_type
Definition iterator.h:79
CombinedInputIterator & operator=(const CombinedInputIterator &other)
Definition iterator.h:219
CombinedInputIterator & operator=(CombinedInputIterator &&other)=default
CombinedInputIterator & operator+=(difference_type i)
bool operator>=(const CombinedInputIterator &other) const
Definition iterator.h:327
internal::getIteratorTag_t< typename std::iterator_traits< iterA_T >::iterator_category, typename std::iterator_traits< iterB_T >::iterator_category > iterator_category
Definition iterator.h:82
CombinedInputIterator(CombinedInputIterator &&iter)=default
CombinedInputIterator operator+(difference_type i) const
bool operator!=(const CombinedInputIterator &other) const
Definition iterator.h:306
std::ptrdiff_t difference_type
Definition iterator.h:78
CombinedInputIterator & operator++()
Definition iterator.h:227
value_type operator[](difference_type i) const
bool operator<(const CombinedInputIterator &other) const
Definition iterator.h:313
friend std::ostream & operator<<(std::ostream &o, const CombinedOutputIterator &iter)
Definition iterator.h:196
CombinedOutputIterator(const CombinedOutputIterator &iter)=default
std::input_iterator_tag iterator_category
Definition iterator.h:173
CombinedOutputIterator(CombinedOutputIterator &&iter)=default
CombinedOutputIterator & operator=(const CombinedOutputIterator &other)
Definition iterator.h:360
CombinedOutputIterator & operator++()
Definition iterator.h:368
CombinedOutputIterator(iterA_T iterA, iterB_T iterB, F functor)
Definition iterator.h:353
CombinedOutputIterator & operator=(CombinedOutputIterator &&other)=default
GLsizei const GLfloat * value
Definition glcorearb.h:819
constexpr bool isBidirectionalIterator_v
Definition iterator.h:38
constexpr bool areBothRandomAccessIterators_v
Definition iterator.h:43
typename getIteratorTag< iterA_T, iterB_T >::value_type getIteratorTag_t
Definition iterator.h:70
constexpr bool isRandomAccessIterator_v
Definition iterator.h:40
static auto makeIter(iterA_T iterA, iterB_T iterB, F functor) -> CombinedOutputIterator< input_T, iterA_T, iterB_T, F >
Definition iterator.h:207
VectorOfTObjectPtrs other