Loading...
Searching...
No Matches
seqan3::debug_stream_type< char_t > Class Template Reference
Core » Debug Stream

A "pretty printer" for most SeqAn data structures and related types. More...

`#include <seqan3/core/debug_stream/debug_stream_type.hpp>`

## Public Types

using | fmtflags = typename std::basic_ostream<char_t>::fmtflags
| This type is std::ios_base::fmtflags.

## Public Member Functions

Constructor, destructor and assignment.
The standard functions are explicitly set to default.
| debug_stream_type ()=default
| Defaulted.
| debug_stream_type (debug_stream_type const &)=default
| Defaulted.
| debug_stream_type (debug_stream_type &&)=default
| Defaulted.
debug_stream_type & | operator= (debug_stream_type const &)=default
| Defaulted.
debug_stream_type & | operator= (debug_stream_type &&)=default
| Defaulted.
| ~debug_stream_type ()=default
| Defaulted.
constexpr | debug_stream_type (std::basic_ostream< char_t > &out)
| Construction from an output stream.
Miscelleneous
void | set_underlying_stream (std::basic_ostream< char_t > &out)
| Change the underlying output stream.
std::basic_ostream< char_t > & | get_underlying_stream () const noexcept
| Retrieve the underlying stream.
Format flags (std::ios_base::fmtflags)
std::ios_base::fmtflags that modify the stream's behaviour.
fmtflags | flags () const
| Retrieve the format flags from the stream.
fmtflags | flags (fmtflags const flgs)
| Replace the current flags on the stream with the given argument.
void | setf (fmtflags const flag)
| Set the format flag(s) on the stream (current flags are ORed with the argument).
void | unsetf (fmtflags const flag)
| Unset the format flag(s) on the stream.
Format flags (seqan3::fmtflags2)
SeqAn specific debug flags for the debug stream.
fmtflags2 | flags2 () const
| Retrieve the format flags from the stream.
fmtflags2 | flags2 (fmtflags2 flgs)
| Replace the current flags on the stream with the given argument.
void | setf (fmtflags2 const flag)
| Set the format flag(s) on the stream (current flags are ORed with the argument).
void | unsetf (fmtflags2 const flag)
| Unset the format flag(s) on the stream.

## Friends

template<typename T>
struct | debug_stream_printer
template<typename T>
struct | std_printer

## Formatted output

template<typename other_char_t, typename t>
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<< (std::ostream &(*fp)(std::ostream &))
| This overloads enables forwarding std::endl and other manipulators.

## Detailed Description

template<typename char_t = char>
class seqan3::debug_stream_type< char_t >

A "pretty printer" for most SeqAn data structures and related types.

A global instance of this type exists as seqan3::debug_stream. You can stream to it as you would to std::cout or std::cerr, but the debug stream has special overloads that make certain types streamable (that are not streamable to std::cout). Additionally some data structures are visualised more elaborately via the debug stream and there are extra flags to configure it (seqan3::fmtflags2).

See also
  Debug Stream

# Example

Simple usage:

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <iostream>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/views/to_rank.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
// The alphabet normally needs to be converted to char explicitly:
std::cout << seqan3::to_char('C'_dna5) << '\n'; // prints 'C'
// The debug_stream, on the other hand, does this automatically:
seqan3::debug_stream << 'C'_dna5 << '\n'; // prints 'C'
// The debug_stream can also print all types that model std::ranges::input_range:
std::vector<seqan3::dna5> vec{"ACGT"_dna5};
seqan3::debug_stream << vec << '\n'; // prints "ACGT"
// ranges of non-alphabets are printed comma-separated:
seqan3::debug_stream << (vec | seqan3::views::to_rank) << '\n'; // prints "[0,1,2,3]"
}
std::cout
debug_stream.hpp
Provides seqan3::debug_stream and related types.
dna5.hpp
Provides seqan3::dna5, container aliases and string literals.
seqan3::views::to_rank
auto const to_rank
A view that calls seqan3::to_rank() on each element in the input range.
Definition to_rank.hpp:63
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:381
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38
iostream
seqan3::literals
The SeqAn namespace for literals.
to_rank.hpp
Provides seqan3::views::to_rank.
std::vector

Changing flags:

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
int main()
{
uint8_t i = 71;
seqan3::debug_stream << '\'' << i << "'\n"; // prints '71' (because flag is set by default)
seqan3::debug_stream.unsetf(seqan3::fmtflags2::small_int_as_number); // unsets the flag
seqan3::debug_stream << '\'' << i << "'\n"; // prints 'G'
seqan3::debug_stream << seqan3::fmtflags2::small_int_as_number << '\'' << i << "'\n"; // prints '71' again
// instead of formatting the stream "inline", one can also call .setf()
}
seqan3::fmtflags2::small_int_as_number
@ small_int_as_number
Definition debug_stream_type.hpp:35

See seqan3::fmtflags2 for more details.

Attention
  This class does not yet model seqan3::output_stream_over fully,

Todo
  implement.

## Member Function Documentation

## set_underlying_stream()

template<typename char_t = char>

void seqan3::debug_stream_type< char_t >::set_underlying_stream | ( | std::basic_ostream< char_t > & | out | ) |

inline

Change the underlying output stream.

Parameters

  out | Reference to the new output stream.

The actual underlying stream that is printed to defaults to std::cerr, but can be changed via this function. You can set any kind of output stream, e.g. a std::ostringstream or a std::ofstream if you want to write to a file, but please be aware that the debug_stream never takes ownership of the underlying stream so you need to take special care that its object lifetime does not end before the debug_stream's.

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <sstream>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
std::ostringstream o;
seqan3::debug_stream.set_underlying_stream(o);
seqan3::debug_stream << "ACGT"_dna5;
o.flush();
seqan3::debug_stream << o.str(); // prints the string stream's buffer: "ACGT"
}
std::ostringstream
std::ostringstream::flush
T flush(T... args)
sstream
std::ostringstream::str
T str(T... args)

In the case where you wish to print to some stream object locally, instead create you own debug stream:

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <sstream>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
std::ostringstream o;
seqan3::debug_stream_type my_stream{o};
my_stream << "ACGT"_dna5;
o.flush();
seqan3::debug_stream << o.str() << '\n'; // prints the string stream's buffer: "ACGT"
}
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79

The documentation for this class was generated from the following file:

- debug_stream_type.hpp

Hide me