SeqAn3  3.0.2
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, cigar_op>
55 {
56 private:
59 
61  friend base_t;
63 
64 public:
68  constexpr cigar() noexcept = default;
69  constexpr cigar(cigar const &) noexcept = default;
70  constexpr cigar(cigar &&) noexcept = default;
71  constexpr cigar & operator=(cigar const &) noexcept = default;
72  constexpr cigar & operator=(cigar &&) noexcept = default;
73  ~cigar() noexcept = default;
74 
75  // Inherit constructors from base
76  using base_t::base_t;
77 
84  SEQAN3_DOXYGEN_ONLY(( constexpr cigar(component_type const alph) noexcept {} ))
85 
86 
92  SEQAN3_DOXYGEN_ONLY(( constexpr cigar & operator=(component_type const alph) noexcept {} ))
94 
95  // Inherit operators from base
96  using base_t::operator=;
97 
101  small_string<11> to_string() const noexcept
103  {
104  small_string<11> ret{}; // maximum number of digits for uint32_t + 1 char for the cigar_op
105  ret.resize(11);
106 
107  auto [ ptr, errc ] = std::to_chars(ret.data(), ret.data() + 10, get<0>(*this));
108 
109  *ptr = seqan3::to_char(get<1>(*this));
110  (void)errc;
111 
112  ret.resize(ptr - ret.data() + 1);
113  return ret;
114  }
116 
120  cigar & assign_string(small_string<11> const s) noexcept
122  {
123  uint32_t num{};
124  auto [ ptr, errc ] = std::from_chars(s.data(), s.data() + 10, num);
125 
126  if ((errc != std::errc{}) || (!char_is_valid_for<cigar_op>(*ptr)) || (*(ptr + 1) != 0))
127  {
128  get<0>(*this) = 0;
129  assign_char_to('P', get<1>(*this));
130  }
131  else
132  {
133  get<0>(*this) = num;
134  assign_char_to(*ptr, get<1>(*this));
135  }
136 
137  return *this;
138  }
140 
148  SEQAN3_DOXYGEN_ONLY(( template <size_t index> constexpr auto get(cigar & l) noexcept {} ))
149 
150 
156  SEQAN3_DOXYGEN_ONLY(( template <typename type> constexpr auto get(cigar & l) noexcept {} ))
158 };
159 
161 template <typename char_t>
163 {
164  s << c.to_string();
165  return s;
166 }
167 
168 } // namespace seqan3
seqan3::cigar::cigar
constexpr cigar(component_type const alph) noexcept
Construction via a value of one of the components.
Definition: cigar.hpp:84
seqan3::cigar::assign_string
cigar & assign_string(small_string< 11 > const s) noexcept
Assign from the string representation.
Definition: cigar.hpp:121
seqan3::alphabet_tuple_base
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:119
charconv
Provides std::from_chars and std::to_chars if not defined in the stl <charconv> header.
seqan3::small_string
Implements a small string that can be used for compile time computations.
Definition: small_string.hpp:42
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:320
seqan3::alphabet_base< cigar,(1 *... *alphabet_size< component_types >), void >
seqan3::cigar::to_string
small_string< 11 > to_string() const noexcept
Return the string representation.
Definition: cigar.hpp:102
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
seqan3::cigar::~cigar
~cigar() noexcept=default
Defaulted.
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:70
small_string.hpp
A constexpr string implementation to manipulate string literals at compile time.
cigar_op.hpp
Introduces the cigar_op alphabet.
seqan3::cigar
The cigar semialphabet pairs a counter with a seqan3::cigar_op letter.
Definition: cigar.hpp:54
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::cigar::cigar
constexpr cigar() noexcept=default
Defaulted.
std::errc
std::from_chars
T from_chars(T... args)
seqan3::operator<<
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, tuple_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: aligned_sequence_concept.hpp:562
std::to_chars
T to_chars(T... args)
seqan3::cigar::get
constexpr auto get(cigar &l) noexcept
Tuple-like access to the contained components.
Definition: cigar.hpp:148
uint.hpp
Provides alphabet adaptations for standard uint types.
alphabet_tuple_base.hpp
Provides seqan3::alphabet_tuple_base.
seqan3::assign_char_to
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:416
seqan3::cigar::operator=
constexpr cigar & operator=(cigar const &) noexcept=default
Defaulted.
seqan3::small_string::resize
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition: small_string.hpp:216