SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
max_error.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 <range/v3/numeric/accumulate.hpp>
17 
24 #include <seqan3/std/algorithm>
25 
26 namespace seqan3::search_cfg
27 {
35 template <typename ...errors_t>
37  requires sizeof...(errors_t) <= 4 &&
38  ((detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, total> ||
39  detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, substitution> ||
40  detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, deletion> ||
41  detail::is_type_specialisation_of_v<std::remove_reference_t<errors_t>, insertion>) && ...)
43 class max_error : public pipeable_config_element<max_error<errors_t...>, std::array<uint8_t, 4>>
44 {
47 
49  template <typename ..._errors_t>
50  static constexpr bool check_consistency(_errors_t ...errors)
51  {
52  if constexpr (sizeof...(errors) < 2)
53  {
54  return true;
55  }
56  else
57  {
58  return [] (auto head, auto ...tail) constexpr
59  {
60  using head_t = decltype(head);
61  if constexpr (((head_t::_id != decltype(tail)::_id) && ...))
62  return check_consistency(tail...);
63  else
64  return false;
65  }(errors...);
66  }
67  }
68 
69  static_assert(check_consistency(errors_t{}...),
70  "You may not use the same error specifier more than once.");
71 
72 public:
73 
76  static constexpr detail::search_config_id id{detail::search_config_id::max_error};
77 
79 
83  constexpr max_error() noexcept = default;
84  constexpr max_error(max_error const &) noexcept = default;
85  constexpr max_error(max_error &&) noexcept = default;
86  constexpr max_error & operator=(max_error const &) noexcept = default;
87  constexpr max_error & operator=(max_error &&) noexcept = default;
88  ~max_error() noexcept = default;
89 
112  constexpr max_error(errors_t && ...errors) noexcept
114  requires sizeof...(errors_t) > 0
116  : base_t{}
117  {
118  detail::for_each([this](auto e)
119  {
121  }, std::forward<errors_t>(errors)...);
122 
123  // Only total is set so we set all other errors to the total limit.
124  if constexpr (((std::remove_reference_t<errors_t>::_id() == 0) || ...) && sizeof...(errors) == 1)
125  {
126  std::ranges::fill(base_t::value | views::slice(1, 4), base_t::value[0]);
127  } // otherwise if total is not set but any other field is set than use total as the sum of all set errors.
128  else if constexpr (!((std::remove_reference_t<errors_t>::_id() == 0) || ...) && sizeof...(errors) > 0)
129  {
130  base_t::value[0] = std::min(static_cast<uint8_t>(255), ranges::accumulate(base_t::value | views::slice(1, 4),
131  static_cast<uint8_t>(0)));
132  }
133  }
135 };
136 
144 
146 template <typename ...errors_t>
147 max_error(errors_t && ...) -> max_error<remove_cvref_t<errors_t>...>;
149 
150 } // namespace seqan3::search_cfg
Provides the error types for maximum number of errors.
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
Provides compatibility matrix for search configurations.
Adds pipe interface to configuration elements.
Definition: pipeable_config_element.hpp:30
A special sub namespace for the search configurations.
std::array< uint8_t, 4 > value
The stored config value.
Definition: pipeable_config_element.hpp:33
~max_error() noexcept=default
Destructor.
T min(T... args)
constexpr max_error() noexcept=default
Default constructor.
Provides seqan3::pipeable_config_element.
constexpr max_error & operator=(max_error const &) noexcept=default
Copy assignment.
constexpr max_error(errors_t &&...errors) noexcept
Constructs the object from a set of error specifiers.
Definition: max_error.hpp:112
Adaptations of algorithms from the Ranges TS.
Provides seqan3::views::slice.
Provides seqan3::detail::configuration and utility functions.
A configuration element for the maximum number of errors across all error types (mismatches, insertions, deletions). This is an upper bound of errors independent from error numbers of specific error types.
Definition: max_error.hpp:43
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:141