Skip to content

Commit

Permalink
[MISC] clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jan 26, 2024
1 parent 17a38fc commit 29fc2a9
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,17 @@ namespace seqan3
* \return The given stream to which the alignment representation is appended.
*/
template <typename alignment_t>
requires (tuple_like<std::remove_cvref_t<alignment_t>> && detail::all_model_aligned_seq<detail::tuple_type_list_t<std::remove_cvref_t<alignment_t>>>)
requires (tuple_like<std::remove_cvref_t<alignment_t>>
&& detail::all_model_aligned_seq<detail::tuple_type_list_t<std::remove_cvref_t<alignment_t>>>)
struct alignment_printer<alignment_t>
{
constexpr static auto print = [](auto & stream, auto && alignment)
static constexpr auto print = [](auto & stream, auto && alignment)
{
constexpr size_t sequence_count = std::tuple_size_v<std::remove_cvref_t<alignment_t>>;
constexpr size_t sequence_count = std::tuple_size_v<std::remove_cvref_t<alignment_t>>;

static_assert(sequence_count >= 2, "An alignment requires at least two sequences.");
static_assert(sequence_count >= 2, "An alignment requires at least two sequences.");

detail::stream_alignment(stream, alignment, std::make_index_sequence<sequence_count - 1>{});
detail::stream_alignment(stream, alignment, std::make_index_sequence<sequence_count - 1>{});
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ template <typename coordinate_type>
detail::advanceable_alignment_coordinate>
struct advanceable_alignment_coordinate_printer<coordinate_type>
{
constexpr static auto print = [](auto & s, coordinate_type const & c)
static constexpr auto print = [](auto & s, coordinate_type const & c)
{
s << std::tie(c.first, c.second);
s << std::tie(c.first, c.second);
};
};

Expand Down
10 changes: 5 additions & 5 deletions include/seqan3/alignment/matrix/detail/debug_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ template <typename alignment_matrix_t>
requires detail::matrix<std::remove_cvref_t<alignment_matrix_t>>
struct alignment_matrix_printer<alignment_matrix_t>
{
constexpr static auto print = [](auto & s, auto && matrix)
static constexpr auto print = [](auto & s, auto && matrix)
{
detail::debug_matrix debug{std::forward<alignment_matrix_t>(matrix)};
detail::debug_matrix debug{std::forward<alignment_matrix_t>(matrix)};

std::stringstream sstream{};
debug.stream_matrix(sstream, s.flags2());
s << sstream.str();
std::stringstream sstream{};
debug.stream_matrix(sstream, s.flags2());
s << sstream.str();
};
};

Expand Down
21 changes: 11 additions & 10 deletions include/seqan3/alignment/matrix/detail/trace_directions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ template <typename trace_directions_t>
requires std::is_same_v<std::remove_cvref_t<trace_directions_t>, detail::trace_directions>
struct trace_directions_printer<trace_directions_t>
{
constexpr static auto print = [](auto & s, detail::trace_directions const trace)
static constexpr auto print = [](auto & s, detail::trace_directions const trace)
{
static char const * unicode[32]{"", "", "", "↖↑", "", "↖⇡", "↑⇡", "↖↑⇡", "", "↖←", "↑←",
"↖↑←", "⇡←", "↖⇡←", "↑⇡←", "↖↑⇡←", "", "↖⇠", "↑⇠", "↖↑⇠", "⇡⇠", "↖⇡⇠",
"↑⇡⇠", "↖↑⇡⇠", "←⇠", "↖←⇠", "↑←⇠", "↖↑←⇠", "⇡←⇠", "↖⇡←⇠", "↑⇡←⇠", "↖↑⇡←⇠"};
static char const * unicode[32]{"", "", "", "↖↑", "", "↖⇡", "↑⇡", "↖↑⇡",
"", "↖←", "↑←", "↖↑←", "⇡←", "↖⇡←", "↑⇡←", "↖↑⇡←",
"", "↖⇠", "↑⇠", "↖↑⇠", "⇡⇠", "↖⇡⇠", "↑⇡⇠", "↖↑⇡⇠",
"←⇠", "↖←⇠", "↑←⇠", "↖↑←⇠", "⇡←⇠", "↖⇡←⇠", "↑⇡←⇠", "↖↑⇡←⇠"};

static char const * csv[32]{"N", "D", "U", "DU", "u", "Du", "Uu", "DUu", "L", "DL", "UL",
"DUL", "uL", "DuL", "UuL", "DUuL", "l", "Dl", "Ul", "DUl", "ul", "Dul",
"Uul", "DUul", "Ll", "DLl", "ULl", "DULl", "uLl", "DuLl", "UuLl", "DUuLl"};
static char const * csv[32]{"N", "D", "U", "DU", "u", "Du", "Uu", "DUu", "L", "DL", "UL",
"DUL", "uL", "DuL", "UuL", "DUuL", "l", "Dl", "Ul", "DUl", "ul", "Dul",
"Uul", "DUul", "Ll", "DLl", "ULl", "DULl", "uLl", "DuLl", "UuLl", "DUuLl"};

bool is_unicode = (s.flags2() & fmtflags2::utf8) == fmtflags2::utf8;
auto const & trace_dir = is_unicode ? unicode : csv;
bool is_unicode = (s.flags2() & fmtflags2::utf8) == fmtflags2::utf8;
auto const & trace_dir = is_unicode ? unicode : csv;

s << trace_dir[static_cast<size_t>(trace)];
s << trace_dir[static_cast<size_t>(trace)];
};
};

Expand Down
83 changes: 44 additions & 39 deletions include/seqan3/alignment/pairwise/alignment_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,50 +415,55 @@ namespace seqan3
template <typename T>
requires (!std::is_same_v<T, std::remove_cvref_t<T>>)
struct alignment_result_printer<T> : public alignment_result_printer<std::remove_cvref_t<T>>
{
};
{};

template <typename result_value_t>
struct alignment_result_printer<alignment_result<result_value_t>>
{
constexpr static auto print = [](auto & stream, alignment_result<result_value_t> const & result)
{
using alignment_result_t = alignment_result<result_value_t>;
using disabled_t = std::nullopt_t *;
using result_data_t =
typename detail::alignment_result_value_type_accessor<std::remove_cvref_t<alignment_result_t>>::type;

constexpr bool has_sequence1_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence1_id), disabled_t>;
constexpr bool has_sequence2_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence2_id), disabled_t>;
constexpr bool has_score = !std::is_same_v<decltype(std::declval<result_data_t>().score), disabled_t>;
constexpr bool has_end_positions =
!std::is_same_v<decltype(std::declval<result_data_t>().end_positions), disabled_t>;
constexpr bool has_begin_positions =
!std::is_same_v<decltype(std::declval<result_data_t>().begin_positions), disabled_t>;
constexpr bool has_alignment = !std::is_same_v<decltype(std::declval<result_data_t>().alignment), disabled_t>;

bool prepend_comma = false;
auto append_to_stream = [&](auto &&... args)
static constexpr auto print = [](auto & stream, alignment_result<result_value_t> const & result)
{
((stream << (prepend_comma ? std::string{", "} : std::string{})) << ... << std::forward<decltype(args)>(args));
prepend_comma = true;
};

stream << '{';
if constexpr (has_sequence1_id)
append_to_stream("sequence1 id: ", result.sequence1_id());
if constexpr (has_sequence2_id)
append_to_stream("sequence2 id: ", result.sequence2_id());
if constexpr (has_score)
append_to_stream("score: ", result.score());
if constexpr (has_begin_positions)
append_to_stream("begin: (", result.sequence1_begin_position(), ",", result.sequence2_begin_position(), ")");
if constexpr (has_end_positions)
append_to_stream("end: (", result.sequence1_end_position(), ",", result.sequence2_end_position(), ")");
if constexpr (has_alignment)
append_to_stream("\nalignment:\n", result.alignment());
stream << '}';

using alignment_result_t = alignment_result<result_value_t>;
using disabled_t = std::nullopt_t *;
using result_data_t =
typename detail::alignment_result_value_type_accessor<std::remove_cvref_t<alignment_result_t>>::type;

constexpr bool has_sequence1_id =
!std::is_same_v<decltype(std::declval<result_data_t>().sequence1_id), disabled_t>;
constexpr bool has_sequence2_id =
!std::is_same_v<decltype(std::declval<result_data_t>().sequence2_id), disabled_t>;
constexpr bool has_score = !std::is_same_v<decltype(std::declval<result_data_t>().score), disabled_t>;
constexpr bool has_end_positions =
!std::is_same_v<decltype(std::declval<result_data_t>().end_positions), disabled_t>;
constexpr bool has_begin_positions =
!std::is_same_v<decltype(std::declval<result_data_t>().begin_positions), disabled_t>;
constexpr bool has_alignment = !std::is_same_v<decltype(std::declval<result_data_t>().alignment), disabled_t>;

bool prepend_comma = false;
auto append_to_stream = [&](auto &&... args)
{
((stream << (prepend_comma ? std::string{", "} : std::string{}))
<< ... << std::forward<decltype(args)>(args));
prepend_comma = true;
};

stream << '{';
if constexpr (has_sequence1_id)
append_to_stream("sequence1 id: ", result.sequence1_id());
if constexpr (has_sequence2_id)
append_to_stream("sequence2 id: ", result.sequence2_id());
if constexpr (has_score)
append_to_stream("score: ", result.score());
if constexpr (has_begin_positions)
append_to_stream("begin: (",
result.sequence1_begin_position(),
",",
result.sequence2_begin_position(),
")");
if constexpr (has_end_positions)
append_to_stream("end: (", result.sequence1_end_position(), ",", result.sequence2_end_position(), ")");
if constexpr (has_alignment)
append_to_stream("\nalignment:\n", result.alignment());
stream << '}';
};
};

Expand Down
4 changes: 2 additions & 2 deletions include/seqan3/alphabet/detail/debug_stream_alphabet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template <typename alphabet_t>
requires alphabet<alphabet_t>
struct alphabet_printer<alphabet_t>
{
constexpr static auto print = [](auto & s, alphabet_t l)
static constexpr auto print = [](auto & s, alphabet_t l)
{
s << to_char(l);
};
Expand All @@ -50,7 +50,7 @@ template <typename alphabet_t>
requires std::same_as<std::remove_cvref_t<alphabet_t>, mask>
struct mask_printer<alphabet_t>
{
constexpr static auto print = [](auto & s, alphabet_t const l)
static constexpr auto print = [](auto & s, alphabet_t const l)
{
s << (l == std::remove_cvref_t<alphabet_t>{} ? "UNMASKED" : "MASKED");
};
Expand Down
15 changes: 10 additions & 5 deletions include/seqan3/core/debug_stream/debug_stream_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ class debug_stream_type
{
using t_ = std::remove_cvref_t<t>;

if constexpr(default_printer::is_printable<t_>) {
if constexpr (default_printer::is_printable<t_>)
{
default_printer::print(s, v);
} else {
}
else
{
std::string const msg = std::string{"debug_stream has no print overload for type: "} + typeid(v).name();
throw std::runtime_error{msg};
}
Expand All @@ -148,10 +151,10 @@ class debug_stream_type

//!\}

template<typename T>
template <typename T>
friend struct debug_stream_printer;

template<typename T>
template <typename T>
friend struct std_printer;

//!\brief This type is std::ios_base::fmtflags
Expand Down Expand Up @@ -227,7 +230,9 @@ class debug_stream_type
};

template <typename value_t>
requires (std::is_same_v<std::remove_cvref_t<value_t>, int8_t> || std::is_same_v<std::remove_cvref_t<value_t>, uint8_t> || std::is_same_v<std::remove_cvref_t<value_t>, fmtflags2>)
requires (std::is_same_v<std::remove_cvref_t<value_t>, int8_t>
|| std::is_same_v<std::remove_cvref_t<value_t>, uint8_t>
|| std::is_same_v<std::remove_cvref_t<value_t>, fmtflags2>)
struct debug_stream_printer<value_t>
{
struct print_fn
Expand Down
93 changes: 55 additions & 38 deletions include/seqan3/core/debug_stream/default_printer.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------

/*!\file
* \author Marcel Ehrhardt <marcel.ehrhardt AT fu-berlin.de>
* \brief Provides seqan3::default_printer.
*/

#pragma once

#include <iosfwd>
#include <utility>
#include <tuple>
#include <utility>

#include <seqan3/core/platform.hpp>

namespace seqan3
{

// clang-format off
struct no_printer_found{};
template <typename> struct advanceable_alignment_coordinate_printer {};
template <typename> struct alignment_matrix_printer {};
Expand All @@ -26,15 +39,21 @@ template <typename> struct std_printer {};
template <typename> struct char_sequence_printer {};
template <typename> struct trace_directions_printer {};
template <typename> struct tuple_printer {};
// clang-format on

template <typename printer_t>
concept printable = requires() { { printer_t::print }; };
concept printable = requires () {
{
printer_t::print
};
};

template <typename type_t>
requires requires(std::ostream & cout, type_t value)
{
{cout << value};
}
requires requires (std::ostream & cout, type_t value) {
{
cout << value
};
}
struct std_printer<type_t>
{
static constexpr auto print = [](auto & s, auto && value)
Expand All @@ -52,32 +71,32 @@ struct integral_printer<integral_t>
// note that we assume here that we always can print all std::integral's,
// but this is not correct since std::cout << char32_t{5}; is not possible.
// since char32_t is also an alphabet, we avoid infinite recursion here.
if constexpr(printable<std_printer<integral_t>>)
if constexpr (printable<std_printer<integral_t>>)
std_printer<integral_t>::print(s, value);
else
static_assert(std::same_as<integral_t, void>, "This type is not printable.");
};
};

template <template<typename> typename ...printers_t>
template <template <typename> typename... printers_t>
struct printer_order
{
template <typename type_t, typename ...types>
template <typename type_t, typename... types>
static constexpr std::ptrdiff_t find_index()
{
std::ptrdiff_t i = 0;
return ((printable<types> ? false : ++i) && ...) ? -1 : i;
std::ptrdiff_t i = 0;
return ((printable<types> ? false : ++i) && ...) ? -1 : i;
}

template <typename type_t, std::ptrdiff_t i = find_index<type_t, printers_t<type_t>...>()>
using printer_for_t = std::tuple_element_t<
i == -1 ? sizeof...(printers_t) : i,
std::tuple<printers_t<type_t>..., no_printer_found>>;
using printer_for_t =
std::tuple_element_t<i == -1 ? sizeof...(printers_t) : i, std::tuple<printers_t<type_t>..., no_printer_found>>;

// std::tuple<...> list of all printers that can print type_t
// NOTE: printer_order<...> might be nicer but is more complicated to write
template <typename type_t>
using printers_for_t = decltype(std::tuple_cat(std::conditional_t<printable<printers_t<type_t>>, std::tuple<printers_t<type_t>>, std::tuple<>>{}...));
using printers_for_t = decltype(std::tuple_cat(
std::conditional_t<printable<printers_t<type_t>>, std::tuple<printers_t<type_t>>, std::tuple<>>{}...));

template <typename type_t>
static constexpr bool is_printable = printable<printer_for_t<type_t>>;
Expand All @@ -89,29 +108,27 @@ struct printer_order
};
};

struct default_printer : printer_order<
debug_stream_printer,

alignment_result_printer, // type seqan3::alignment_result<>
alignment_printer, // concept seqan3::tuple_like<>
advanceable_alignment_coordinate_printer, // type seqan3::detail::advanceable_alignment_coordinate<>
alignment_matrix_printer, // concept seqan3::detail::matrix<>
trace_directions_printer, // type seqan3::detail::trace_directions

mask_printer, // type seqan3::mask
integral_printer, // concept std::integral
// NOTE: alphabet_printer needs the integral_printer overload, otherwise might have infinite recursion due to char and uint beeing an alphabet
alphabet_printer, // concept seqan3::alphabet

char_sequence_printer, // concept std::range::input_range<> with char value_type
integer_sequence_printer, // concept std::range::input_range<> with std::integral value_type
sequence_printer, // concept seqan3::sequence<>, i.e. std::range::input_range<> with seqan3::alphabet value_type
input_range_printer, // concept std::range::input_range<>

optional_printer, // type std::optional<> or std::nullopt_t
tuple_printer, // concept seqan3::tuple_like<>
std_printer // anything that can be printed by std::ostream
>
struct default_printer :
printer_order<
debug_stream_printer,
alignment_result_printer, // type seqan3::alignment_result<>
alignment_printer, // concept seqan3::tuple_like<>
advanceable_alignment_coordinate_printer, // type seqan3::detail::advanceable_alignment_coordinate<>
alignment_matrix_printer, // concept seqan3::detail::matrix<>
trace_directions_printer, // type seqan3::detail::trace_directions
mask_printer, // type seqan3::mask
integral_printer, // concept std::integral
// NOTE: alphabet_printer needs the integral_printer overload, otherwise it might have infinite recursion due to
// char and uint being an alphabet
alphabet_printer, // concept seqan3::alphabet
char_sequence_printer, // concept std::range::input_range<> with char value_type
integer_sequence_printer, // concept std::range::input_range<> with std::integral value_type
sequence_printer, // concept seqan3::sequence<>, i.e. std::range::input_range<> with seqan3::alphabet value_type
input_range_printer, // concept std::range::input_range<>
optional_printer, // type std::optional<> or std::nullopt_t
tuple_printer, // concept seqan3::tuple_like<>
std_printer // anything that can be printed by std::ostream
>
{};

} // namespace seqan3
Loading

0 comments on commit 29fc2a9

Please sign in to comment.