SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alignment_matrix_column_major_range_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 <cassert>
13#include <iterator>
14#include <ranges>
15#include <span>
16
19
20namespace seqan3::detail
21{
22
58template <typename derived_t>
60{
61private:
63 friend derived_t;
64
74 class alignment_column_type : public std::ranges::view_interface<alignment_column_type>
75 {
76 private:
79
80 static_assert(std::ranges::random_access_range<view_type>, "Column view must support random access.");
81 static_assert(std::ranges::sized_range<view_type>, "Column view must be a sized range.");
82 static_assert(std::ranges::view<view_type>, "Column view must be a view.");
83
85 using sentinel = std::ranges::sentinel_t<view_type>;
86
97 {
98 public:
107 using pointer = void;
109 using difference_type = std::ranges::range_difference_t<view_type>;
113
117 constexpr iterator_type() = default;
118 constexpr iterator_type(iterator_type const &) = default;
119 constexpr iterator_type(iterator_type &&) = default;
120 constexpr iterator_type & operator=(iterator_type const &) = default;
121 constexpr iterator_type & operator=(iterator_type &&) = default;
122 ~iterator_type() = default;
123
127 explicit constexpr iterator_type(alignment_column_type & host) :
128 host_ptr{&host},
129 host_iter{host.ref.begin()}
130 {
131 host_ptr->me_ptr->on_column_iterator_creation(host_iter);
132 }
134
139 constexpr reference operator*() const noexcept
140 {
141 static_assert(std::convertible_to<decltype(host_ptr->me_ptr->make_proxy(host_iter)), reference>,
142 "The returned type of make_proxy must be convertible to the reference type.");
143 assert(host_ptr != nullptr);
144 return host_ptr->me_ptr->make_proxy(host_iter);
145 }
147
152 constexpr iterator_type & operator++() noexcept
153 {
154 assert(host_ptr != nullptr);
155 assert(host_ptr->me_ptr != nullptr);
156
157 host_ptr->me_ptr->before_column_iterator_increment(host_iter);
158 ++host_iter;
159 host_ptr->me_ptr->after_column_iterator_increment(host_iter);
160 return *this;
161 }
162
164 constexpr iterator_type operator++(int) noexcept
165 {
166 iterator_type tmp{*this};
167 ++(*this);
168 return tmp;
169 }
171
176 constexpr bool operator==(sentinel const & rhs) const noexcept
177 {
178 return host_iter == rhs;
179 }
180
182 friend constexpr bool operator==(sentinel const & lhs, iterator_type const & rhs) noexcept
183 {
184 return rhs == lhs;
185 }
186
188 constexpr bool operator==(iterator_type const & rhs) const noexcept
189 {
190 return (host_ptr == rhs.host_ptr) && (host_iter == rhs.host_iter);
191 }
192
194 constexpr bool operator!=(sentinel const & rhs) const noexcept
195 {
196 return !(*this == rhs);
197 }
198
200 friend constexpr bool operator!=(sentinel const & lhs, iterator_type const & rhs) noexcept
201 {
202 return rhs != lhs;
203 }
204
206 constexpr bool operator!=(iterator_type const & rhs) const noexcept
207 {
208 return !(*this == rhs);
209 }
211
212 private:
216 std::ranges::iterator_t<view_type> host_iter{};
217 }; // class iterator_type
218
219 public:
223 constexpr alignment_column_type() = default;
224 constexpr alignment_column_type(alignment_column_type const &) = default;
229
238 constexpr alignment_column_type(derived_t & me, view_type ref) : ref{std::move(ref)}, me_ptr{&me}
239 {}
241
247 constexpr iterator_type begin() noexcept
248 {
249 assert(me_ptr != nullptr);
250 return iterator_type{*this};
251 }
252
254 constexpr auto begin() const noexcept = delete; // Not needed by the alignment algorithm
255
257 constexpr sentinel end() noexcept
258 {
259 return ref.end();
260 }
261
263 constexpr sentinel end() const noexcept = delete; // Not needed by the alignment algorithm
265
267 constexpr size_t size() const noexcept
268 {
269 return std::ranges::size(ref);
270 }
271
272 private:
277 }; // class alignment_column_type
278
292 {
293 public:
302 using pointer = void;
304 using difference_type = std::ranges::range_difference_t<alignment_column_type>;
308
312 constexpr iterator_type() = default;
313 constexpr iterator_type(iterator_type const &) = default;
314 constexpr iterator_type(iterator_type &&) = default;
315 constexpr iterator_type & operator=(iterator_type const &) = default;
316 constexpr iterator_type & operator=(iterator_type &&) = default;
317 ~iterator_type() = default;
318
322 explicit constexpr iterator_type(derived_t & me) : me_ptr{&me}, column_index{0}
323 {}
325
330 constexpr reference operator*() const noexcept
331 {
332 static_assert(std::convertible_to<decltype(me_ptr->initialise_column(column_index)), reference>,
333 "The returned type of initialise_column must be convertible to the reference type.");
334 return me_ptr->initialise_column(column_index);
335 }
337
342 constexpr iterator_type & operator++() noexcept
343 {
344 ++column_index;
345 return *this;
346 }
347
349 constexpr void operator++(int) noexcept
350 {
351 ++(*this);
352 }
354
359 constexpr bool operator==(std::default_sentinel_t const &) const noexcept
360 {
361 return column_index == me_ptr->num_cols;
362 }
363
365 friend constexpr bool operator==(std::default_sentinel_t const & lhs, iterator_type const & rhs) noexcept
366 {
367 return rhs == lhs;
368 }
369
371 constexpr bool operator!=(std::default_sentinel_t const & rhs) const noexcept
372 {
373 return !(*this == rhs);
374 }
375
377 friend constexpr bool operator!=(std::default_sentinel_t const & lhs, iterator_type const & rhs) noexcept
378 {
379 return rhs != lhs;
380 }
382
383 private:
387 size_t column_index{};
388 }; // class iterator_type
389
408
416 SEQAN3_DOXYGEN_ONLY(typedef /*IMPLEMENTATION_DEFINED*/ value_type;)
417
421 SEQAN3_DOXYGEN_ONLY(typedef /*IMPLEMENTATION_DEFINED*/ column_data_view_type;)
423
433 SEQAN3_DOXYGEN_ONLY(value_type make_proxy(iter_t host_iter) noexcept {})
434
447 SEQAN3_DOXYGEN_ONLY(alignment_column_type initialise_column(size_t column_index){})
448
453 template <typename iter_t>
454 constexpr void on_column_iterator_creation(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
455 {}
456
461 template <typename iter_t>
462 constexpr void before_column_iterator_increment(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
463 {}
464
469 template <typename iter_t>
470 constexpr void after_column_iterator_increment(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
471 {}
473
477 using sentinel = std::default_sentinel_t;
478
479public:
485 constexpr iterator begin() noexcept
486 {
487 return iterator{static_cast<derived_t &>(*this)};
488 }
489
491 constexpr iterator begin() const noexcept = delete; // not needed for the alignment algorithm
492
494 constexpr sentinel end() noexcept
495 {
496 return std::default_sentinel;
497 }
498
500 constexpr sentinel end() const noexcept = delete; // not needed for the alignment algorithm
502};
503} // namespace seqan3::detail
Provides various type traits on generic types.
The iterator over an alignment-column.
Definition alignment_matrix_column_major_range_base.hpp:97
constexpr reference operator*() const noexcept
Returns a proxy for the current alignment cell.
Definition alignment_matrix_column_major_range_base.hpp:139
constexpr bool operator==(sentinel const &rhs) const noexcept
Returns true if the host iterator reached the end, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:176
typename deferred_type< typename derived_t::value_type >::type value_type
A value type dependent on the derived type.
Definition alignment_matrix_column_major_range_base.hpp:103
constexpr iterator_type & operator++() noexcept
Advances the iterator by one.
Definition alignment_matrix_column_major_range_base.hpp:152
std::ranges::iterator_t< view_type > host_iter
Wrapped iterator over aliased matrix column.
Definition alignment_matrix_column_major_range_base.hpp:216
friend constexpr bool operator==(sentinel const &lhs, iterator_type const &rhs) noexcept
Returns true if the host iterator reached the end, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:182
constexpr iterator_type & operator=(iterator_type &&)=default
Defaulted.
constexpr iterator_type & operator=(iterator_type const &)=default
Defaulted.
friend constexpr bool operator!=(sentinel const &lhs, iterator_type const &rhs) noexcept
Returns true if the host iterator did not reach the end, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:200
constexpr iterator_type(alignment_column_type &host)
Construction from the underlying alignment-column.
Definition alignment_matrix_column_major_range_base.hpp:127
alignment_column_type * host_ptr
Pointer to the underlying alignment-column.
Definition alignment_matrix_column_major_range_base.hpp:214
constexpr iterator_type operator++(int) noexcept
Advances the iterator and returns previous iterator.
Definition alignment_matrix_column_major_range_base.hpp:164
constexpr bool operator!=(sentinel const &rhs) const noexcept
Returns true if the host iterator did not reach the end, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:194
typename deferred_type< typename derived_t::reference >::type reference
The reference type dependent on the derived type.
Definition alignment_matrix_column_major_range_base.hpp:105
std::ranges::range_difference_t< view_type > difference_type
Difference type.
Definition alignment_matrix_column_major_range_base.hpp:109
void pointer
Pointer type.
Definition alignment_matrix_column_major_range_base.hpp:107
constexpr bool operator==(iterator_type const &rhs) const noexcept
Returns true if both iterators are equal, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:188
constexpr bool operator!=(iterator_type const &rhs) const noexcept
Returns true if both iterators are not equal, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:206
Represents a column within an alignment matrix.
Definition alignment_matrix_column_major_range_base.hpp:75
view_type ref
The aliased alignment-column.
Definition alignment_matrix_column_major_range_base.hpp:274
constexpr size_t size() const noexcept
Returns the size the alignment column.
Definition alignment_matrix_column_major_range_base.hpp:267
constexpr alignment_column_type & operator=(alignment_column_type const &)=default
Defaulted.
constexpr alignment_column_type(alignment_column_type &&)=default
Defaulted.
derived_t * me_ptr
Pointer to the derived type.
Definition alignment_matrix_column_major_range_base.hpp:276
typename deferred_type< typename derived_t::column_data_view_type >::type view_type
A view aliasing the actual stored data column within the underlying matrix.
Definition alignment_matrix_column_major_range_base.hpp:78
constexpr sentinel end() noexcept
Returns an iterator to the end of the column.
Definition alignment_matrix_column_major_range_base.hpp:257
constexpr sentinel end() const noexcept=delete
Deleted end for const-qualified alignment-columns.
constexpr auto begin() const noexcept=delete
Deleted begin for const-qualified alignment-columns.
std::ranges::sentinel_t< view_type > sentinel
The sentinel type of the underlying view.
Definition alignment_matrix_column_major_range_base.hpp:85
constexpr alignment_column_type & operator=(alignment_column_type &&)=default
Defaulted.
constexpr alignment_column_type(alignment_column_type const &)=default
Defaulted.
constexpr iterator_type begin() noexcept
Returns an iterator to the begin of the column.
Definition alignment_matrix_column_major_range_base.hpp:247
constexpr alignment_column_type(derived_t &me, view_type ref)
Constructs from the derived type.
Definition alignment_matrix_column_major_range_base.hpp:238
A column iterator over the alignment matrix.
Definition alignment_matrix_column_major_range_base.hpp:292
constexpr iterator_type & operator=(iterator_type const &)=default
Defaulted.
constexpr void operator++(int) noexcept
Increments by one.
Definition alignment_matrix_column_major_range_base.hpp:349
alignment_column_type value_type
The alignment-column type.
Definition alignment_matrix_column_major_range_base.hpp:298
friend constexpr bool operator!=(std::default_sentinel_t const &lhs, iterator_type const &rhs) noexcept
Returns true if the host iterator did not reach the end, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:377
constexpr iterator_type(iterator_type const &)=default
Defaulted.
constexpr bool operator!=(std::default_sentinel_t const &rhs) const noexcept
Returns true if the behind-the-end column was not reached, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:371
friend constexpr bool operator==(std::default_sentinel_t const &lhs, iterator_type const &rhs) noexcept
Returns true if the host iterator reached the end, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:365
std::ranges::range_difference_t< alignment_column_type > difference_type
Difference type.
Definition alignment_matrix_column_major_range_base.hpp:304
constexpr bool operator==(std::default_sentinel_t const &) const noexcept
Returns true if the behind-the-end column was reached, false otherwise.
Definition alignment_matrix_column_major_range_base.hpp:359
size_t column_index
The current column index.
Definition alignment_matrix_column_major_range_base.hpp:387
void pointer
Pointer type.
Definition alignment_matrix_column_major_range_base.hpp:302
derived_t * me_ptr
Pointer to the derived type.
Definition alignment_matrix_column_major_range_base.hpp:385
constexpr iterator_type & operator=(iterator_type &&)=default
Defaulted.
constexpr reference operator*() const noexcept
Returns the current alignment-column.
Definition alignment_matrix_column_major_range_base.hpp:330
constexpr iterator_type(derived_t &me)
Construction from an instance of the derived type.
Definition alignment_matrix_column_major_range_base.hpp:322
constexpr iterator_type & operator++() noexcept
Increments by one.
Definition alignment_matrix_column_major_range_base.hpp:342
constexpr iterator_type(iterator_type &&)=default
Defaulted.
Provides a range interface for alignment matrices.
Definition alignment_matrix_column_major_range_base.hpp:60
typedef column_data_view_type
The view over the current alignment-column; must model std::ranges::view and std::ranges::input_range...
Definition alignment_matrix_column_major_range_base.hpp:421
std::default_sentinel_t sentinel
The type of sentinel.
Definition alignment_matrix_column_major_range_base.hpp:477
friend derived_t
Befriend the derived type.
Definition alignment_matrix_column_major_range_base.hpp:63
constexpr alignment_matrix_column_major_range_base & operator=(alignment_matrix_column_major_range_base const &)=default
Defaulted.
constexpr void on_column_iterator_creation(iter_t host_iter) noexcept
Allows additional initialisations when calling begin on an alignment-column.
Definition alignment_matrix_column_major_range_base.hpp:454
constexpr alignment_matrix_column_major_range_base()=default
Defaulted.
alignment_column_type initialise_column(size_t column_index)
Returns the current alignment-column at the given column_index.
Definition alignment_matrix_column_major_range_base.hpp:447
constexpr iterator begin() const noexcept=delete
Deleted begin for const-qualified alignment matrix.
constexpr void after_column_iterator_increment(iter_t host_iter) noexcept
Allows to perform additional steps after incrementing the alignment-column-iterator.
Definition alignment_matrix_column_major_range_base.hpp:470
constexpr iterator begin() noexcept
Returns an iterator to the first column of the matrix.
Definition alignment_matrix_column_major_range_base.hpp:485
constexpr sentinel end() noexcept
Returns a sentinel marking the end of the matrix.
Definition alignment_matrix_column_major_range_base.hpp:494
constexpr sentinel end() const noexcept=delete
Deleted end for const-qualified alignment matrix.
constexpr void before_column_iterator_increment(iter_t host_iter) noexcept
Allows to perform additional steps before incrementing the alignment-column-iterator.
Definition alignment_matrix_column_major_range_base.hpp:462
constexpr alignment_matrix_column_major_range_base & operator=(alignment_matrix_column_major_range_base &&)=default
Defaulted.
constexpr alignment_matrix_column_major_range_base(alignment_matrix_column_major_range_base const &)=default
Defaulted.
typedef value_type
The proxy type of an alignment matrix.
Definition alignment_matrix_column_major_range_base.hpp:416
constexpr alignment_matrix_column_major_range_base(alignment_matrix_column_major_range_base &&)=default
Defaulted.
value_type make_proxy(iter_t host_iter) noexcept
Creates the proxy value returned when dereferencing the alignment-column-iterator.
Definition alignment_matrix_column_major_range_base.hpp:433
Provides various transformation traits used by the range module.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
t type
The type identity.
Definition basic.hpp:108
Hide me