BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
cigar_op.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <bio/alphabet/base.hpp>
17
18// ------------------------------------------------------------------
19// cigar_op
20// ------------------------------------------------------------------
21
22namespace bio::alphabet
23{
24
58class cigar_op : public base<cigar_op, 10, char>
59{
60private:
63
65 friend base_t;
67
68public:
72 constexpr cigar_op() noexcept = default;
73 constexpr cigar_op(cigar_op const &) noexcept = default;
74 constexpr cigar_op(cigar_op &&) noexcept = default;
75 constexpr cigar_op & operator=(cigar_op const &) noexcept = default;
76 constexpr cigar_op & operator=(cigar_op &&) noexcept = default;
77 ~cigar_op() noexcept = default;
79
80protected:
82
84 static constexpr std::array<char_type, alphabet_size>
85 rank_to_char{'M', 'I', 'D', 'N', 'S', 'H', 'P', '=', 'X', 'B'};
86
88 static constexpr std::array<rank_type, 256> char_to_rank = []() constexpr
89 {
91
92 // reverse mapping for characters
93 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
94 {
95 ret[rank_to_char[rnk]] = rnk;
96 }
97
98 return ret;
99 }();
100};
101
102} // namespace bio::alphabet
103
104// ------------------------------------------------------------------
105// literals
106// ------------------------------------------------------------------
107
108namespace bio::alphabet
109{
110
111inline namespace literals
112{
113
122consteval cigar_op operator""_cigar_op(char const c)
123{
124 if (!char_is_valid_for<cigar_op>(c))
125 throw std::invalid_argument{"Illegal character in character literal."};
126 return cigar_op{}.assign_char(c);
127}
129} // namespace literals
130
131} // namespace bio::alphabet
Provides bio::alphabet::base.
A CRTP-base that makes defining a custom alphabet easier.
Definition: base.hpp:55
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
The cigar operation alphabet..
Definition: cigar_op.hpp:59
constexpr cigar_op() noexcept=default
Defaulted.
The alphabet module's namespace.
Definition: aa10li.hpp:23