SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
align_config_aligned_ends.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 <type_traits>
17 #include <tuple>
18 
24 
25 namespace seqan3
26 {
27 
40 template <typename value_t,
47 {
48 protected:
49 
51  template <typename ...ends_t>
52  friend class end_gaps;
53 
55  static constexpr bool is_static = _is_static;
57  static constexpr bool static_value = _value;
58 
59 public:
60 
62  constexpr bool operator()() const noexcept
63  {
64  return value;
65  }
66 
68  value_t value{};
69 };
70 
71 // ----------------------------------------------------------------------------
72 // front_end_first
73 // ----------------------------------------------------------------------------
74 
92 template <typename value_t>
94 {
97  static constexpr std::integral_constant<uint8_t, 0> id{};
98 };
99 
104 template <typename value_t>
108 
109 // ----------------------------------------------------------------------------
110 // back_end_first
111 // ----------------------------------------------------------------------------
112 
123 template <typename value_t>
125 {
128  static constexpr std::integral_constant<uint8_t, 1> id{};
129 };
130 
135 template <typename value_t>
139 
140 // ----------------------------------------------------------------------------
141 // front_end_second
142 // ----------------------------------------------------------------------------
143 
154 template <typename value_t>
156 {
159  static constexpr std::integral_constant<uint8_t, 2> id{};
160 };
161 
166 template <typename value_t>
170 
171 // ----------------------------------------------------------------------------
172 // back_end_second
173 // ----------------------------------------------------------------------------
174 
185 template <typename value_t>
187 {
190  static constexpr std::integral_constant<uint8_t, 3> id{};
191 };
192 
197 template <typename value_t>
201 
202 // ----------------------------------------------------------------------------
203 // end_gaps
204 // ----------------------------------------------------------------------------
205 
244 template <typename ...ends_t>
246  requires sizeof...(ends_t) <= 4 &&
247  ((detail::is_type_specialisation_of_v<ends_t, front_end_first> ||
248  detail::is_type_specialisation_of_v<ends_t, back_end_first> ||
249  detail::is_type_specialisation_of_v<ends_t, front_end_second> ||
250  detail::is_type_specialisation_of_v<ends_t, back_end_second>) && ...)
252 class end_gaps
253 {
255  template <typename ..._ends_t>
256  static constexpr bool check_consistency(_ends_t ...ends)
257  {
258  if constexpr (sizeof...(ends) < 2)
259  {
260  return true;
261  }
262  else
263  {
264  return [] (auto head, auto ...tail) constexpr
265  {
266  using head_t = decltype(head);
267  if constexpr (((head_t::id != decltype(tail)::id) && ...))
268  return check_consistency(tail...);
269  else
270  return false;
271  }(ends...);
272  }
273  }
274 
275  static_assert(check_consistency(ends_t{}...),
276  "You may not use the same end_gap specifier more than once.");
277 
278 public:
283  constexpr end_gaps() noexcept
285  {
286  [[maybe_unused]] auto dummy = ((values[std::remove_reference_t<ends_t>::id()] =
288  }
289 
290  constexpr end_gaps(end_gaps const &) noexcept = default;
291  constexpr end_gaps(end_gaps &&) noexcept = default;
292  constexpr end_gaps & operator=(end_gaps const &) noexcept = default;
293  constexpr end_gaps & operator=(end_gaps &&) noexcept = default;
294  ~end_gaps() noexcept = default;
295 
297  constexpr end_gaps(ends_t const ...args) noexcept
298  requires sizeof...(ends_t) > 0
299  {
300  detail::for_each([this](auto e)
301  {
302  values[remove_cvref_t<decltype(e)>::id()] = e();
303  }, args...);
304  }
305  //\!}
306 
322  constexpr bool operator[](size_t const pos) const noexcept
323  {
324  assert(pos < values.size());
325  return values[pos];
326  }
327 
340  template <size_t pos>
341  static constexpr bool get_static() noexcept
342  {
343  static_assert(is_static_array[pos],
344  "You may not access an element that was not set in a core constant expression.");
345  return get<pos>(static_values);
346  }
348 
361  template <size_t pos>
362  static constexpr bool is_static() noexcept
363  {
364  return get<pos>(is_static_array);
365  }
367 
368 private:
369 
371  std::array<bool, 4> values{false, false, false, false};
372 
374  static constexpr std::array<bool, 4> is_static_array
375  {
376  [](auto ...ends) constexpr
377  {
378  std::array<bool, 4> tmp{false, false, false, false};
379  detail::for_each([&tmp](auto v)
380  {
381  tmp[decltype(v)::id()] = decltype(v)::is_static;
382  }, ends...);
383  return tmp;
384  }(ends_t{}...)
385  };
386 
388  static constexpr std::array<bool, 4> static_values
389  {
390  [](auto ...ends) constexpr
391  {
392  std::array<bool, 4> tmp{false, false, false, false};
393  detail::for_each([&tmp](auto v)
394  {
395  tmp[decltype(v)::id()] = decltype(v)::static_value;
396  }, ends...);
397  return tmp;
398  }(ends_t{}...)
399  };
400 };
401 
410 template <typename ...ends_t>
411 end_gaps(ends_t const & ...) -> end_gaps<ends_t...>;
413 
414 // ----------------------------------------------------------------------------
415 // free_ends_all
416 // ----------------------------------------------------------------------------
417 
439 inline constexpr end_gaps free_ends_all{front_end_first<std::true_type>{},
443 
444 // ----------------------------------------------------------------------------
445 // free_ends_none
446 // ----------------------------------------------------------------------------
447 
461 inline constexpr end_gaps free_ends_none{front_end_first<std::false_type>{},
465 
466 // ----------------------------------------------------------------------------
467 // free_ends_first
468 // ----------------------------------------------------------------------------
469 
484 inline constexpr end_gaps free_ends_first{front_end_first<std::true_type>{},
488 
489 // ----------------------------------------------------------------------------
490 // free_ends_second
491 // ----------------------------------------------------------------------------
492 
507 inline constexpr end_gaps free_ends_second{front_end_first<std::false_type>{},
512 } // namespace seqan3
513 
515 {
516 
517 // ----------------------------------------------------------------------------
518 // aligned_ends
519 // ----------------------------------------------------------------------------
520 
543 template <typename end_gaps_t>
545  requires detail::is_type_specialisation_of_v<end_gaps_t, end_gaps>
547 struct aligned_ends : public pipeable_config_element<aligned_ends<end_gaps_t>, end_gaps_t>
548 {
551  static constexpr detail::align_config_id id{detail::align_config_id::aligned_ends};
552 };
553 
558 template <typename end_gaps_t>
562 
563 } // namespace seqan3::align_cfg
seqan3::end_gaps::operator[]
constexpr bool operator[](size_t const pos) const noexcept
Returns the value for the specifier at the given position.
Definition: align_config_aligned_ends.hpp:322
std::false_type
pack_algorithm.hpp
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
std::array::size
T size(T... args)
seqan3::front_end_second
The penalty configuration for aligning the front of the second sequence with a gap.
Definition: align_config_aligned_ends.hpp:155
std::ends
T ends(T... args)
seqan3::back_end_first
The penalty configuration for aligning the back of the first sequence with a gap.
Definition: align_config_aligned_ends.hpp:124
seqan3::end_gaps::end_gaps
constexpr end_gaps(ends_t const ...args) noexcept requires sizeof...(ends_t) > 0
Construction from at least one sequence end-gap specifier.
Definition: align_config_aligned_ends.hpp:297
basic.hpp
Provides various type traits on generic types.
seqan3::field::id
The identifier, usually a string.
seqan3::sequence_end_gap_specifier_base::static_value
static constexpr bool static_value
Holds the static value if the state is static.
Definition: align_config_aligned_ends.hpp:57
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
tuple
pipeable_config_element.hpp
Provides seqan3::pipeable_config_element.
seqan3::end_gaps::operator=
constexpr end_gaps & operator=(end_gaps const &) noexcept=default
Defaulted.
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
seqan3::end_gaps::get_static
static constexpr bool get_static() noexcept
Returns the static value for the specifier at the given position.
Definition: align_config_aligned_ends.hpp:341
seqan3::end_gaps::is_static
static constexpr bool is_static() noexcept
Returns whether a value at the given position was set statically.
Definition: align_config_aligned_ends.hpp:362
seqan3::end_gaps
Wraps the sequence end-gap specifiers and provides ordered access to the respective values.
Definition: align_config_aligned_ends.hpp:252
std::array< bool, 4 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::align_cfg
A special sub namespace for the alignment configurations.
Definition: align_config_aligned_ends.hpp:514
seqan3::pipeable_config_element
Adds pipe interface to configuration elements.
Definition: pipeable_config_element.hpp:30
seqan3::align_cfg::aligned_ends
The configuration for aligned sequence ends.
Definition: align_config_aligned_ends.hpp:547
seqan3::back_end_second
The penalty configuration for aligning the back of the second sequence with a gap.
Definition: align_config_aligned_ends.hpp:186
seqan3::sequence_end_gap_specifier_base
A mixin class which can maintain a static or a dynamic bool state.
Definition: align_config_aligned_ends.hpp:46
seqan3::sequence_end_gap_specifier_base::value
value_t value
The wrapped value.
Definition: align_config_aligned_ends.hpp:68
seqan3::end_gaps::~end_gaps
~end_gaps() noexcept=default
Defaulted.
std::remove_reference_t
seqan3::end_gaps::end_gaps
constexpr end_gaps() noexcept
Default constructor.
Definition: align_config_aligned_ends.hpp:284
std::remove_cv_t
seqan3::front_end_first
The penalty configuration for aligning the front of the first sequence with a gap.
Definition: align_config_aligned_ends.hpp:93
std::conditional_t
seqan3::sequence_end_gap_specifier_base::operator()
constexpr bool operator()() const noexcept
Returns the wrapped value.
Definition: align_config_aligned_ends.hpp:62
seqan3::sequence_end_gap_specifier_base::is_static
static constexpr bool is_static
Used to differentiate between static and dynamic state.
Definition: align_config_aligned_ends.hpp:55
detail.hpp
Provides some utility functions for the alignment configurations.