SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
cigar.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
20 #include <seqan3/std/charconv>
21 
22 // ------------------------------------------------------------------
23 // cigar
24 // ------------------------------------------------------------------
25 
26 namespace seqan3
27 {
28 
54 class cigar : public alphabet_tuple_base<cigar, uint32_t, exposition_only::cigar_operation>
55 {
56 private:
59 
61  friend base_t;
63 
64 public:
65 
95 
99  constexpr cigar() noexcept = default;
100  constexpr cigar(cigar const &) noexcept = default;
101  constexpr cigar(cigar &&) noexcept = default;
102  constexpr cigar & operator=(cigar const &) noexcept = default;
103  constexpr cigar & operator=(cigar &&) noexcept = default;
104  ~cigar() noexcept = default;
105 
106  // Inherit constructors from base
107  using base_t::base_t;
108 
117  SEQAN3_DOXYGEN_ONLY(( constexpr cigar(component_type const alph) noexcept {} ))
118 
127  SEQAN3_DOXYGEN_ONLY(( constexpr cigar & operator=(component_type const alph) noexcept {} ))
129 
130  // Inherit operators from base
131  using base_t::operator=;
132 
140  small_string<11> to_string() const noexcept
141  {
142  small_string<11> ret{}; // maximum number of digits for uint32_t + 1 char for the cigar operation
143  ret.resize(11);
144 
145  auto [ ptr, errc ] = std::to_chars(ret.data(), ret.data() + 10, get<0>(*this));
146 
147  *ptr = seqan3::to_char(get<1>(*this));
148  (void)errc;
149 
150  ret.resize(ptr - ret.data() + 1);
151  return ret;
152  }
154 
163  {
164  uint32_t num{};
165  auto [ ptr, errc ] = std::from_chars(s.data(), s.data() + 10, num);
166 
167  if ((errc != std::errc{}) || (!char_is_valid_for<operation>(*ptr)) || (*(ptr + 1) != 0))
168  {
169  get<0>(*this) = 0;
170  assign_char_to('P', get<1>(*this));
171  }
172  else
173  {
174  get<0>(*this) = num;
175  assign_char_to(*ptr, get<1>(*this));
176  }
177 
178  return *this;
179  }
181 
191  SEQAN3_DOXYGEN_ONLY(( friend template <size_t index> constexpr auto get(cigar & l) noexcept {} ))
192 
193 
201  SEQAN3_DOXYGEN_ONLY(( friend template <typename type> constexpr auto get(cigar & l) noexcept {} ))
203 };
204 
206 template <typename char_t>
207 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, cigar const c)
208 {
209  s << c.to_string();
210  return s;
211 }
212 
213 // ------------------------------------------------------------------
214 // literals
215 // ------------------------------------------------------------------
216 
227 inline cigar::operation operator""_cigar_operation(char const c) noexcept
228 {
229  return cigar::operation{}.assign_char(c);
230 }
232 
233 } // namespace seqan3
Provides seqan3::alphabet_tuple_base.
Introduces the seqan3::exposition_only::cigar_operation alphabet.
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:159
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:124
The seqan3::cigar semialphabet pairs a counter with a seqan3::cigar::operation letter.
Definition: cigar.hpp:55
constexpr friend auto get(cigar &l) noexcept
Tuple-like access to the contained components.
Definition: cigar.hpp:191
small_string< 11 > to_string() const noexcept
Return the string representation.
Definition: cigar.hpp:140
constexpr cigar() noexcept=default
Defaulted.
alphabet_tuple_base< cigar, uint32_t, exposition_only::cigar_operation > base_t
The base class.
Definition: cigar.hpp:58
cigar & assign_string(small_string< 11 > const s) noexcept
Assign from the string representation.
Definition: cigar.hpp:162
The actual implementation of seqan3::cigar::operation for documentation purposes only.
Definition: cigar_operation.hpp:48
Implements a small string that can be used for compile time computations.
Definition: small_string.hpp:43
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition: small_string.hpp:216
Provides seqan3::debug_stream and related types.
T from_chars(T... args)
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: debug_stream_alignment.hpp:103
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:429
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:328
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
A constexpr string implementation to manipulate string literals at compile time.
Provides std::from_chars and std::to_chars if not defined in the stl <charconv> header.
T to_chars(T... args)
Provides alphabet adaptations for standard uint types.