SeqAn3 3.4.0-rc.4
The Modern C++ library for sequence analysis.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
default_printer.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <functional>
13#include <iosfwd>
14#include <tuple>
15#include <utility>
16
18
19namespace seqan3
20{
21
22// clang-format off
27template <typename> struct advanceable_alignment_coordinate_printer {};
28template <typename> struct alignment_matrix_printer {};
29template <typename> struct alignment_printer {};
30template <typename> struct alignment_result_printer {};
31template <typename> struct alphabet_printer {};
32template <typename> struct cigar_printer {};
33template <typename> struct debug_stream_printer {};
34template <typename> struct dynamic_bitset_printer {};
35template <typename> struct enumeration_printer {};
36template <typename> struct input_range_printer {};
37template <typename> struct integer_sequence_printer {};
38template <typename> struct integral_printer {};
39template <typename> struct mask_printer {};
40template <typename> struct optional_printer {};
41template <typename> struct sam_flag_printer {};
42template <typename> struct sequence_printer {};
43template <typename> struct search_result_printer {};
44template <typename> struct simd_printer {};
45template <typename> struct std_byte_printer {};
46template <typename> struct std_variant_printer {};
47template <typename> struct std_printer {};
48template <typename> struct strong_type_printer {};
49template <typename> struct char_sequence_printer {};
50template <typename> struct trace_directions_printer {};
51template <typename> struct tuple_printer {};
52// clang-format on
53
66template <typename printer_t, typename stream_t, typename arg_t>
67concept printable_with = std::invocable<printer_t, stream_t, arg_t>;
68
77template <typename type_t>
78 requires requires (std::ostream & cout, type_t const & value) {
79 { cout << value };
80 }
82{
93 template <typename stream_t, typename arg_t>
94 requires requires (stream_t & stream) { stream.stream; }
95 constexpr void operator()(stream_t & stream, arg_t && arg) const
96 {
97 *stream.stream << arg;
98 }
99};
100
109template <std::integral integral_t>
111{
117 template <typename stream_t>
118 constexpr void operator()(stream_t & stream, integral_t const arg) const
119 {
120 // note that we assume here that we always can print all std::integral's,
121 // but this is not correct since std::cout << char32_t{5}; is not possible.
122 // since char32_t is also an alphabet, we avoid infinite recursion here.
125 else
126 static_assert(std::same_as<integral_t *, void>, "This type is not printable.");
127 // We actually want `static_assert(false, "This type is not printable.");`.
128 // But this only works starting with GCC13. Before that, also the `if constexpr` branches that are not taken
129 // are evaluated and `static_assert(false)` will always result in an error. As a pre-GCC13 workaround,
130 // we can make the `false` dependent on some template type, which then will only be evaluated if the branch is
131 // taken.
132 }
133};
134
144template <template <typename> typename... printer_templates_t>
146{
147protected:
155 template <typename stream_t, typename arg_t, typename... printers_t>
156 static constexpr size_t find_index()
157 {
158 size_t i = 0;
159 return ((printable_with<printers_t, stream_t, arg_t> ? false : ++i) && ...) ? sizeof...(printer_templates_t)
160 : i;
161 }
162
172 template <typename stream_t,
173 typename arg_t,
176 // first: the index of the printer that can print the arguments or sizeof...(printers_t) if no printer was found
177 // second: the tuple of instantiated printers extended with no_printer_found
178 std::tuple_element_t<i, std::tuple<printer_templates_t<arg_t>..., no_printer_found>>;
179};
180
190 public printer_order<
192 alignment_result_printer, // type seqan3::alignment_result<>
193 search_result_printer, // type seqan3::search_result<>
194 alignment_printer, // concept seqan3::tuple_like<>
195 advanceable_alignment_coordinate_printer, // type seqan3::detail::advanceable_alignment_coordinate<>
196 alignment_matrix_printer, // concept seqan3::detail::matrix<>
197 trace_directions_printer, // type seqan3::detail::trace_directions
198 mask_printer, // type seqan3::mask
199 integral_printer, // concept std::integral
200 cigar_printer, // type seqan3::cigar
201 // NOTE: alphabet_printer needs the integral_printer overload, otherwise it might have infinite recursion due to
202 // char and uint being an alphabet
203 alphabet_printer, // concept seqan3::alphabet
204 sam_flag_printer, // type seqan3::sam_flag
205 simd_printer, // concept simd::simd_concept<>
206 dynamic_bitset_printer, // type seqan3::dynamic_bitset<>
207 char_sequence_printer, // concept std::range::input_range<> with char value_type
208 integer_sequence_printer, // concept std::range::input_range<> with std::integral value_type
209 sequence_printer, // concept seqan3::sequence<>, i.e. std::range::input_range<> with seqan3::alphabet value_type
210 input_range_printer, // concept std::range::input_range<>
211 strong_type_printer, // concept seqan3::detail::derived_from_strong_type<>
212 optional_printer, // type std::optional<> or std::nullopt_t
213 enumeration_printer, // types for which seqan3::enumeration_names is overloaded
214 tuple_printer, // concept seqan3::tuple_like<>
215 std_byte_printer, // type std::byte
216 std_variant_printer, // type std::variant<>
217 std_printer // anything that can be printed by std::ostream
218 >
219{
220public:
227 template <typename stream_t, typename arg_t>
229 constexpr void operator()(stream_t & stream, arg_t && arg) const
230 {
232 std::invoke(printer_t{}, stream, std::forward<arg_t>(arg));
233 }
234};
235
236} // namespace seqan3
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
Definition default_printer.hpp:67
T invoke(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides platform and dependency checks.
Definition default_printer.hpp:27
Definition default_printer.hpp:28
Definition default_printer.hpp:29
Definition default_printer.hpp:30
Definition default_printer.hpp:31
Definition default_printer.hpp:49
Definition default_printer.hpp:32
Definition default_printer.hpp:33
The default printer that is used by seqan3::debug_stream.
Definition default_printer.hpp:219
constexpr void operator()(stream_t &stream, arg_t &&arg) const
The function call operator that is only defined if the type is printable.
Definition default_printer.hpp:229
Definition default_printer.hpp:34
Definition default_printer.hpp:35
Definition default_printer.hpp:36
Definition default_printer.hpp:37
constexpr void operator()(stream_t &stream, integral_t const arg) const
The function call operator that prints the integral to the stream.
Definition default_printer.hpp:118
Definition default_printer.hpp:38
Definition default_printer.hpp:39
A tag that indicates that no printer was found for the given type.
Definition default_printer.hpp:26
Definition default_printer.hpp:40
The printer_order is a variadic template that defines the order of the printers.
Definition default_printer.hpp:146
static constexpr size_t find_index()
Find the index of the first printer that can print the argument.
Definition default_printer.hpp:156
std::tuple_element_t< i, std::tuple< printer_templates_t< arg_t >..., no_printer_found > > printer_for_t
The type of the printer that can print the argument to the stream.
Definition default_printer.hpp:178
Definition default_printer.hpp:41
Definition default_printer.hpp:43
Definition default_printer.hpp:42
Definition default_printer.hpp:44
Definition default_printer.hpp:45
constexpr void operator()(stream_t &stream, arg_t &&arg) const
The function call operator that prints the value to the stream.
Definition default_printer.hpp:95
Definition default_printer.hpp:47
Definition default_printer.hpp:46
Definition default_printer.hpp:48
Definition default_printer.hpp:50
Definition default_printer.hpp:51
Hide me