SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
uint.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 
26 #pragma once
27 
30 
31 namespace seqan3::detail
32 {
36 template <typename type>
37 constexpr bool is_uint_adaptation_v = std::same_as<type, uint8_t> ||
38  std::same_as<type, uint16_t> ||
39  std::same_as<type, uint32_t>;
40 } // namespace seqan3::detail
41 
42 namespace seqan3::custom
43 {
44 
49 template <typename uint_type>
51  requires seqan3::detail::is_uint_adaptation_v<uint_type>
53 struct alphabet<uint_type>
54 {
56  static constexpr auto alphabet_size =
57  detail::min_viable_uint_t<detail::size_in_values_v<uint_type>>{detail::size_in_values_v<uint_type>};
58 
63  static constexpr auto to_char(uint_type const intgr) noexcept
64  {
65  if constexpr (std::same_as<uint_type, uint8_t>)
66  return static_cast<char>(intgr);
67  else if constexpr (std::same_as<uint_type, uint16_t>)
68  return static_cast<char16_t>(intgr);
69  else
70  return static_cast<char32_t>(intgr);
71  }
72 
77  static constexpr uint_type to_rank(uint_type const intgr) noexcept
78  {
79  return intgr;
80  }
81 
87  static constexpr uint_type & assign_char_to(decltype(to_char(uint_type{})) const chr, uint_type & intgr) noexcept
88  {
89  return intgr = chr;
90  }
91 
97  static constexpr uint_type & assign_rank_to(uint_type const intgr2, uint_type & intgr) noexcept
98  {
99  return intgr = intgr2;
100  }
101 };
102 
103 } // namespace seqan3::custom
seqan3::custom::alphabet
A type that can be specialised to provide customisation point implementations so that third party typ...
Definition: concept.hpp:48
seqan3::custom::alphabet< uint_type >::assign_rank_to
static constexpr uint_type & assign_rank_to(uint_type const intgr2, uint_type &intgr) noexcept
Assign a rank to to the uint (same as calling =).
Definition: uint.hpp:97
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:321
seqan3::custom::alphabet< uint_type >::to_rank
static constexpr uint_type to_rank(uint_type const intgr) noexcept
Converting uint to rank is a no-op (it will just return the value you pass in).
Definition: uint.hpp:77
seqan3::custom::alphabet< uint_type >::to_char
static constexpr auto to_char(uint_type const intgr) noexcept
Converting uint to char casts to a character type of same size.
Definition: uint.hpp:63
int_types.hpp
Provides metaprogramming utilities for integer types.
seqan3::custom::alphabet< uint_type >::assign_char_to
static constexpr uint_type & assign_char_to(decltype(to_char(uint_type{})) const chr, uint_type &intgr) noexcept
Assign from a character type via implicit or explicit cast.
Definition: uint.hpp:87
std::conditional_t
seqan3::alphabet_size
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:707
concept.hpp
Core alphabet concept and free function/type trait wrappers.
seqan3::custom
A namespace for third party and standard library specialisations of SeqAn customisation points.
Definition: char.hpp:44