SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
masked.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 
19 
20 namespace seqan3
21 {
41  template <typename sequence_alphabet_t>
43  requires WritableAlphabet<sequence_alphabet_t>
45 class masked : public alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>
46 {
47 private:
49  using base_type = alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>;
50 
51 public:
53  using sequence_alphabet_type = sequence_alphabet_t;
54 
57 
59 
63  constexpr masked() : base_type{} {}
64  constexpr masked(masked const &) = default;
65  constexpr masked(masked &&) = default;
66  constexpr masked & operator =(masked const &) = default;
67  constexpr masked & operator =(masked &&) = default;
68  ~masked() = default;
69 
70  using base_type::base_type; // Inherit non-default constructors
71 
73  SEQAN3_DOXYGEN_ONLY(( constexpr masked(component_type const alph) {} ))
75  SEQAN3_DOXYGEN_ONLY(( constexpr masked(indirect_component_type const alph) {} ))
77  SEQAN3_DOXYGEN_ONLY(( constexpr masked & operator=(component_type const alph) {} ))
79  SEQAN3_DOXYGEN_ONLY(( constexpr masked & operator=(indirect_component_type const alph) {} ))
81 
82  // Inherit operators from base
83  using base_type::operator=;
84  using base_type::operator==;
85  using base_type::operator!=;
86  using base_type::operator>=;
87  using base_type::operator<=;
88  using base_type::operator<;
89  using base_type::operator>;
90 
94  constexpr masked & assign_char(char_type const c) noexcept
96  {
97  seqan3::assign_char_to(c, get<0>(*this));
98  seqan3::assign_rank_to(is_lower(c), get<1>(*this));
99  return *this;
100  }
101 
104  {
105  if (!char_is_valid(c))
106  throw invalid_char_assignment{detail::get_display_name_v<masked>, c};
107 
108  return assign_char(c);
109  }
111 
115  constexpr char_type to_char() const noexcept
117  {
118  if (seqan3::to_rank(get<1>(*this)))
119  {
120  return to_lower(seqan3::to_char(get<0>(*this)));
121  }
122  else
123  {
124  return seqan3::to_char(get<0>(*this));
125  }
126  }
128 
147  static constexpr bool char_is_valid(char_type const c) noexcept
148  {
149  return masked{}.assign_char(c).to_char() == c;
150  }
151 };
152 
155 template <typename sequence_alphabet_type>
156 masked(sequence_alphabet_type &&, mask const &)
157  -> masked<std::decay_t<sequence_alphabet_type>>;
158 } //namespace seqan3
masked & assign_char_strictly(char_type const c)
Strict assign from a character.
Definition: masked.hpp:103
Meta-header for the mask submodule; includes all headers from alphabet/mask/.
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: masked.hpp:53
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:207
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character value has a one-to-one mapping to an alphabet value. ...
Definition: masked.hpp:147
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: masked.hpp:56
constexpr char_type to_char() const noexcept
Return a character.
Definition: masked.hpp:116
auto constexpr is_lower
Checks whether c is a lower case character.
Definition: predicate.hpp:271
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:285
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:103
The main SeqAn3 namespace.
constexpr masked & operator=(masked const &)=default
Defaulted.
constexpr masked()
Defaulted.
Definition: masked.hpp:63
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:188
decltype(seqan3::to_char(std::declval< alphabet_type const >())) alphabet_char_t
The char_type of the alphabet; defined as the return type of seqan3::to_char.
Definition: concept.hpp:294
static detail::min_viable_uint_t< size > constexpr alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:175
Provides character predicates for tokenisation.
~masked()=default
Defaulted.
Provides utilities for modifying characters.
constexpr masked & assign_char(char_type const c) noexcept
Assign from a character.
Definition: masked.hpp:95
Implementation of a masked alphabet to be used for tuple composites.
Definition: mask.hpp:34
Provides seqan3::alphabet_tuple_base.
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:395
constexpr masked(component_type const alph)
Construction via a value of one of the components.
Definition: masked.hpp:73
An exception typically thrown by seqan3::Alphabet::assign_char_strict.
Definition: exception.hpp:25
Implementation of a masked composite, which extends a given alphabet with a mask. ...
Definition: masked.hpp:45
constexpr char_type to_lower(char_type const c) noexcept
Converts &#39;A&#39;-&#39;Z&#39; to &#39;a&#39;-&#39;z&#39; respectively; other characters are returned as is.
Definition: transform.hpp:82