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
debug_stream_type.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 <cassert>
13#include <iosfwd>
14#include <stdexcept>
15
19
20namespace seqan3
21{
22
23// ------------------------------------------------------------------
24// seqan3::fmtflags2
25// ------------------------------------------------------------------
26
31enum class fmtflags2 : int8_t
32{
33 none = 0,
34 utf8 = 1,
35 small_int_as_number = 1 << 1,
37 default_ = small_int_as_number
38};
39
43template <>
44inline constexpr bool add_enum_bitwise_operators<fmtflags2> = true;
46
47// ------------------------------------------------------------------
48// seqan3::debug_stream_type
49// ------------------------------------------------------------------
50
77template <typename char_t = char>
79{
80public:
85 debug_stream_type() = default;
90 ~debug_stream_type() = default;
91
93 constexpr explicit debug_stream_type(std::basic_ostream<char_t> & out) : stream{&out}
94 {}
96
118 {
119 stream = &out;
120 }
121
124 {
125 assert(stream != nullptr);
126 return *stream;
127 }
129
134 template <typename other_char_t, typename t>
136 {
137 if constexpr (printable_with<default_printer, decltype(s), t>)
138 {
139 std::invoke(default_printer{}, s, std::forward<t>(v));
140 }
141 else
142 {
143 std::string const msg = "debug_stream has no print overload for type: " + detail::type_name_as_string<t>;
144 throw std::runtime_error{msg};
145 }
146 return s;
147 }
148
151 {
152 *stream << fp;
153 return *this;
154 }
155
157
158 template <typename T>
159 friend struct debug_stream_printer;
160
161 template <typename T>
162 friend struct std_printer;
163
166
173 {
174 return stream->flags();
175 }
176
179 {
180 return stream->flags(flgs);
181 }
182
184 void setf(fmtflags const flag)
185 {
186 stream->setf(flag);
187 }
188
190 void unsetf(fmtflags const flag)
191 {
192 stream->unsetf(flag);
193 }
194
196
203 {
204 return flgs2;
205 }
206
209 {
210 flgs2 = flgs;
211 return flgs2;
212 }
213
215 void setf(fmtflags2 const flag)
216 {
217 flgs2 |= flag;
218 }
219
222 {
223 flgs2 &= ~flag;
224 }
225
227
228private:
231
233 fmtflags2 flgs2{fmtflags2::default_};
234};
235
245template <typename value_t>
246 requires (std::is_same_v<std::remove_cvref_t<value_t>, int8_t>
247 || std::is_same_v<std::remove_cvref_t<value_t>, uint8_t>
248 || std::is_same_v<std::remove_cvref_t<value_t>, fmtflags2>)
250{
261 template <typename char_t>
262 constexpr void operator()(debug_stream_type<char_t> & stream, int8_t const v) const
263 {
265 *stream.stream << static_cast<int>(v);
266 else
267 *stream.stream << v;
268 }
269
280 template <typename char_t>
281 constexpr void operator()(debug_stream_type<char_t> & stream, uint8_t const v) const
282 {
284 *stream.stream << static_cast<unsigned>(v);
285 else
286 *stream.stream << v;
287 }
288
297 template <typename char_t>
298 constexpr void operator()(debug_stream_type<char_t> & stream, fmtflags2 const flag) const
299 {
300 stream.setf(flag);
301 }
302};
303
304} // namespace seqan3
Provides seqan3::add_enum_bitwise_operators.
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
debug_stream_type & operator<<(std::ostream &(*fp)(std::ostream &))
This overloads enables forwarding std::endl and other manipulators.
Definition debug_stream_type.hpp:150
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition debug_stream_type.hpp:202
debug_stream_type & operator=(debug_stream_type const &)=default
Defaulted.
fmtflags2 flags2(fmtflags2 flgs)
Replace the current flags on the stream with the given argument.
Definition debug_stream_type.hpp:208
constexpr debug_stream_type(std::basic_ostream< char_t > &out)
Construction from an output stream.
Definition debug_stream_type.hpp:93
typename std::basic_ostream< char_t >::fmtflags fmtflags
This type is std::ios_base::fmtflags.
Definition debug_stream_type.hpp:165
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition debug_stream_type.hpp:190
~debug_stream_type()=default
Defaulted.
void setf(fmtflags2 const flag)
Set the format flag(s) on the stream (current flags are ORed with the argument).
Definition debug_stream_type.hpp:215
debug_stream_type(debug_stream_type const &)=default
Defaulted.
fmtflags flags(fmtflags const flgs)
Replace the current flags on the stream with the given argument.
Definition debug_stream_type.hpp:178
std::basic_ostream< char_t > * stream
Pointer to the output stream.
Definition debug_stream_type.hpp:230
debug_stream_type()=default
Defaulted.
void setf(fmtflags const flag)
Set the format flag(s) on the stream (current flags are ORed with the argument).
Definition debug_stream_type.hpp:184
debug_stream_type(debug_stream_type &&)=default
Defaulted.
std::basic_ostream< char_t > & get_underlying_stream() const noexcept
Retrieve the underlying stream.
Definition debug_stream_type.hpp:123
fmtflags2 flgs2
The SeqAn specific flags to the stream.
Definition debug_stream_type.hpp:233
fmtflags flags() const
Retrieve the format flags from the stream.
Definition debug_stream_type.hpp:172
friend debug_stream_type< other_char_t > & operator<<(debug_stream_type< other_char_t > &s, t &&v)
Forwards to the underlying stream object.
Definition debug_stream_type.hpp:135
debug_stream_type & operator=(debug_stream_type &&)=default
Defaulted.
void unsetf(fmtflags2 const flag)
Unset the format flag(s) on the stream.
Definition debug_stream_type.hpp:221
void set_underlying_stream(std::basic_ostream< char_t > &out)
Change the underlying output stream.
Definition debug_stream_type.hpp:117
Definition default_printer.hpp:67
Provides seqan3::default_printer.
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition debug_stream_type.hpp:32
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
@ none
No flag is set.
@ flag
The alignment flag (bit information), uint16_t value.
T invoke(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
constexpr bool add_enum_bitwise_operators< fmtflags2 >
Overload bitwise operators for seqan3::fmtflags2.
Definition debug_stream_type.hpp:44
constexpr void operator()(debug_stream_type< char_t > &stream, uint8_t const v) const
Prints a uint8_t value to the debug stream.
Definition debug_stream_type.hpp:281
constexpr void operator()(debug_stream_type< char_t > &stream, int8_t const v) const
Prints an int8_t value to the debug stream.
Definition debug_stream_type.hpp:262
constexpr void operator()(debug_stream_type< char_t > &stream, fmtflags2 const flag) const
Sets the fmtflags2 of the debug stream.
Definition debug_stream_type.hpp:298
Definition default_printer.hpp:33
The default printer that is used by seqan3::debug_stream.
Definition default_printer.hpp:219
Definition default_printer.hpp:47
Provides traits to inspect some information of a type, for example its name.
Hide me