68class cigar :
public base<cigar, (1ul << 28) * size<cigar_op>,
73 using base_t = base<cigar, (1ul << 28) * size<cigar_op>, void>;
76 static constexpr size_t wasted_rank = 16ull - size<cigar_op>;
79 constexpr uint32_t to_num_rank() const noexcept { return rank >> 4; }
82 constexpr uint8_t to_op_rank() const noexcept { return rank & 0b1111; }
85 constexpr void assign_num_rank(uint32_t r) noexcept { rank = (rank & 0b1111) | (r << 4); }
88 constexpr void assign_op_rank(uint8_t r) noexcept { rank = (rank & ~0b1111) | r; }
91 template <typename alphabet_type>
92 class component_proxy : public proxy_base<component_proxy<alphabet_type>, alphabet_type>
96 using base_t = proxy_base<component_proxy<alphabet_type>, alphabet_type>;
105 using base_t::operator=;
111 component_proxy() = delete;
112 constexpr component_proxy(component_proxy const &) noexcept = default;
113 constexpr component_proxy(component_proxy &&) noexcept = default;
114 ~component_proxy() noexcept = default;
117 constexpr component_proxy(cigar & p) : parent{&p} {}
120 constexpr component_proxy & operator=(component_proxy const & rhs)
122 return assign_rank(rhs.to_rank());
127 constexpr component_proxy const & operator=(component_proxy const & rhs) const
129 return assign_rank(rhs.to_rank());
134 constexpr alphabet::rank_t<alphabet_type> to_rank() const noexcept
136 if constexpr (BIOCPP_IS_SAME(alphabet_type, uint32_t))
137 return parent->to_num_rank();
139 return parent->to_op_rank();
143 constexpr component_proxy & assign_rank(alphabet::rank_t<alphabet_type> const r) noexcept
145 if constexpr (BIOCPP_IS_SAME(alphabet_type, uint32_t))
146 parent->assign_num_rank(r);
148 parent->assign_op_rank(r);
153 constexpr component_proxy const & assign_rank(alphabet::rank_t<alphabet_type> const r) const noexcept
156 parent->assign_num_rank(r);
158 parent->assign_op_rank(r);
171 friend constexpr bool operator==(
cigar const lhs, component_proxy
const rhs)
noexcept
173 return get<alphabet_type>(lhs) ==
static_cast<alphabet_type
>(rhs);
177 friend constexpr auto operator<=>(cigar
const lhs, component_proxy
const rhs)
noexcept
179 return get<alphabet_type>(lhs) <=>
static_cast<alphabet_type
>(rhs);
188 constexpr cigar() noexcept = default;
191 constexpr
cigar & operator=(
cigar const &) noexcept = default;
199 explicit constexpr cigar(uint32_t
const count) noexcept : base_t{count << 4} {}
202 explicit constexpr cigar(
cigar_op const op) noexcept : base_t{op.to_rank()} {}
207 assign_num_rank(count);
214 assign_op_rank(op.to_rank());
240 constexpr uint32_t
to_rank() const noexcept {
return rank < 16u ? rank : rank - wasted_rank; }
243 explicit constexpr operator uint32_t()
const {
return to_num_rank(); }
246 explicit constexpr operator cigar_op()
const {
return alphabet::assign_rank_to(to_op_rank(),
cigar_op{}); }
263 auto [ptr, errc] =
std::to_chars(buffer.data(), buffer.data() + 10,
operator uint32_t());
279 ret.resize(s.
size());
305 assert(r < alphabet_size);
306 rank = r < 16u ? r : r + wasted_rank;
326 else if (num < 0 || num > (2u << 28))
332 assign_num_rank(num);
351 template <meta::one_of<u
int32_t, cigar_op> type>
352 friend constexpr type
get(
cigar const & l)
noexcept
354 return l.operator type();
365 template <meta::one_of<u
int32_t, cigar_op> type>
368 return component_proxy<type>{l};
379 template <
size_t index>
380 requires(index == 0 || index == 1)
381 friend constexpr auto get(
cigar const & l)
noexcept
383 if constexpr (index == 0)
384 return get<uint32_t>(l);
385 else if constexpr (index == 1)
386 return get<cigar_op>(l);
397 template <
size_t index>
398 requires(index == 0 || index == 1)
401 if constexpr (index == 0)
402 return get<uint32_t>(l);
403 else if constexpr (index == 1)
404 return get<cigar_op>(l);
409static_assert(
sizeof(cigar) == 4,
"Something wrong with binary layout of bio::alphabet::cigar. PLEASE REPORT BUG.");
422template <std::
size_t i>
423struct tuple_element<i,
bio::alphabet::cigar>
441#if __has_include(<fmt/format.h>)
443# include <fmt/format.h>
446struct fmt::formatter<
bio::alphabet::cigar> : fmt::formatter<std::string_view>
452 return fmt::formatter<std::string_view>::format(v, ctx);
Introduces the cigar_op alphabet.
A CRTP-base that makes defining a custom alphabet easier.
Definition: base.hpp:55
constexpr char_type to_char() const noexcept
Return the letter as a character of char_type.
Definition: base.hpp:104
The cigar operation alphabet..
Definition: cigar_op.hpp:59
The cigar semialphabet pairs a counter with a bio::alphabet::cigar_op letter.
Definition: cigar.hpp:70
constexpr cigar & assign_rank(uint32_t const r) noexcept
Assign from a numeric value.
Definition: cigar.hpp:303
std::string_view to_string(std::span< char > buffer) const noexcept
Convert to string representation.
Definition: cigar.hpp:260
friend constexpr type get(cigar const &l) noexcept
Get one of the two components from the cigar element (by type).
Definition: cigar.hpp:352
ranges::small_string< 10 > to_string() const noexcept
Convert to string representation.
Definition: cigar.hpp:273
constexpr cigar(cigar_op const op) noexcept
Construct from one component.
Definition: cigar.hpp:202
friend constexpr auto get(cigar &l) noexcept
Get one of the two components from the cigar element (by type).
Definition: cigar.hpp:366
constexpr uint32_t to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: cigar.hpp:240
cigar & assign_string(std::string_view const s)
Assign from the string representation.
Definition: cigar.hpp:316
constexpr cigar() noexcept=default
Defaulted.
constexpr cigar & operator=(uint32_t const count) noexcept
Assign from one component.
Definition: cigar.hpp:205
constexpr cigar & operator=(cigar_op const op) noexcept
Assign from one component.
Definition: cigar.hpp:212
friend constexpr auto get(cigar const &l) noexcept
Get one of the two components from the cigar element (by index).
Definition: cigar.hpp:381
constexpr cigar(uint32_t const count) noexcept
Construct from one component.
Definition: cigar.hpp:199
friend constexpr auto get(cigar &l) noexcept
Get one of the two components from the cigar element (by index).
Definition: cigar.hpp:399
Implements a small string that can be used for compile time computations.
Definition: small_string.hpp:47
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition: small_string.hpp:209
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:70
constexpr auto assign_char_strictly_to
Assign a character to an alphabet object, throw if the character is not valid.
Definition: concept.hpp:461
#define BIOCPP_IS_SAME(...)
A macro that behaves like std::is_same_v, except that it doesn't need to instantiate the template on ...
Definition: core.hpp:175
The alphabet module's namespace.
Definition: aa10li.hpp:23
The main BioC++ namespace.
Definition: aa10li.hpp:23
A constexpr string implementation to manipulate string literals at compile time.
Provides bio::alphabet::tuple_base.
Provides alphabet adaptations for standard uint types.