Skip to content

Commit

Permalink
Merge pull request #1285 from h-2/more_alphabet
Browse files Browse the repository at this point in the history
Resolve open Alphabet TODOs
  • Loading branch information
h-2 authored Oct 8, 2019
2 parents 01ff96f + f8a8eb7 commit ebd0790
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 198 deletions.
18 changes: 6 additions & 12 deletions include/seqan3/alphabet/alphabet_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,43 +180,37 @@ class alphabet_base
//!\brief Checks whether the letters `lhs` and `rhs` are equal.
friend constexpr bool operator==(derived_type const lhs, derived_type const rhs) noexcept
{
using seqan3::to_rank;
return to_rank(lhs) == to_rank(rhs);
return seqan3::to_rank(lhs) == seqan3::to_rank(rhs);
}

//!\brief Checks whether the letters `lhs` and `rhs` are unequal.
friend constexpr bool operator!=(derived_type const lhs, derived_type const rhs) noexcept
{
using seqan3::to_rank;
return to_rank(lhs) != to_rank(rhs);
return seqan3::to_rank(lhs) != seqan3::to_rank(rhs);
}

//!\brief Checks whether the letter `lhs` is smaller than `rhs`.
friend constexpr bool operator<(derived_type const lhs, derived_type const rhs) noexcept
{
using seqan3::to_rank;
return to_rank(lhs) < to_rank(rhs);
return seqan3::to_rank(lhs) < seqan3::to_rank(rhs);
}

//!\brief Checks whether the letter `lhs` is greater than `rhs`.
friend constexpr bool operator>(derived_type const lhs, derived_type const rhs) noexcept
{
using seqan3::to_rank;
return to_rank(lhs) > to_rank(rhs);
return seqan3::to_rank(lhs) > seqan3::to_rank(rhs);
}

//!\brief Checks whether the letter `lhs` is smaller than or equal to `rhs`.
friend constexpr bool operator<=(derived_type const lhs, derived_type const rhs) noexcept
{
using seqan3::to_rank;
return to_rank(lhs) <= to_rank(rhs);
return seqan3::to_rank(lhs) <= seqan3::to_rank(rhs);
}

//!\brief Checks whether the letter `lhs` is bigger than or equal to `rhs`.
friend constexpr bool operator>=(derived_type const lhs, derived_type const rhs) noexcept
{
using seqan3::to_rank;
return to_rank(lhs) >= to_rank(rhs);
return seqan3::to_rank(lhs) >= seqan3::to_rank(rhs);
}
//!\}

Expand Down
3 changes: 1 addition & 2 deletions include/seqan3/alphabet/aminoacid/aminoacid_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ class aminoacid_base : public alphabet_base<derived_type, size, char>
//!\endcond
explicit constexpr aminoacid_base(other_aa_type const & other) noexcept
{
using seqan3::to_rank;
static_cast<derived_type &>(*this) =
detail::convert_through_char_representation<derived_type, other_aa_type>[to_rank(other)];
detail::convert_through_char_representation<derived_type, other_aa_type>[seqan3::to_rank(other)];
}
//!\}

Expand Down
23 changes: 12 additions & 11 deletions include/seqan3/alphabet/cigar/cigar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
namespace seqan3
{

/*!\brief The cigar alphabet pairs a counter with a seqan3::cigar_op letter.
/*!\brief The cigar semialphabet pairs a counter with a seqan3::cigar_op letter.
* \ingroup cigar
* \implements seqan3::writable_alphabet
* \implements seqan3::writable_semialphabet
* \implements seqan3::trivially_copyable
* \implements seqan3::standard_layout
* \implements std::regular
*
* \details
*
* This alphabet represents a unit in a CIGAR string, typically found in the
* This semialphabet represents a unit in a CIGAR string, typically found in the
* SAM and BAM formats. It consists of a number and a seqan3::cigar_op symbol.
*
* The "char representation" of this alphabet is a seqan3::small_string. This
* has some implications when using it in code that doesn't expect a range
* of symbols.
* It has a "visual representation", but since this is a string and not a char,
* the type only models seqan3::writable_semialphabet and not
* seqan3::writable_alphabet.
* Members for reading/writing the string are provided.
*
* To avoid confusion between string and char literal, this alphabet has
* no user defined literal operators. Always assign from a pair of
Expand Down Expand Up @@ -102,8 +103,8 @@ class cigar : public alphabet_tuple_base<cigar, uint32_t, cigar_op>
/*!\name Read functions
* \{
*/
//!\brief Return the character representation.
small_string<11> to_char() const noexcept
//!\brief Return the string representation.
small_string<11> to_string() const noexcept
{
small_string<11> ret{}; // maximum number of digits for uint32_t + 1 char for the cigar_op
ret.resize(11);
Expand All @@ -121,8 +122,8 @@ class cigar : public alphabet_tuple_base<cigar, uint32_t, cigar_op>
/*!\name Write functions
* \{
*/
//!\brief Assign from the character representation.
cigar & assign_char(small_string<11> const s) noexcept
//!\brief Assign from the string representation.
cigar & assign_string(small_string<11> const s) noexcept
{
uint32_t num{};
auto [ ptr, errc ] = std::from_chars(s.data(), s.data() + 10, num);
Expand Down Expand Up @@ -165,7 +166,7 @@ class cigar : public alphabet_tuple_base<cigar, uint32_t, cigar_op>
template <typename char_t>
inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, cigar const c)
{
s << to_char(c);
s << c.to_string();
return s;
}

Expand Down
19 changes: 3 additions & 16 deletions include/seqan3/alphabet/composite/alphabet_tuple_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,8 @@ class alphabet_tuple_base :
+ to_rank() * alphabet_tuple_base::cummulative_alph_sizes[index]);
}

/*!\name Associated types
* \{
*/
using typename base_t::rank_type;
using typename base_t::char_type;
using typename base_t::phred_type;
//!\}

public:
//Import from base type:
using base_t::to_rank;
using base_t::alphabet_size;
using base_t::operator=;

/*!\name Constructors, destructor and assignment
Expand Down Expand Up @@ -438,8 +428,7 @@ class alphabet_tuple_base :
using t = meta::at_c<component_list, index>;
t val{};

using seqan3::assign_rank_to;
assign_rank_to(l.to_component_rank<index>(), val);
seqan3::assign_rank_to(l.to_component_rank<index>(), val);

return component_proxy<t, index>{val, l};
}
Expand Down Expand Up @@ -469,8 +458,7 @@ class alphabet_tuple_base :
using t = meta::at_c<component_list, index>;
t val{};

using seqan3::assign_rank_to;
assign_rank_to(l.to_component_rank<index>(), val);
seqan3::assign_rank_to(l.to_component_rank<index>(), val);

return val;
}
Expand Down Expand Up @@ -610,8 +598,7 @@ class alphabet_tuple_base :
template <std::size_t ...idx>
static constexpr rank_type rank_sum_helper(component_types ... components, std::index_sequence<idx...> const &) noexcept
{
using seqan3::to_rank;
return ((to_rank(components) * cummulative_alph_sizes[idx]) + ...);
return ((seqan3::to_rank(components) * cummulative_alph_sizes[idx]) + ...);
}
};

Expand Down
3 changes: 1 addition & 2 deletions include/seqan3/alphabet/composite/alphabet_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ class alphabet_variant : public alphabet_base<alphabet_variant<alternative_types
}
}

using seqan3::assign_rank_to;
return assign_rank_to(to_rank() - partial_sum_sizes[index], alternative_t{});
return seqan3::assign_rank_to(to_rank() - partial_sum_sizes[index], alternative_t{});
}

/*!\brief Compile-time generated lookup table which contains the partial
Expand Down
3 changes: 2 additions & 1 deletion include/seqan3/alphabet/concept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ struct to_char_fn
{
{ impl(priority_tag<2>{}, a) };
requires noexcept(impl(priority_tag<2>{}, a));
requires builtin_character<decltype(impl(priority_tag<2>{}, a))>;
}
//!\endcond
constexpr decltype(auto) operator()(alph_t const a) const noexcept
Expand Down Expand Up @@ -302,7 +303,7 @@ namespace seqan3
* 3. A member function called `to_char()`.
*
* Functions are only considered for one of the above cases if they are marked `noexcept` (`constexpr` is not required,
* but recommended).
* but recommended) and if the returned type models seqan3::builtin_character.
*
* Every alphabet type must provide one of the above.
*
Expand Down
Loading

0 comments on commit ebd0790

Please sign in to comment.