Loading...
Searching...
No Matches
alphabet_base.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <cassert>
#include <concepts>
#include <type_traits>
#include <seqan3/alphabet/concept.hpp>
#include <seqan3/utility/detail/integer_traits.hpp>
namespace seqan3
{
template <typename derived_type, size_t size, typename char_t = char>
class alphabet_base
{
protected:
static_assert(size != 0, "alphabet size must be >= 1"); // == 1 is handled below in separate specialisation
using char_type = std::conditional_t<std::same_as<char_t, void>, char, char_t>;
using rank_type = detail::min_viable_uint_t<size - 1>;
public:
constexpr alphabet_base() noexcept = default;
constexpr alphabet_base(alphabet_base const &) noexcept = default;
constexpr alphabet_base(alphabet_base &&) noexcept = default;
constexpr alphabet_base & operator=(alphabet_base const &) noexcept = default;
constexpr alphabet_base & operator=(alphabet_base &&) noexcept = default;
~alphabet_base() noexcept = default;
constexpr char_type to_char() const noexcept
requires (!std::same_as<char_t, void>)
{
return derived_type::rank_to_char(rank);
}
constexpr rank_type to_rank() const noexcept
{
return rank;
}
constexpr derived_type & assign_char(char_type const chr) noexcept
requires (!std::same_as<char_t, void>)
{
rank = derived_type::char_to_rank(chr);
return static_cast<derived_type &>(*this);
}
constexpr derived_type & assign_rank(rank_type const c) noexcept
{
assert(static_cast<size_t>(c) < static_cast<size_t>(alphabet_size));
rank = c;
return static_cast<derived_type &>(*this);
}
static constexpr detail::min_viable_uint_t<size> alphabet_size = size;
friend constexpr bool operator==(derived_type const lhs, derived_type const rhs) noexcept
{
return seqan3::to_rank(lhs) == seqan3::to_rank(rhs);
}
friend constexpr bool operator!=(derived_type const lhs, derived_type const rhs) noexcept
{
return seqan3::to_rank(lhs) != seqan3::to_rank(rhs);
}
friend constexpr bool operator<(derived_type const lhs, derived_type const rhs) noexcept
{
return seqan3::to_rank(lhs) < seqan3::to_rank(rhs);
}
friend constexpr bool operator>(derived_type const lhs, derived_type const rhs) noexcept
{
return seqan3::to_rank(lhs) > seqan3::to_rank(rhs);
}
friend constexpr bool operator<=(derived_type const lhs, derived_type const rhs) noexcept
{
return seqan3::to_rank(lhs) <= seqan3::to_rank(rhs);
}
friend constexpr bool operator>=(derived_type const lhs, derived_type const rhs) noexcept
{
return seqan3::to_rank(lhs) >= seqan3::to_rank(rhs);
}
private:
rank_type rank;
};
} // namespace seqan3
concept.hpp
Core alphabet concept and free function/type trait wrappers.
cassert
seqan3::alphabet_base::operator<
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
seqan3::alphabet_base::operator==
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
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
seqan3::alphabet_base::alphabet_base
constexpr alphabet_base() noexcept=default
Defaulted.
seqan3::alphabet_base::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
seqan3::alphabet_base::operator>=
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
seqan3::alphabet_base::operator>
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
seqan3::alphabet_base::rank_type
detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition alphabet_base.hpp:77
seqan3::alphabet_base< derived_type, size, char >::alphabet_size
static constexpr detail::min_viable_uint_t< size > alphabet_size
Definition alphabet_base.hpp:196
seqan3::alphabet_base::operator<=
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
seqan3::alphabet_base::operator!=
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
seqan3::alphabet_base< derived_type, size, char >::to_char
constexpr char_type to_char() const noexcept
Definition alphabet_base.hpp:112
seqan3::alphabet_base::char_type
std::conditional_t< std::same_as< char_t, void >, char, char_t > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition alphabet_base.hpp:69
seqan3::alphabet_base::assign_rank
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
std::conditional_t
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
integer_traits.hpp
Provides metaprogramming utilities for integer types.
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std
SeqAn specific customisations in the standard namespace.
type_traits
Hide me