SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
two_dimensional_matrix_iterator_base.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <concepts>
13#include <ranges>
14#include <type_traits>
15
19
20namespace seqan3::detail
21{
22
35enum struct matrix_major_order : uint8_t
36{
37 column,
38 row
39};
40
72template <typename derived_t, matrix_major_order order>
74{
75private:
77 friend derived_t;
78
80 template <typename other_derived_t, matrix_major_order other_order>
82
99
101 template <typename _derived_t>
102 using difference_type = typename _derived_t::difference_type;
103
105 template <typename _derived_t>
106 using reference = typename _derived_t::reference;
107
109 template <typename _derived_t>
110 using pointer = typename _derived_t::pointer;
111
112public:
117 template <typename dummy_t = derived_t>
118 constexpr reference<dummy_t> operator*() const noexcept
119 {
120 return *as_derived().host_iter;
121 }
122
124 template <typename dummy_t = derived_t>
126 {
127 return *(as_derived() + offset);
128 }
129
131 template <typename dummy_t = derived_t>
132 constexpr reference<dummy_t> operator[](matrix_offset const & offset) const noexcept
133 {
134 return *(as_derived() + offset);
135 }
136
138 template <typename dummy_t = derived_t>
139 constexpr pointer<dummy_t> operator->() const noexcept
140 {
141 return std::addressof(*as_derived().host_iter);
142 }
143
154 SEQAN3_DOXYGEN_ONLY(constexpr seqan3::detail::matrix_coordinate coordinate() const noexcept {})
156
175 SEQAN3_DOXYGEN_ONLY(constexpr derived_t & operator+=(matrix_offset const & offset) noexcept {})
176
178 constexpr derived_t & operator++() noexcept
179 {
180 if constexpr (order == matrix_major_order::column)
182 else
184 }
185
187 constexpr derived_t operator++(int) noexcept
188 {
189 derived_t previous{as_derived()};
190 ++(*this);
191 return previous;
192 }
193
195 template <typename dummy_t = derived_t>
197 {
198 if constexpr (order == matrix_major_order::column)
200 else
202 }
203
205 template <typename dummy_t = derived_t>
207 {
208 derived_t next{as_derived()};
209 next += offset;
210 return next;
211 }
212
214 template <typename dummy_t = derived_t>
216 {
217 return iter + offset;
218 }
219
221 constexpr derived_t operator+(matrix_offset const & offset) const noexcept
222 {
223 derived_t next{as_derived()};
224 next += offset;
225 return next;
226 }
227
229 constexpr friend derived_t operator+(matrix_offset const & offset, derived_t const iter)
230 {
231 return iter + offset;
232 }
233
235 constexpr derived_t & operator--() noexcept
236 {
237 if constexpr (order == matrix_major_order::column)
239 else
241 }
242
244 constexpr derived_t operator--(int) noexcept
245 {
246 derived_t previous{as_derived()};
247 --(*this);
248 return previous;
249 }
250
252 template <typename dummy_t = derived_t>
254 {
255 return *this += -offset;
256 }
257
259 template <typename dummy_t = derived_t>
261 {
262 derived_t next{as_derived()};
263 next -= offset;
264 return next;
265 }
266
268 constexpr derived_t & operator-=(matrix_offset const & offset) noexcept
269 {
271 }
272
274 constexpr derived_t operator-(matrix_offset const & offset) const noexcept
275 {
276 derived_t next{as_derived()};
277 next -= offset;
278 return next;
279 }
280
282 template <typename dummy_t = derived_t>
283 friend constexpr std::iter_difference_t<dummy_t> operator-(derived_t const lhs, derived_t const rhs) noexcept
284 {
285 return lhs.as_host_iter() - rhs.as_host_iter();
286 }
288
293 // What if the derived type is different?
294 // How can make sure this is the same type?
295 template <typename other_derived_t>
296 requires std::constructible_from<derived_t, other_derived_t>
297 || std::constructible_from<other_derived_t, derived_t>
299 {
300 return as_derived().host_iter == rhs.as_derived().host_iter;
301 }
302
304 template <typename other_derived_t>
305 requires std::constructible_from<derived_t, other_derived_t>
306 || std::constructible_from<other_derived_t, derived_t>
308 {
309 return !(*this == rhs);
310 }
311
313 template <typename other_derived_t>
314 requires std::constructible_from<derived_t, other_derived_t>
315 || std::constructible_from<other_derived_t, derived_t>
317 {
318 return as_derived().host_iter < rhs.as_derived().host_iter;
319 }
320
322 template <typename other_derived_t>
323 requires std::constructible_from<derived_t, other_derived_t>
324 || std::constructible_from<other_derived_t, derived_t>
326 {
327 return as_derived().host_iter <= rhs.as_derived().host_iter;
328 }
329
331 template <typename other_derived_t>
332 requires std::constructible_from<derived_t, other_derived_t>
333 || std::constructible_from<other_derived_t, derived_t>
335 {
336 return as_derived().host_iter > rhs.as_derived().host_iter;
337 }
338
340 template <typename other_derived_t>
341 requires std::constructible_from<derived_t, other_derived_t>
342 || std::constructible_from<other_derived_t, derived_t>
344 {
345 return as_derived().host_iter >= rhs.as_derived().host_iter;
346 }
348
349private:
351 constexpr auto const & as_host_iter() const
352 {
353 return as_derived().host_iter;
354 }
355
357 constexpr derived_t & as_derived()
358 {
359 return static_cast<derived_t &>(*this);
360 }
361
363 constexpr derived_t const & as_derived() const
364 {
365 return static_cast<derived_t const &>(*this);
366 }
367
368 // matrix_iterator_t host_iter{}; //!< The wrapped matrix iterator.
369};
370} // namespace seqan3::detail
T addressof(T... args)
Provides various type traits on generic types.
A crtp-base class for iterators over seqan3::detail::two_dimensional_matrix.
Definition two_dimensional_matrix_iterator_base.hpp:74
constexpr derived_t operator--(int) noexcept
Returns an iterator decremented by one following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:244
constexpr bool operator>=(two_dimensional_matrix_iterator_base< other_derived_t, order > const &rhs) const noexcept
Checks if lhs is greater than or equal to rhs.
Definition two_dimensional_matrix_iterator_base.hpp:343
constexpr derived_t & operator-=(std::iter_difference_t< dummy_t > const offset) noexcept
Advances the iterator by offset following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:253
constexpr friend derived_t operator+(std::iter_difference_t< dummy_t > const offset, derived_t const iter)
Returns an iterator advanced by offset following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:215
typename _derived_t::pointer pointer
Helper template definition to get the pointer type of the derived type.
Definition two_dimensional_matrix_iterator_base.hpp:110
constexpr friend derived_t operator+(matrix_offset const &offset, derived_t const iter)
Returns an iterator advanced by offset in the respective dimensions.
Definition two_dimensional_matrix_iterator_base.hpp:229
constexpr two_dimensional_matrix_iterator_base()=default
Defaulted.
friend derived_t
Befriend the derived type.
Definition two_dimensional_matrix_iterator_base.hpp:77
constexpr two_dimensional_matrix_iterator_base & operator=(two_dimensional_matrix_iterator_base &&)=default
Defaulted.
constexpr derived_t & operator-=(matrix_offset const &offset) noexcept
Returns an iterator advanced by offset in the respective dimensions.
Definition two_dimensional_matrix_iterator_base.hpp:268
constexpr reference< dummy_t > operator[](std::iter_difference_t< dummy_t > const offset) const noexcept
Returns a reference to the pointed-to-element after advancing the iterator by the given offset.
Definition two_dimensional_matrix_iterator_base.hpp:125
constexpr auto const & as_host_iter() const
Return the host_iter of the derived type.
Definition two_dimensional_matrix_iterator_base.hpp:351
constexpr derived_t & operator--() noexcept
Advances the iterator by minus one following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:235
constexpr derived_t operator++(int) noexcept
Returns an iterator incremented by one following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:187
constexpr derived_t & operator+=(std::iter_difference_t< dummy_t > const offset) noexcept
Advances the iterator by offset following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:196
constexpr two_dimensional_matrix_iterator_base & operator=(two_dimensional_matrix_iterator_base const &)=default
Defaulted.
constexpr two_dimensional_matrix_iterator_base(two_dimensional_matrix_iterator_base const &)=default
Defaulted.
friend constexpr std::iter_difference_t< dummy_t > operator-(derived_t const lhs, derived_t const rhs) noexcept
Returns the distance between two iterators.
Definition two_dimensional_matrix_iterator_base.hpp:283
constexpr bool operator==(two_dimensional_matrix_iterator_base< other_derived_t, order > const &rhs) const noexcept
Returns true if both iterators are equal, false otherwise.
Definition two_dimensional_matrix_iterator_base.hpp:298
constexpr pointer< dummy_t > operator->() const noexcept
Returns a pointer to the pointed-to-element.
Definition two_dimensional_matrix_iterator_base.hpp:139
constexpr derived_t operator-(matrix_offset const &offset) const noexcept
Returns an iterator advanced by offset in the respective dimensions.
Definition two_dimensional_matrix_iterator_base.hpp:274
constexpr derived_t operator+(std::iter_difference_t< dummy_t > const offset) const noexcept
Returns an iterator advanced by offset following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:206
constexpr bool operator<=(two_dimensional_matrix_iterator_base< other_derived_t, order > const &rhs) const noexcept
Checks if lhs is smaller than or equal to rhs.
Definition two_dimensional_matrix_iterator_base.hpp:325
constexpr reference< dummy_t > operator[](matrix_offset const &offset) const noexcept
Returns a reference to the pointed-to-element after advancing the iterator by the given offset.
Definition two_dimensional_matrix_iterator_base.hpp:132
constexpr reference< dummy_t > operator*() const noexcept
Returns a reference to the pointed to element.
Definition two_dimensional_matrix_iterator_base.hpp:118
typename _derived_t::reference reference
Helper template definition to get the reference type of the derived type.
Definition two_dimensional_matrix_iterator_base.hpp:106
constexpr derived_t const & as_derived() const
Cast this to derived type.
Definition two_dimensional_matrix_iterator_base.hpp:363
constexpr bool operator>(two_dimensional_matrix_iterator_base< other_derived_t, order > const &rhs) const noexcept
Checks if lhs is greater than rhs.
Definition two_dimensional_matrix_iterator_base.hpp:334
constexpr two_dimensional_matrix_iterator_base(two_dimensional_matrix_iterator_base &&)=default
Defaulted.
constexpr seqan3::detail::matrix_coordinate coordinate() const noexcept
Returns the current position of the iterator as a seqan3::detail::matrix_coordinate.
Definition two_dimensional_matrix_iterator_base.hpp:154
constexpr bool operator<(two_dimensional_matrix_iterator_base< other_derived_t, order > const &rhs) const noexcept
Checks if lhs is smaller than rhs.
Definition two_dimensional_matrix_iterator_base.hpp:316
constexpr derived_t operator+(matrix_offset const &offset) const noexcept
Returns an iterator advanced by offset in the respective dimensions.
Definition two_dimensional_matrix_iterator_base.hpp:221
constexpr derived_t & as_derived()
Cast this to derived type.
Definition two_dimensional_matrix_iterator_base.hpp:357
constexpr bool operator!=(two_dimensional_matrix_iterator_base< other_derived_t, order > const &rhs) const noexcept
Returns true if both iterators are unequal, false otherwise.
Definition two_dimensional_matrix_iterator_base.hpp:307
constexpr derived_t operator-(std::iter_difference_t< dummy_t > const offset) const noexcept
Returns an iterator advanced by offset following the given matrix major order.
Definition two_dimensional_matrix_iterator_base.hpp:260
typename _derived_t::difference_type difference_type
Helper template definition to get the difference type of the derived type.
Definition two_dimensional_matrix_iterator_base.hpp:102
matrix_major_order
Selects the major order of the matrix.
Definition two_dimensional_matrix_iterator_base.hpp:36
@ column
The corresponding alignment coordinate will be incrementable/decrementable in the column index.
@ row
The corresponding alignment coordinate will be incrementable/decrementable in the row index.
@ column
Accesses matrix in column major order.
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
Provides various transformation traits for use on iterators.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
A strong type for designated initialisation of the column index of a matrix.
Definition matrix_coordinate.hpp:29
A representation of a location or offset within a two-dimensional matrix.
Definition matrix_coordinate.hpp:87
A strong type for designated initialisation of the row index of a matrix.
Definition matrix_coordinate.hpp:58
Hide me