Loading...
Searching...
No Matches
debug_stream_type.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <cassert>
#include <iosfwd>
#include <stdexcept>
#include <seqan3/core/add_enum_bitwise_operators.hpp>
#include <seqan3/core/debug_stream/default_printer.hpp>
#include <seqan3/utility/detail/type_name_as_string.hpp>
namespace seqan3
{
// ------------------------------------------------------------------
// seqan3::fmtflags2
// ------------------------------------------------------------------
enum class fmtflags2 : int8_t
{
none = 0,
utf8 = 1,
small_int_as_number = 1 << 1,
default_ = small_int_as_number
};
template <>
inline constexpr bool add_enum_bitwise_operators<fmtflags2> = true;
// ------------------------------------------------------------------
// seqan3::debug_stream_type
// ------------------------------------------------------------------
template <typename char_t = char>
class debug_stream_type
{
public:
debug_stream_type() = default;
debug_stream_type(debug_stream_type const &) = default;
debug_stream_type(debug_stream_type &&) = default;
debug_stream_type & operator=(debug_stream_type const &) = default;
debug_stream_type & operator=(debug_stream_type &&) = default;
~debug_stream_type() = default;
constexpr explicit debug_stream_type(std::basic_ostream<char_t> & out) : stream{&out}
{}
void set_underlying_stream(std::basic_ostream<char_t> & out)
{
stream = &out;
}
std::basic_ostream<char_t> & get_underlying_stream() const noexcept
{
assert(stream != nullptr);
return *stream;
}
template <typename other_char_t, typename t>
friend debug_stream_type<other_char_t> & operator<<(debug_stream_type<other_char_t> & s, t && v)
{
if constexpr (printable_with<default_printer, decltype(s), t>)
{
std::invoke(default_printer{}, s, std::forward<t>(v));
}
else
{
std::string const msg = "debug_stream has no print overload for type: " + detail::type_name_as_string<t>;
throw std::runtime_error{msg};
}
return s;
}
debug_stream_type & operator<<(std::ostream & (*fp)(std::ostream &))
{
*stream << fp;
return *this;
}
template <typename T>
friend struct debug_stream_printer;
template <typename T>
friend struct std_printer;
using fmtflags = typename std::basic_ostream<char_t>::fmtflags;
fmtflags flags() const
{
return stream->flags();
}
fmtflags flags(fmtflags const flgs)
{
return stream->flags(flgs);
}
void setf(fmtflags const flag)
{
stream->setf(flag);
}
void unsetf(fmtflags const flag)
{
stream->unsetf(flag);
}
fmtflags2 flags2() const
{
return flgs2;
}
fmtflags2 flags2(fmtflags2 flgs)
{
flgs2 = flgs;
return flgs2;
}
void setf(fmtflags2 const flag)
{
flgs2 |= flag;
}
void unsetf(fmtflags2 const flag)
{
flgs2 &= ~flag;
}
private:
std::basic_ostream<char_t> * stream /* = &std::cerr*/;
fmtflags2 flgs2{fmtflags2::default_};
};
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>)
struct debug_stream_printer<value_t>
{
template <typename char_t>
constexpr void operator()(debug_stream_type<char_t> & stream, int8_t const v) const
{
if ((stream.flags2() & fmtflags2::small_int_as_number) == fmtflags2::small_int_as_number)
*stream.stream << static_cast<int>(v);
else
*stream.stream << v;
}
template <typename char_t>
constexpr void operator()(debug_stream_type<char_t> & stream, uint8_t const v) const
{
if ((stream.flags2() & fmtflags2::small_int_as_number) == fmtflags2::small_int_as_number)
*stream.stream << static_cast<unsigned>(v);
else
*stream.stream << v;
}
template <typename char_t>
constexpr void operator()(debug_stream_type<char_t> & stream, fmtflags2 const flag) const
{
stream.setf(flag);
}
};
} // namespace seqan3
add_enum_bitwise_operators.hpp
Provides seqan3::add_enum_bitwise_operators.
std::basic_ostream
std::string
cassert
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
seqan3::debug_stream_type::operator<<
debug_stream_type & operator<<(std::ostream &(*fp)(std::ostream &))
This overloads enables forwarding std::endl and other manipulators.
Definition debug_stream_type.hpp:150
seqan3::debug_stream_type::flags2
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition debug_stream_type.hpp:202
seqan3::debug_stream_type::operator=
debug_stream_type & operator=(debug_stream_type const &)=default
Defaulted.
seqan3::debug_stream_type::flags2
fmtflags2 flags2(fmtflags2 flgs)
Replace the current flags on the stream with the given argument.
Definition debug_stream_type.hpp:208
seqan3::debug_stream_type::debug_stream_type
constexpr debug_stream_type(std::basic_ostream< char_t > &out)
Construction from an output stream.
Definition debug_stream_type.hpp:93
seqan3::debug_stream_type::fmtflags
typename std::basic_ostream< char_t >::fmtflags fmtflags
This type is std::ios_base::fmtflags.
Definition debug_stream_type.hpp:165
seqan3::debug_stream_type::unsetf
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition debug_stream_type.hpp:190
seqan3::debug_stream_type::~debug_stream_type
~debug_stream_type()=default
Defaulted.
seqan3::debug_stream_type::setf
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
seqan3::debug_stream_type::debug_stream_type
debug_stream_type(debug_stream_type const &)=default
Defaulted.
seqan3::debug_stream_type::flags
fmtflags flags(fmtflags const flgs)
Replace the current flags on the stream with the given argument.
Definition debug_stream_type.hpp:178
seqan3::debug_stream_type::debug_stream_type
debug_stream_type()=default
Defaulted.
seqan3::debug_stream_type::setf
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
seqan3::debug_stream_type::debug_stream_type
debug_stream_type(debug_stream_type &&)=default
Defaulted.
seqan3::debug_stream_type::get_underlying_stream
std::basic_ostream< char_t > & get_underlying_stream() const noexcept
Retrieve the underlying stream.
Definition debug_stream_type.hpp:123
seqan3::debug_stream_type::flags
fmtflags flags() const
Retrieve the format flags from the stream.
Definition debug_stream_type.hpp:172
seqan3::debug_stream_type::operator<<
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
seqan3::debug_stream_type::operator=
debug_stream_type & operator=(debug_stream_type &&)=default
Defaulted.
seqan3::debug_stream_type::unsetf
void unsetf(fmtflags2 const flag)
Unset the format flag(s) on the stream.
Definition debug_stream_type.hpp:221
seqan3::debug_stream_type::set_underlying_stream
void set_underlying_stream(std::basic_ostream< char_t > &out)
Change the underlying output stream.
Definition debug_stream_type.hpp:117
seqan3::printable_with
Definition default_printer.hpp:67
default_printer.hpp
Provides seqan3::default_printer.
std::forward
T forward(T... args)
seqan3::fmtflags2
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition debug_stream_type.hpp:32
seqan3::fmtflags2::utf8
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition debug_stream_type.hpp:34
seqan3::fmtflags2::none
@ none
No flag is set.
Definition debug_stream_type.hpp:33
seqan3::fmtflags2::small_int_as_number
@ small_int_as_number
Definition debug_stream_type.hpp:35
seqan3::field::flag
@ flag
The alignment flag (bit information), uint16_t value.
Definition record.hpp:84
std::invoke
T invoke(T... args)
iosfwd
std::is_same_v
T is_same_v
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std::runtime_error
stdexcept
seqan3::debug_stream_printer< value_t >::operator()
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
seqan3::debug_stream_printer< value_t >::operator()
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
seqan3::debug_stream_printer< value_t >::operator()
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
seqan3::debug_stream_printer
Definition default_printer.hpp:33
seqan3::default_printer
The default printer that is used by seqan3::debug_stream.
Definition default_printer.hpp:221
seqan3::std_printer
Definition default_printer.hpp:47
type_name_as_string.hpp
Provides traits to inspect some information of a type, for example its name.
Hide me