SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
debug_stream_type.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <iosfwd>
13
15
16namespace seqan3
17{
18
19// ------------------------------------------------------------------
20// seqan3::fmtflags2
21// ------------------------------------------------------------------
22
28{
29 none = 0,
30 utf8 = 1,
31 small_int_as_number = 1 << 1,
33 default_ = small_int_as_number
34};
35
39template <>
40inline constexpr bool add_enum_bitwise_operators<fmtflags2> = true;
42
43// ------------------------------------------------------------------
44// seqan3::debug_stream_type
45// ------------------------------------------------------------------
46
73template <typename char_t = char>
75{
76public:
81 debug_stream_type() = default;
86 ~debug_stream_type() = default;
87
89 constexpr explicit debug_stream_type(std::basic_ostream<char_t> & out) : stream{&out}
90 {}
92
114 {
115 stream = &out;
116 }
118
123 template <typename other_char_t, typename t>
125
128 {
129 *stream << fp;
130 return *this;
131 }
132
134 debug_stream_type & operator<<(int8_t const v)
135 {
137 *stream << static_cast<int>(v);
138 else
139 *stream << v;
140 return *this;
141 }
142
143 debug_stream_type & operator<<(uint8_t const v)
144 {
146 *stream << static_cast<unsigned>(v);
147 else
148 *stream << v;
149 return *this;
150 }
153
156
163 {
164 return stream->flags();
165 }
166
169 {
170 return stream->flags(flgs);
171 }
172
174 void setf(fmtflags const flag)
175 {
176 stream->setf(flag);
177 }
178
180 void unsetf(fmtflags const flag)
181 {
182 stream->unsetf(flag);
183 }
184
185// fmtflags is an enum in libstdc++ and an unsigned in libc++
186#ifdef _LIBCPP_VERSION
187 static_assert(std::same_as<fmtflags, unsigned>);
188#else
191 {
192 setf(flag);
193 return *this;
194 }
195#endif
197
204 {
205 return flgs2;
206 }
207
210 {
211 flgs2 = flgs;
212 return flgs2;
213 }
214
216 void setf(fmtflags2 const flag)
217 {
218 flgs2 |= flag;
219 }
220
223 {
224 flgs2 &= ~flag;
225 }
226
229 {
230 setf(flag);
231 return *this;
232 }
234
235private:
237 std::basic_ostream<char_t> * stream /* = &std::cerr*/;
238
240 fmtflags2 flgs2{fmtflags2::default_};
241};
242
244template <typename char_t, typename t>
245debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, t && v)
246{
247 (*s.stream) << v;
248 return s;
249}
250
251} // namespace seqan3
Provides seqan3::add_enum_bitwise_operators.
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:75
debug_stream_type & operator<<(std::ostream &(*fp)(std::ostream &))
This overloads enables forwarding std::endl and other manipulators.
Definition debug_stream_type.hpp:127
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition debug_stream_type.hpp:203
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:209
constexpr debug_stream_type(std::basic_ostream< char_t > &out)
Construction from an output stream.
Definition debug_stream_type.hpp:89
typename std::basic_ostream< char_t >::fmtflags fmtflags
This type is std::ios_base::fmtflags.
Definition debug_stream_type.hpp:155
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition debug_stream_type.hpp:180
~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:216
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:168
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:174
debug_stream_type(debug_stream_type &&)=default
Defaulted.
debug_stream_type & operator<<(fmtflags const flag)
Set the format flag(s) on the stream (current flags are ORed with the argument).
Definition debug_stream_type.hpp:190
fmtflags flags() const
Retrieve the format flags from the stream.
Definition debug_stream_type.hpp:162
debug_stream_type & operator<<(fmtflags2 const flag)
Set the format flag(s) on the stream (current flags are ORed with the argument).
Definition debug_stream_type.hpp:228
friend debug_stream_type< other_char_t > & operator<<(debug_stream_type< other_char_t > &s, t &&v)
Forwards to the underlying stream object.
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:222
void set_underlying_stream(std::basic_ostream< char_t > &out)
Change the underlying output stream.
Definition debug_stream_type.hpp:113
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition debug_stream_alignment.hpp:107
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition debug_stream_type.hpp:28
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition debug_stream_type.hpp:30
@ small_int_as_number
Definition debug_stream_type.hpp:31
@ none
No flag is set.
Definition debug_stream_type.hpp:29
@ flag
The alignment flag (bit information), uint16_t value.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Hide me