SeqAn3 3.2.0-rc.1
The Modern C++ library for sequence analysis.
alignment_matrix_column_major_range_base.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <seqan3/std/iterator>
16#include <seqan3/std/ranges>
17#include <seqan3/std/span>
18
21
22namespace seqan3::detail
23{
24
60template <typename derived_t>
62{
63private:
65 friend derived_t;
66
76 class alignment_column_type : public std::ranges::view_interface<alignment_column_type>
77 {
78 private:
81
82 static_assert(std::ranges::random_access_range<view_type>, "Column view must support random access.");
83 static_assert(std::ranges::sized_range<view_type>, "Column view must be a sized range.");
84 static_assert(std::ranges::view<view_type>, "Column view must be a view.");
85
87 using sentinel = std::ranges::sentinel_t<view_type>;
88
99 {
100 public:
101
110 using pointer = void;
112 using difference_type = std::ranges::range_difference_t<view_type>;
116
120 constexpr iterator_type() = default;
121 constexpr iterator_type(iterator_type const &) = default;
122 constexpr iterator_type(iterator_type &&) = default;
123 constexpr iterator_type & operator=(iterator_type const &) = default;
124 constexpr iterator_type & operator=(iterator_type &&) = default;
125 ~iterator_type() = default;
126
130 explicit constexpr iterator_type(alignment_column_type & host) :
131 host_ptr{&host},
132 host_iter{host.ref.begin()}
133 {
134 host_ptr->me_ptr->on_column_iterator_creation(host_iter);
135 }
137
142 constexpr reference operator*() const noexcept
143 {
144 static_assert(std::convertible_to<decltype(host_ptr->me_ptr->make_proxy(host_iter)), reference>,
145 "The returned type of make_proxy must be convertible to the reference type.");
146 assert(host_ptr != nullptr);
147 return host_ptr->me_ptr->make_proxy(host_iter);
148 }
150
155 constexpr iterator_type & operator++() noexcept
156 {
157 assert(host_ptr != nullptr);
158 assert(host_ptr->me_ptr != nullptr);
159
160 host_ptr->me_ptr->before_column_iterator_increment(host_iter);
161 ++host_iter;
162 host_ptr->me_ptr->after_column_iterator_increment(host_iter);
163 return *this;
164 }
165
167 constexpr iterator_type operator++(int) noexcept
168 {
169 iterator_type tmp{*this};
170 ++(*this);
171 return tmp;
172 }
174
179 constexpr bool operator==(sentinel const & rhs) const noexcept
180 {
181 return host_iter == rhs;
182 }
183
185 friend constexpr bool operator==(sentinel const & lhs, iterator_type const & rhs) noexcept
186 {
187 return rhs == lhs;
188 }
189
191 constexpr bool operator==(iterator_type const & rhs) const noexcept
192 {
193 return (host_ptr == rhs.host_ptr) && (host_iter == rhs.host_iter);
194 }
195
197 constexpr bool operator!=(sentinel const & rhs) const noexcept
198 {
199 return !(*this == rhs);
200 }
201
203 friend constexpr bool operator!=(sentinel const & lhs, iterator_type const & rhs) noexcept
204 {
205 return rhs != lhs;
206 }
207
209 constexpr bool operator!=(iterator_type const & rhs) const noexcept
210 {
211 return !(*this == rhs);
212 }
214
215 private:
219 std::ranges::iterator_t<view_type> host_iter{};
220 }; // class iterator_type
221
222 public:
226 constexpr alignment_column_type() = default;
227 constexpr alignment_column_type(alignment_column_type const &) = default;
232
242 ref{std::move(ref)},
243 me_ptr{&me}
244 {}
246
252 constexpr iterator_type begin() noexcept
253 {
254 assert(me_ptr != nullptr);
255 return iterator_type{*this};
256 }
257
259 constexpr auto begin() const noexcept = delete; // Not needed by the alignment algorithm
260
262 constexpr sentinel end() noexcept
263 {
264 return ref.end();
265 }
266
268 constexpr sentinel end() const noexcept = delete; // Not needed by the alignment algorithm
270
272 constexpr size_t size() const noexcept
273 {
274 return std::ranges::size(ref);
275 }
276
277 private:
282 }; // class alignment_column_type
283
297 {
298 public:
307 using pointer = void;
309 using difference_type = std::ranges::range_difference_t<alignment_column_type>;
313
317 constexpr iterator_type() = default;
318 constexpr iterator_type(iterator_type const &) = default;
319 constexpr iterator_type(iterator_type &&) = default;
320 constexpr iterator_type & operator=(iterator_type const &) = default;
321 constexpr iterator_type & operator=(iterator_type &&) = default;
322 ~iterator_type() = default;
323
327 explicit constexpr iterator_type(derived_t & me) :
328 me_ptr{&me},
329 column_index{0}
330 {}
332
337 constexpr reference operator*() const noexcept
338 {
339 static_assert(std::convertible_to<decltype(me_ptr->initialise_column(column_index)), reference>,
340 "The returned type of initialise_column must be convertible to the reference type.");
341 return me_ptr->initialise_column(column_index);
342 }
344
349 constexpr iterator_type & operator++() noexcept
350 {
351 ++column_index;
352 return *this;
353 }
354
356 constexpr void operator++(int) noexcept
357 {
358 ++(*this);
359 }
361
366 constexpr bool operator==(std::default_sentinel_t const &) const noexcept
367 {
368 return column_index == me_ptr->num_cols;
369 }
370
372 friend constexpr bool operator==(std::default_sentinel_t const & lhs, iterator_type const & rhs) noexcept
373 {
374 return rhs == lhs;
375 }
376
378 constexpr bool operator!=(std::default_sentinel_t const & rhs) const noexcept
379 {
380 return !(*this == rhs);
381 }
382
384 friend constexpr bool operator!=(std::default_sentinel_t const & lhs, iterator_type const & rhs) noexcept
385 {
386 return rhs != lhs;
387 }
389
390 private:
394 size_t column_index{};
395 }; // class iterator_type
396
415
423 SEQAN3_DOXYGEN_ONLY(typedef /*IMPLEMENTATION_DEFINED*/ value_type;)
424
428 SEQAN3_DOXYGEN_ONLY(typedef /*IMPLEMENTATION_DEFINED*/ column_data_view_type;)
430
440 SEQAN3_DOXYGEN_ONLY(value_type make_proxy(iter_t host_iter) noexcept {})
441
454 SEQAN3_DOXYGEN_ONLY(alignment_column_type initialise_column(size_t column_index) {})
455
460 template <typename iter_t>
461 constexpr void on_column_iterator_creation(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
462 {}
463
468 template <typename iter_t>
469 constexpr void before_column_iterator_increment(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
470 {}
471
476 template <typename iter_t>
477 constexpr void after_column_iterator_increment(iter_t SEQAN3_DOXYGEN_ONLY(host_iter)) noexcept
478 {}
480
484 using sentinel = std::default_sentinel_t;
485
486public:
492 constexpr iterator begin() noexcept
493 {
494 return iterator{static_cast<derived_t &>(*this)};
495 }
496
498 constexpr iterator begin() const noexcept = delete; // not needed for the alignment algorithm
499
501 constexpr sentinel end() noexcept
502 {
503 return std::default_sentinel;
504 }
505
507 constexpr sentinel end() const noexcept = delete; // not needed for the alignment algorithm
509};
510} // namespace seqan3::detail
Provides various type traits on generic types.
The iterator over an alignment-column.
Definition: alignment_matrix_column_major_range_base.hpp:99
constexpr reference operator*() const noexcept
Returns a proxy for the current alignment cell.
Definition: alignment_matrix_column_major_range_base.hpp:142
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:179
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:106
constexpr friend 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:185
constexpr iterator_type & operator++() noexcept
Advances the iterator by one.
Definition: alignment_matrix_column_major_range_base.hpp:155
std::ranges::iterator_t< view_type > host_iter
Wrapped iterator over aliased matrix column.
Definition: alignment_matrix_column_major_range_base.hpp:219
constexpr iterator_type & operator=(iterator_type &&)=default
Defaulted.
constexpr friend 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:203
constexpr iterator_type & operator=(iterator_type const &)=default
Defaulted.
constexpr iterator_type(alignment_column_type &host)
Construction from the underlying alignment-column.
Definition: alignment_matrix_column_major_range_base.hpp:130
alignment_column_type * host_ptr
Pointer to the underlying alignment-column.
Definition: alignment_matrix_column_major_range_base.hpp:217
constexpr iterator_type operator++(int) noexcept
Advances the iterator and returns previous iterator.
Definition: alignment_matrix_column_major_range_base.hpp:167
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:197
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:108
std::ranges::range_difference_t< view_type > difference_type
Difference type.
Definition: alignment_matrix_column_major_range_base.hpp:112
void pointer
Pointer type.
Definition: alignment_matrix_column_major_range_base.hpp:110
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:191
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:209
Represents a column within an alignment matrix.
Definition: alignment_matrix_column_major_range_base.hpp:77
view_type ref
The aliased alignment-column.
Definition: alignment_matrix_column_major_range_base.hpp:279
constexpr size_t size() const noexcept
Returns the size the alignment column.
Definition: alignment_matrix_column_major_range_base.hpp:272
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:281
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:80
constexpr sentinel end() noexcept
Returns an iterator to the end of the column.
Definition: alignment_matrix_column_major_range_base.hpp:262
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:87
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:252
constexpr alignment_column_type(derived_t &me, view_type ref)
Constructs from the derived type.
Definition: alignment_matrix_column_major_range_base.hpp:241
A column iterator over the alignment matrix.
Definition: alignment_matrix_column_major_range_base.hpp:297
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:356
alignment_column_type value_type
The alignment-column type.
Definition: alignment_matrix_column_major_range_base.hpp:303
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:378
std::ranges::range_difference_t< alignment_column_type > difference_type
Difference type.
Definition: alignment_matrix_column_major_range_base.hpp:309
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:366
size_t column_index
The current column index.
Definition: alignment_matrix_column_major_range_base.hpp:394
void pointer
Pointer type.
Definition: alignment_matrix_column_major_range_base.hpp:307
derived_t * me_ptr
Pointer to the derived type.
Definition: alignment_matrix_column_major_range_base.hpp:392
constexpr friend 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:384
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:337
constexpr iterator_type(derived_t &me)
Construction from an instance of the derived type.
Definition: alignment_matrix_column_major_range_base.hpp:327
constexpr friend 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:372
constexpr iterator_type & operator++() noexcept
Increments by one.
Definition: alignment_matrix_column_major_range_base.hpp:349
constexpr iterator_type(iterator_type &&)=default
Defaulted.
Provides a range interface for alignment matrices.
Definition: alignment_matrix_column_major_range_base.hpp:62
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:428
std::default_sentinel_t sentinel
The type of sentinel.
Definition: alignment_matrix_column_major_range_base.hpp:484
friend derived_t
Befriend the derived type.
Definition: alignment_matrix_column_major_range_base.hpp:65
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:461
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:454
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:477
constexpr iterator begin() noexcept
Returns an iterator to the first column of the matrix.
Definition: alignment_matrix_column_major_range_base.hpp:492
constexpr sentinel end() noexcept
Returns a sentinel marking the end of the matrix.
Definition: alignment_matrix_column_major_range_base.hpp:501
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:469
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:423
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:440
Provides various transformation traits used by the range module.
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:151
The <iterator> header from C++20's standard library.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
The <ranges> header from C++20's standard library.
Provides std::span from the C++20 standard library.
Return the type identity; further arguments are ignored, but can make this type dependent if they are...
Definition: basic.hpp:105
t type
The type identity.
Definition: basic.hpp:107