SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
search_result.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 
14 #pragma once
15 
16 #include <seqan3/std/concepts>
17 #include <exception>
18 
24 
25 namespace seqan3::detail
26 {
27 // forward declaration
28 template <typename search_configuration_t>
29 #if !SEQAN3_WORKAROUND_GCC_93467
30  requires is_type_specialisation_of_v<search_configuration_t, configuration>
31 #endif // !SEQAN3_WORKAROUND_GCC_93467
32 struct policy_search_result_builder;
33 } // namespace seqan3::detail
34 
35 namespace seqan3
36 {
37 
65 template <typename query_id_type,
66  typename cursor_type,
67  typename reference_id_type,
68  typename reference_begin_position_type>
70  requires (std::integral<query_id_type> || std::same_as<query_id_type, detail::empty_type>) &&
71  (fm_index_cursor_specialisation<cursor_type> || std::same_as<cursor_type, detail::empty_type>) &&
72  (std::integral<reference_id_type> || std::same_as<reference_id_type, detail::empty_type>) &&
73  (std::integral<reference_begin_position_type> || std::same_as<reference_begin_position_type,
74  detail::empty_type>)
77 {
78 private:
80  query_id_type query_id_{};
82  cursor_type cursor_{};
84  reference_id_type reference_id_{};
86  reference_begin_position_type reference_begin_position_{};
87 
88  // Grant the policy access to private constructors.
89  template <typename search_configuration_t>
90  #if !SEQAN3_WORKAROUND_GCC_93467
91  requires detail::is_type_specialisation_of_v<search_configuration_t, configuration>
94  #endif // !SEQAN3_WORKAROUND_GCC_93467
95  friend struct detail::policy_search_result_builder;
96 
97 public:
101  search_result() = default;
102  search_result(search_result const &) = default;
103  search_result(search_result &&) = default;
104  search_result & operator=(search_result const &) = default;
106  ~search_result() = default;
107 
113  constexpr auto query_id() const noexcept
115  {
116  static_assert(!std::same_as<query_id_type, detail::empty_type>,
117  "You tried to access the query_id but it was not selected in the output "
118  "configuration of the search.");
119 
120  return query_id_;
121  }
122 
127  constexpr auto index_cursor() const noexcept(!(std::same_as<cursor_type, detail::empty_type>))
128  {
129  static_assert(!std::same_as<cursor_type, detail::empty_type>,
130  "You tried to access the index cursor but it was not selected in the output "
131  "configuration of the search.");
132 
133  return cursor_;
134  }
135 
142  constexpr auto reference_id() const noexcept(!(std::same_as<reference_id_type, detail::empty_type>))
143  {
144  static_assert(!std::same_as<reference_id_type, detail::empty_type>,
145  "You tried to access the reference id but it was not selected in the output "
146  "configuration of the search.");
147 
148  return reference_id_;
149  }
150 
152  constexpr auto reference_begin_position() const
153  noexcept(!(std::same_as<reference_begin_position_type, detail::empty_type>))
154  {
155  static_assert(!std::same_as<reference_begin_position_type, detail::empty_type>,
156  "You tried to access the reference begin position but it was not selected in the "
157  "output configuration of the search.");
158 
159  return reference_begin_position_;
160  }
162 
166  friend bool operator==(search_result const & lhs, search_result const & rhs) noexcept
168  {
169  bool equality = lhs.query_id_ == rhs.query_id_;
170  if constexpr (!std::is_same_v<cursor_type, detail::empty_type>)
171  equality &= lhs.cursor_ == rhs.cursor_;
172  if constexpr (!std::is_same_v<reference_id_type, detail::empty_type>)
173  equality &= lhs.reference_id_ == rhs.reference_id_;
174  if constexpr (!std::is_same_v<reference_begin_position_type, detail::empty_type>)
175  equality &= lhs.reference_begin_position_ == rhs.reference_begin_position_;
176 
177  return equality;
178  }
179 
181  friend bool operator!=(search_result const & lhs, search_result const & rhs) noexcept
182  {
183  return !(lhs == rhs);
184  }
186 };
187 
195 template <typename char_t, typename search_result_t>
197  requires detail::is_type_specialisation_of_v<std::remove_cvref_t<search_result_t>, search_result>
199 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, search_result_t && result)
200 {
201  using result_type_list = detail::transfer_template_args_onto_t<std::remove_cvref_t<search_result_t>, type_list>;
202 
203  stream << "<";
204  if constexpr (!std::same_as<list_traits::at<0, result_type_list>, detail::empty_type>)
205  stream << "query_id:" << result.query_id();
206  if constexpr (!std::same_as<list_traits::at<1, result_type_list>, detail::empty_type>)
207  stream << ", index cursor is present";
208  if constexpr (!std::same_as<list_traits::at<2, result_type_list>, detail::empty_type>)
209  stream << ", reference_id:" << result.reference_id();
210  if constexpr (!std::same_as<list_traits::at<3, result_type_list>, detail::empty_type>)
211  stream << ", reference_pos:" << result.reference_begin_position();
212  stream << ">";
213 
214  return stream;
215 }
216 
217 } // namespace seqan3
exception
seqan3::type_list
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:31
seqan3::search_result
The result class generated by the seqan3::seach algorithm.
Definition: search_result.hpp:77
configuration.hpp
Provides seqan3::detail::configuration and utility functions.
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
seqan3::search_result::index_cursor
constexpr auto index_cursor() const noexcept(!(std::same_as< cursor_type, detail::empty_type >))
Returns the index cursor pointing to the suffix array range where the query was found.
Definition: search_result.hpp:127
seqan3::search_result::search_result
search_result(search_result const &)=default
Defaulted.
concepts
The Concepts library.
seqan3::search_result::operator=
search_result & operator=(search_result &&)=default
Defaulted.
seqan3::search_result::operator=
search_result & operator=(search_result const &)=default
Defaulted.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::search_result::search_result
search_result()=default
Defaulted.
seqan3::search_result::reference_id
constexpr auto reference_id() const noexcept(!(std::same_as< reference_id_type, detail::empty_type >))
Returns the reference id where the query was found.
Definition: search_result.hpp:142
seqan3::search_result::~search_result
~search_result()=default
empty_type.hpp
Provides seqan3::detail::empty_type.
std
SeqAn specific customisations in the standard namespace.
seqan3::operator<<
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: debug_stream_alignment.hpp:103
concept.hpp
Provides the concepts for seqan3::fm_index and seqan3::bi_fm_index and its traits and cursors.
seqan3::search_result::operator!=
friend bool operator!=(search_result const &lhs, search_result const &rhs) noexcept
Returns whether lhs and rhs are not the same.
Definition: search_result.hpp:181
seqan3::search_result::reference_begin_position
constexpr auto reference_begin_position() const noexcept(!(std::same_as< reference_begin_position_type, detail::empty_type >))
Returns the reference begin positions where the query was found in the reference text (at reference i...
Definition: search_result.hpp:152
seqan3::pack_traits::at
typename decltype(detail::at< idx, pack_t... >())::type at
Return the type at given index from the type pack.
Definition: traits.hpp:221
fm_index_cursor_specialisation
Concept for unidirectional FM index cursors.
seqan3::search_result::search_result
search_result(search_result &&)=default
Defaulted.