SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::alignment_matrix_column_major_range_base< derived_t > Class Template Reference

Provides a range interface for alignment matrices. More...

#include <seqan3/alignment/matrix/detail/alignment_matrix_column_major_range_base.hpp>

+ Inheritance diagram for seqan3::detail::alignment_matrix_column_major_range_base< derived_t >:

Classes

class  alignment_column_type
 Represents a column within an alignment matrix. More...
 
class  iterator_type
 A column iterator over the alignment matrix. More...
 

Public Member Functions

Iterators

The matrix type is not const-iterable.

constexpr iterator begin () noexcept
 Returns an iterator to the first column of the matrix.
 
constexpr iterator begin () const noexcept=delete
 Deleted begin for const-qualified alignment matrix.
 
constexpr sentinel end () noexcept
 Returns a sentinel marking the end of the matrix.
 
constexpr sentinel end () const noexcept=delete
 Deleted end for const-qualified alignment matrix.
 

Private Types

using iterator = iterator_type
 The type of the iterator.
 
using sentinel = std::default_sentinel_t
 The type of sentinel.
 

Private Member Functions

Constructors, destructor and assignment
constexpr alignment_matrix_column_major_range_base ()=default
 Defaulted.
 
constexpr alignment_matrix_column_major_range_base (alignment_matrix_column_major_range_base const &)=default
 Defaulted.
 
constexpr alignment_matrix_column_major_range_base (alignment_matrix_column_major_range_base &&)=default
 Defaulted.
 
constexpr alignment_matrix_column_major_range_baseoperator= (alignment_matrix_column_major_range_base const &)=default
 Defaulted.
 
constexpr alignment_matrix_column_major_range_baseoperator= (alignment_matrix_column_major_range_base &&)=default
 Defaulted.
 
 ~alignment_matrix_column_major_range_base ()=default
 Defaulted.
 
Required interfaces

The derived class must implement the following methods.

value_type make_proxy (iter_t host_iter) noexcept
 Creates the proxy value returned when dereferencing the alignment-column-iterator.
 
alignment_column_type initialise_column (size_t column_index)
 Returns the current alignment-column at the given column_index.
 
template<typename iter_t >
constexpr void on_column_iterator_creation (iter_t host_iter) noexcept
 Allows additional initialisations when calling begin on an alignment-column.
 
template<typename iter_t >
constexpr void before_column_iterator_increment (iter_t host_iter) noexcept
 Allows to perform additional steps before incrementing the alignment-column-iterator.
 
template<typename iter_t >
constexpr void after_column_iterator_increment (iter_t host_iter) noexcept
 Allows to perform additional steps after incrementing the alignment-column-iterator.
 

Private Attributes

friend derived_t
 Befriend the derived type.
 
Required types

The derived class must implement the following types.

typedef value_type
 The proxy type of an alignment matrix.
 
typedef column_data_view_type
 The view over the current alignment-column; must model std::ranges::view and std::ranges::input_range.
 

Detailed Description

template<typename derived_t>
class seqan3::detail::alignment_matrix_column_major_range_base< derived_t >

Provides a range interface for alignment matrices.

Template Parameters
derived_tThe derived type implementing the data model of the matrix (see details for more information).

This crtp-base class provides a range based interface for alignment matrices. It generates a range of ranges, where both the outer range and the inner ranges model std::ranges::input_range. The interface uses a column-major-order to iterate over the matrix, i.e. the outer range iterates over the columns and the inner range over the num_rows of each column. In addition, the inner range type, also referred to as alignment-column, must model std::ranges::view. It is a shallow wrapper around the actual column stored in the derived_t, who implements the corresponding data model. The current alignment-column is created within the derived_t when the iterator over the outer range is dereferenced. The iterator over the resulting alignment-column is further refined by the derived_t to implement the actual behavior of the underlying alignment matrix.

Requirements of the derived type

This base class requires the following functions and types defined within the derived type in order to customise the returned type over the underlying matrix.

The following functions are not mandatory but can be overriden by the derived type:

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <span>
#include <vector>
{
public:
// Alias the base class
friend base_t;
// Inherit the alignment column type defined in the base class. This type is returned in initialise_column.
using typename base_t::alignment_column_type;
// The following types are required by the base type since they cannot be inferred within the base.
using column_data_view_type = std::span<int>; //This type is the underlying view over the actual memory location.
using value_type = int; // The actual value type.
using reference = int &; // The actual reference type.
my_matrix() = default;
my_matrix(my_matrix const &) = default;
my_matrix(my_matrix &&) = default;
my_matrix & operator=(my_matrix const &) = default;
my_matrix & operator=(my_matrix &&) = default;
~my_matrix() = default;
my_matrix(size_t const num_rows, size_t const num_cols) : num_rows{num_rows}, num_cols{num_cols}
{
data.resize(num_rows * num_cols);
}
protected:
size_t num_rows{};
size_t num_cols{};
//Required for the base class. Initialises the current column given the column index.
alignment_column_type initialise_column(size_t const column_index) noexcept
{
return alignment_column_type{*this,
column_data_view_type{std::addressof(data[num_rows * column_index]), num_rows}};
}
//Required for the base class. Initialises the proxy for the current iterator over the current column.
template <std::random_access_iterator iter_t>
constexpr reference make_proxy(iter_t iter) noexcept
{
return *iter;
}
};
int main()
{
my_matrix matrix{3, 5};
// Fill the matrix with
int val = 0;
for (auto col : matrix) // Iterate over the columns
for (auto & cell : col) // Iterate over the cells in one column.
cell = val++;
// Print the matrix column by column
for (auto col : matrix)
seqan3::debug_stream << col << '\n';
}
T addressof(T... args)
Provides seqan3::detail::alignment_matrix_column_major_range_base.
Provides a range interface for alignment matrices.
Definition alignment_matrix_column_major_range_base.hpp:60
Provides seqan3::debug_stream and related types.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26

Member Function Documentation

◆ after_column_iterator_increment()

template<typename derived_t >
template<typename iter_t >
constexpr void seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::after_column_iterator_increment ( iter_t  host_iter)
inlineconstexprprivatenoexcept

Allows to perform additional steps after incrementing the alignment-column-iterator.

Template Parameters
iter_tThe iterator type of the host iterator.
Parameters
[in]host_iterThe wrapped iterator to the actual memory storage.

◆ before_column_iterator_increment()

template<typename derived_t >
template<typename iter_t >
constexpr void seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::before_column_iterator_increment ( iter_t  host_iter)
inlineconstexprprivatenoexcept

Allows to perform additional steps before incrementing the alignment-column-iterator.

Template Parameters
iter_tThe iterator type of the host iterator.
Parameters
[in]host_iterThe wrapped iterator to the actual memory storage.

◆ initialise_column()

template<typename derived_t >
alignment_column_type seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::initialise_column ( size_t  column_index)
inlineprivate

Returns the current alignment-column at the given column_index.

Parameters
[in]column_indexThe current column position of the outer matrix iterator.
Returns
A view representing the current alignment-column (seqan3::detail::alignment_matrix_column_major_range_base::alignment_column_type)

Creates a new seqan3::detail::alignment_matrix_column_major_range_base::alignment_column_type initialised with the current column of the alignment matrix depending on the given column_index. The alignment_column_type stores a column view as defined by the derived class using the seqan3::detail::alignment_matrix_column_major_range_base::column_data_view_type type definition.

◆ make_proxy()

template<typename derived_t >
value_type seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::make_proxy ( iter_t  host_iter)
inlineprivatenoexcept

Creates the proxy value returned when dereferencing the alignment-column-iterator.

Parameters
[in]host_iterThe wrapped iterator to the actual memory storage.
Returns
A proxy for the current matrix position, which must be of type seqan3::detail::alignment_matrix_column_major_range_base::value_type.

◆ on_column_iterator_creation()

template<typename derived_t >
template<typename iter_t >
constexpr void seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::on_column_iterator_creation ( iter_t  host_iter)
inlineconstexprprivatenoexcept

Allows additional initialisations when calling begin on an alignment-column.

Template Parameters
iter_tThe iterator type of the host iterator.
Parameters
[in]host_iterThe wrapped iterator to the actual memory storage.

Member Data Documentation

◆ column_data_view_type

template<typename derived_t >
typedef seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::column_data_view_type
private

The view over the current alignment-column; must model std::ranges::view and std::ranges::input_range.

Note
This type must be defined by the derived type.

◆ value_type

template<typename derived_t >
typedef seqan3::detail::alignment_matrix_column_major_range_base< derived_t >::value_type
private

The proxy type of an alignment matrix.

Note
This type must be defined by the derived type.

The documentation for this class was generated from the following file:
Hide me