SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
search_result.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 
14 #pragma once
15 
16 #include <concepts>
17 #include <exception>
18 
26 
27 namespace seqan3::detail
28 {
29 // forward declaration
30 template <typename search_configuration_t>
31  requires is_type_specialisation_of_v<search_configuration_t, configuration>
32 struct policy_search_result_builder;
33 } // namespace seqan3::detail
34 
35 namespace seqan3
36 {
37 
67 template <typename query_id_type,
68  typename cursor_type,
69  typename reference_id_type,
70  typename reference_begin_position_type>
71  requires (std::integral<query_id_type> || std::same_as<query_id_type, detail::empty_type>)
72  && (detail::template_specialisation_of<cursor_type, fm_index_cursor>
73  || detail::template_specialisation_of<cursor_type, bi_fm_index_cursor>
74  || std::same_as<cursor_type, detail::empty_type>)
75  && (std::integral<reference_id_type> || std::same_as<reference_id_type, detail::empty_type>)
76  && (std::integral<reference_begin_position_type>
77  || std::same_as<reference_begin_position_type, detail::empty_type>)
78 class search_result
79 {
80 private:
82  query_id_type query_id_{};
84  cursor_type cursor_{};
86  reference_id_type reference_id_{};
88  reference_begin_position_type reference_begin_position_{};
89 
90  // Grant the policy access to private constructors.
91  template <typename search_configuration_t>
92  requires detail::is_type_specialisation_of_v<search_configuration_t, configuration>
93  friend struct detail::policy_search_result_builder;
94 
95 public:
99  search_result() = default;
100  search_result(search_result const &) = default;
101  search_result(search_result &&) = default;
102  search_result & operator=(search_result const &) = default;
103  search_result & operator=(search_result &&) = default;
104  ~search_result() = default;
105 
107 
113  constexpr auto query_id() const noexcept
114  {
115  static_assert(!std::same_as<query_id_type, detail::empty_type>,
116  "You tried to access the query_id but it was not selected in the output "
117  "configuration of the search.");
118 
119  return query_id_;
120  }
121 
126  constexpr auto index_cursor() const noexcept(!(std::same_as<cursor_type, detail::empty_type>))
127  {
128  static_assert(!std::same_as<cursor_type, detail::empty_type>,
129  "You tried to access the index cursor but it was not selected in the output "
130  "configuration of the search.");
131 
132  return cursor_;
133  }
134 
141  constexpr auto reference_id() const noexcept(!(std::same_as<reference_id_type, detail::empty_type>))
142  {
143  static_assert(!std::same_as<reference_id_type, detail::empty_type>,
144  "You tried to access the reference id but it was not selected in the output "
145  "configuration of the search.");
146 
147  return reference_id_;
148  }
149 
151  constexpr auto reference_begin_position() const
152  noexcept(!(std::same_as<reference_begin_position_type, detail::empty_type>))
153  {
154  static_assert(!std::same_as<reference_begin_position_type, detail::empty_type>,
155  "You tried to access the reference begin position but it was not selected in the "
156  "output configuration of the search.");
157 
158  return reference_begin_position_;
159  }
161 
166  friend bool operator==(search_result const & lhs, search_result const & rhs) noexcept
167  {
168  bool equality = lhs.query_id_ == rhs.query_id_;
169  if constexpr (!std::is_same_v<cursor_type, detail::empty_type>)
170  equality &= lhs.cursor_ == rhs.cursor_;
171  if constexpr (!std::is_same_v<reference_id_type, detail::empty_type>)
172  equality &= lhs.reference_id_ == rhs.reference_id_;
173  if constexpr (!std::is_same_v<reference_begin_position_type, detail::empty_type>)
174  equality &= lhs.reference_begin_position_ == rhs.reference_begin_position_;
175 
176  return equality;
177  }
178 
180  friend bool operator!=(search_result const & lhs, search_result const & rhs) noexcept
181  {
182  return !(lhs == rhs);
183  }
185 };
186 
194 template <typename char_t, typename search_result_t>
195  requires detail::is_type_specialisation_of_v<std::remove_cvref_t<search_result_t>, search_result>
196 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, search_result_t && result)
197 {
198  using result_type_list = detail::transfer_template_args_onto_t<std::remove_cvref_t<search_result_t>, type_list>;
199 
200  stream << "<";
201  if constexpr (!std::same_as<list_traits::at<0, result_type_list>, detail::empty_type>)
202  stream << "query_id:" << result.query_id();
203  if constexpr (!std::same_as<list_traits::at<1, result_type_list>, detail::empty_type>)
204  stream << ", index cursor is present";
205  if constexpr (!std::same_as<list_traits::at<2, result_type_list>, detail::empty_type>)
206  stream << ", reference_id:" << result.reference_id();
207  if constexpr (!std::same_as<list_traits::at<3, result_type_list>, detail::empty_type>)
208  stream << ", reference_pos:" << result.reference_begin_position();
209  stream << ">";
210 
211  return stream;
212 }
213 
214 } // namespace seqan3
Provides the seqan3::bi_fm_index_cursor for searching in the bidirectional seqan3::bi_fm_index.
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:78
The <concepts> header from C++20's standard library.
Provides seqan3::configuration and utility functions.
Provides seqan3::debug_stream and related types.
Provides seqan3::detail::empty_type.
Provides the seqan3::fm_index_cursor for searching in the unidirectional seqan3::fm_index.
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
requires detail::debug_stream_range_guard< alignment_matrix_t > &&detail::matrix< alignment_matrix_t > debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &s, alignment_matrix_t &&matrix)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: debug_matrix.hpp:496
SeqAn specific customisations in the standard namespace.
T operator!=(T... args)
Provides the concept for seqan3::detail::sdsl_index.
Type that contains multiple types.
Definition: type_list.hpp:29
Provides type traits for working with templates.