SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
policy_alignment_result_builder.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
19 
20 namespace seqan3::detail
21 {
22 
33 template <typename alignment_configuration_t>
34 #if !SEQAN3_WORKAROUND_GCC_93467
35  requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
38 #endif // !SEQAN3_WORKAROUND_GCC_93467
39 class policy_alignment_result_builder
40 {
41 protected:
43  using traits_type = alignment_configuration_traits<alignment_configuration_t>;
45  using result_type = typename traits_type::alignment_result_type;
46 
47  static_assert(!std::same_as<result_type, empty_type>, "The alignment result type was not configured.");
48 
52  policy_alignment_result_builder() = default;
53  policy_alignment_result_builder(policy_alignment_result_builder const &) = default;
54  policy_alignment_result_builder(policy_alignment_result_builder &&) = default;
55  policy_alignment_result_builder & operator=(policy_alignment_result_builder const &) = default;
56  policy_alignment_result_builder & operator=(policy_alignment_result_builder &&) = default;
57  ~policy_alignment_result_builder() = default;
58 
62  policy_alignment_result_builder(alignment_configuration_t const & SEQAN3_DOXYGEN_ONLY(config))
63  {}
65 
88  template <typename sequence_pair_t,
89  typename index_t,
90  typename score_t,
91  typename matrix_coordinate_t,
92  typename callback_t>
94  requires std::invocable<callback_t, result_type>
96  void make_result_and_invoke([[maybe_unused]] sequence_pair_t && sequence_pair,
97  [[maybe_unused]] index_t && id,
98  [[maybe_unused]] score_t score,
99  [[maybe_unused]] matrix_coordinate_t end_positions,
100  callback_t && callback)
101  {
102  using std::get;
103  using invalid_t = std::nullopt_t *;
104 
105  result_type result{};
106 
107  if constexpr (traits_type::output_sequence1_id)
108  result.data.sequence1_id = id;
109 
110  if constexpr (traits_type::output_sequence2_id)
111  result.data.sequence2_id = id;
112 
113  if constexpr (traits_type::compute_score)
114  {
115  static_assert(!std::same_as<decltype(result.data.score), invalid_t>,
116  "Invalid configuration. Expected result with score!");
117  result.data.score = std::move(score);
118  }
119 
120  if constexpr (traits_type::compute_end_positions)
121  {
122  static_assert(!std::same_as<decltype(result.data.end_positions), invalid_t>,
123  "Invalid configuration. Expected result with end positions!");
124 
125  result.data.end_positions.first = end_positions.col;
126  result.data.end_positions.second = end_positions.row;
127  }
128 
129  // TODO: Add other result.data like sequence1_begin_position, sequence1_end_position, and so on.
130 
131  callback(std::move(result));
132  }
133 };
134 } // namespace seqan3::detail
type_traits.hpp
Provides helper type traits for the configuration and execution of the alignment algorithm.
configuration.hpp
Provides seqan3::detail::configuration and utility functions.
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
seqan3::views::get
auto const get
A view calling std::get on each element in a range.
Definition: get.hpp:65
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
std::nullopt_t
empty_type.hpp
Provides seqan3::detail::empty_type.