SeqAn3
seqan3::alphabet_base< derived_type, size, char_t > Class Template Reference

A CRTP-base that makes defining a custom alphabet easier. More...

#include <seqan3/alphabet/detail/alphabet_base.hpp>

Inheritance diagram for seqan3::alphabet_base< derived_type, size, char_t >:
[legend]

Public Types

Member types
using char_type = char_t
 The type of the alphabet when converted to char (e.g. via to_char()).
 
using rank_type = detail::min_viable_uint_t< size - 1 >
 The type of the alphabet when represented as a number (e.g. via to_rank()).
 

Public Member Functions

Constructors, destructor and assignment
constexpr alphabet_base () noexcept
 
constexpr alphabet_base (alphabet_base const &)=default
 
constexpr alphabet_base (alphabet_base &&)=default
 
constexpr alphabet_baseoperator= (alphabet_base const &)=default
 
constexpr alphabet_baseoperator= (alphabet_base &&)=default
 
 ~alphabet_base ()=default
 
Read functions
constexpr char_type to_char () const noexcept
 Return the letter as a character of char_type. More...
 
constexpr rank_type to_rank () const noexcept
 Return the letter's numeric value (rank in the alphabet). More...
 
Write functions
constexpr derived_type & assign_char (std::conditional_t< std::Same< char_type, void >, char, char_type > const c) noexcept
 Assign from a character. More...
 
constexpr derived_type & assign_rank (rank_type const c) noexcept
 Assign from a numeric value. More...
 

Static Public Attributes

static detail::min_viable_uint_t< size > constexpr value_size = size
 The size of the alphabet, i.e. the number of different values it can take.
 

Friends

Comparison operators
constexpr bool operator== (derived_type const &lhs, derived_type const &rhs) noexcept
 
constexpr bool operator!= (derived_type const &lhs, derived_type const &rhs) noexcept
 
constexpr bool operator< (derived_type const &lhs, derived_type const &rhs) noexcept
 
constexpr bool operator> (derived_type const &lhs, derived_type const &rhs) noexcept
 
constexpr bool operator<= (derived_type const &lhs, derived_type const &rhs) noexcept
 
constexpr bool operator>= (derived_type const &lhs, derived_type const &rhs) noexcept
 

Detailed Description

template<typename derived_type, size_t size, typename char_t = char>
class seqan3::alphabet_base< derived_type, size, char_t >

A CRTP-base that makes defining a custom alphabet easier.

Template Parameters
derived_typeThe CRTP parameter type.
sizeThe size of the alphabet.
char_tThe character type of the alphabet (set this to void when defining just a seqan3::semi_alphabet_concept).

You can use this class to define your own alphabet, but types are not required to be based on it to model seqan3::alphabet_concept, it is purely a way to avoid code duplication.

The base class represents the alphabet value as the rank and automatically deduces the rank type from the size, it further defines all required member functions and types; the derived type needs to define only the following two tables as static member variables:

  • static std::array<char_type, value_size> constexpr rank_to_char that defines for every possible rank value the corresponding char value.
  • static std::array<rank_type, 256> constexpr char_to_rank that defines for every possible character value the corresponding rank value.

Example

This creates an alphabet called ab which has size two and the two letters 'A' and 'B':

class ab : public alphabet_base<ab, 2>
{
private:
// map 0 -> A and 1 -> B
static std::array<char_type, value_size> constexpr rank_to_char{'A', 'B'};
// map every letter to rank zero, except Bs
static std::array<rank_type, 256> constexpr char_to_rank
{
// initialise with an immediately evaluated lambda expression:
[]()
{
std::array<rank_type, 256> ret{}; // initialise all values with 0 / 'A'
// only 'b' and 'B' result in rank 1
ret['b'] = 1;
ret['B'] = 1;
return ret;
}()
};
// make the base class a friend so it can access the tables:
friend alphabet_base<ab, 2>;
};
static_assert(alphabet_concept<ab>);

Member Function Documentation

◆ assign_char()

template<typename derived_type, size_t size, typename char_t = char>
constexpr derived_type& seqan3::alphabet_base< derived_type, size, char_t >::assign_char ( std::conditional_t< std::Same< char_type, void >, char, char_type > const  c)
inlinenoexcept

Assign from a character.

Satisfies the seqan3::alphabet_concept::assign_char() requirement via the seqan3::assign_char() wrapper.

Complexity

Constant.

Exceptions

Guaranteed not to throw.

◆ assign_rank()

template<typename derived_type, size_t size, typename char_t = char>
constexpr derived_type& seqan3::alphabet_base< derived_type, size, char_t >::assign_rank ( rank_type const  c)
inlinenoexcept

Assign from a numeric value.

Satisfies the seqan3::semi_alphabet_concept::assign_rank() requirement via the seqan3::assign_rank() wrapper.

Complexity

Constant.

Exceptions

Guaranteed not to throw.

◆ to_char()

template<typename derived_type, size_t size, typename char_t = char>
constexpr char_type seqan3::alphabet_base< derived_type, size, char_t >::to_char ( ) const
inlinenoexcept

Return the letter as a character of char_type.

Satisfies the seqan3::alphabet_concept::to_char() requirement via the seqan3::to_char() wrapper.

Complexity

Constant.

Exceptions

Guaranteed not to throw.

◆ to_rank()

template<typename derived_type, size_t size, typename char_t = char>
constexpr rank_type seqan3::alphabet_base< derived_type, size, char_t >::to_rank ( ) const
inlinenoexcept

Return the letter's numeric value (rank in the alphabet).

Satisfies the seqan3::semi_alphabet_concept::to_rank() requirement via the to_rank() wrapper.

Complexity

Constant.

Exceptions

Guaranteed not to throw.


The documentation for this class was generated from the following file: