SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alphabet_base.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <cassert>
13#include <concepts>
14#include <type_traits>
15
18
19namespace seqan3
20{
21
52template <typename derived_type, size_t size, typename char_t = char>
54{
55protected:
56 static_assert(size != 0, "alphabet size must be >= 1"); // == 1 is handled below in separate specialisation
57
70
79
80public:
84 constexpr alphabet_base() noexcept = default;
85 constexpr alphabet_base(alphabet_base const &) noexcept = default;
86 constexpr alphabet_base(alphabet_base &&) noexcept = default;
87 constexpr alphabet_base & operator=(alphabet_base const &) noexcept = default;
88 constexpr alphabet_base & operator=(alphabet_base &&) noexcept = default;
89 ~alphabet_base() noexcept = default;
90
92
112 constexpr char_type to_char() const noexcept
113 requires (!std::same_as<char_t, void>)
114 {
115 return derived_type::rank_to_char(rank);
116 }
117
134 constexpr rank_type to_rank() const noexcept
135 {
136 return rank;
137 }
139
160 constexpr derived_type & assign_char(char_type const chr) noexcept
161 requires (!std::same_as<char_t, void>)
162 {
163 rank = derived_type::char_to_rank(chr);
164 return static_cast<derived_type &>(*this);
165 }
166
184 constexpr derived_type & assign_rank(rank_type const c) noexcept
185 {
186 assert(static_cast<size_t>(c) < static_cast<size_t>(alphabet_size));
187 rank = c;
188 return static_cast<derived_type &>(*this);
189 }
191
197
200
205 friend constexpr bool operator==(derived_type const lhs, derived_type const rhs) noexcept
206 {
207 return seqan3::to_rank(lhs) == seqan3::to_rank(rhs);
208 }
209
214 friend constexpr bool operator!=(derived_type const lhs, derived_type const rhs) noexcept
215 {
216 return seqan3::to_rank(lhs) != seqan3::to_rank(rhs);
217 }
218
223 friend constexpr bool operator<(derived_type const lhs, derived_type const rhs) noexcept
224 {
225 return seqan3::to_rank(lhs) < seqan3::to_rank(rhs);
226 }
227
232 friend constexpr bool operator>(derived_type const lhs, derived_type const rhs) noexcept
233 {
234 return seqan3::to_rank(lhs) > seqan3::to_rank(rhs);
235 }
236
241 friend constexpr bool operator<=(derived_type const lhs, derived_type const rhs) noexcept
242 {
243 return seqan3::to_rank(lhs) <= seqan3::to_rank(rhs);
244 }
245
250 friend constexpr bool operator>=(derived_type const lhs, derived_type const rhs) noexcept
251 {
252 return seqan3::to_rank(lhs) >= seqan3::to_rank(rhs);
253 }
255
256private:
259};
260
261} // namespace seqan3
Core alphabet concept and free function/type trait wrappers.
A CRTP-base that makes defining a custom alphabet easier.
Definition alphabet_base.hpp:54
friend constexpr bool operator<(derived_type const lhs, derived_type const rhs) noexcept
Checks whether the letter lhs is smaller than rhs.
Definition alphabet_base.hpp:223
friend constexpr bool operator==(derived_type const lhs, derived_type const rhs) noexcept
Checks whether the letters lhs and rhs are equal.
Definition alphabet_base.hpp:205
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
constexpr alphabet_base() noexcept=default
Defaulted.
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
friend constexpr bool operator>=(derived_type const lhs, derived_type const rhs) noexcept
Checks whether the letter lhs is bigger than or equal to rhs.
Definition alphabet_base.hpp:250
friend constexpr bool operator>(derived_type const lhs, derived_type const rhs) noexcept
Checks whether the letter lhs is greater than rhs.
Definition alphabet_base.hpp:232
static constexpr detail::min_viable_uint_t< size > alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition alphabet_base.hpp:196
friend constexpr bool operator<=(derived_type const lhs, derived_type const rhs) noexcept
Checks whether the letter lhs is smaller than or equal to rhs.
Definition alphabet_base.hpp:241
friend constexpr bool operator!=(derived_type const lhs, derived_type const rhs) noexcept
Checks whether the letters lhs and rhs are unequal.
Definition alphabet_base.hpp:214
constexpr char_type to_char() const noexcept
Return the letter as a character of char_type.
Definition alphabet_base.hpp:112
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
rank_type rank
The value of the alphabet letter is stored as the rank.
Definition alphabet_base.hpp:258
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
Provides metaprogramming utilities for integer types.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
Hide me