SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
debug_stream_type.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <iosfwd>
16 
18 
19 namespace seqan3
20 {
21 
22 // ------------------------------------------------------------------
23 // seqan3::fmtflags2
24 // ------------------------------------------------------------------
25 
29 {
30  none = 0,
31  utf8 = 1,
32  small_int_as_number = 1 << 1,
35 };
36 
38 template <>
40 
41 // ------------------------------------------------------------------
42 // seqan3::debug_stream_type
43 // ------------------------------------------------------------------
44 
69 template <typename char_t = char>
71 {
72 public:
77  debug_stream_type() = default;
78  debug_stream_type(debug_stream_type const &) = default;
82  ~debug_stream_type() = default;
83 
85  constexpr explicit debug_stream_type(std::basic_ostream<char_t> & out) : stream{&out}
86  {}
88 
110  {
111  stream = &out;
112  }
114 
118  template <typename other_char_t, typename t>
121 
124  {
125  *stream << fp;
126  return *this;
127  }
128 
130  debug_stream_type & operator<<(int8_t const v)
131  {
133  *stream << static_cast<int>(v);
134  else
135  *stream << v;
136  return *this;
137  }
138 
139  debug_stream_type & operator<<(uint8_t const v)
140  {
142  *stream << static_cast<unsigned>(v);
143  else
144  *stream << v;
145  return *this;
146  }
149 
152 
157  fmtflags flags() const
159  {
160  return stream->flags();
161  }
162 
164  fmtflags flags(fmtflags const flgs)
165  {
166  return stream->flags(flgs);
167  }
168 
170  void setf(fmtflags const flag)
171  {
172  stream->setf(flag);
173  }
174 
176  void unsetf(fmtflags const flag)
177  {
178  stream->unsetf(flag);
179  }
180 
183  {
184  setf(flag);
185  return *this;
186  }
188 
193  fmtflags2 flags2() const
195  {
196  return flgs2;
197  }
198 
201  {
202  flgs2 = flgs;
203  return flgs2;
204  }
205 
207  void setf(fmtflags2 const flag)
208  {
209  flgs2 |= flag;
210  }
211 
213  void unsetf(fmtflags2 const flag)
214  {
215  flgs2 &= ~flag;
216  }
217 
220  {
221  setf(flag);
222  return *this;
223  }
225 
226 private:
228  std::basic_ostream<char_t> *stream/* = &std::cerr*/;
229 
231  fmtflags2 flgs2{fmtflags2::default_};
232 };
233 
235 template <typename char_t, typename t>
236 debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, t && v)
237 {
238  (*s.stream) << v;
239  return s;
240 }
241 
242 } // namespace seqan3
seqan3::small_int_as_number
@ small_int_as_number
Definition: debug_stream_type.hpp:32
seqan3::utf8
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition: debug_stream_type.hpp:31
seqan3::debug_stream_type::operator<<
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:219
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:170
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:85
seqan3::debug_stream_type::fmtflags
decltype(std::declval< std::basic_ostream< char_t > >().flags()) fmtflags
This type is std::ios_base::fmtflags.
Definition: debug_stream_type.hpp:151
seqan3::debug_stream_type::operator<<
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:182
iosfwd
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.
seqan3::debug_stream_type::flags2
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:194
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:207
seqan3::debug_stream_type::debug_stream_type
debug_stream_type(debug_stream_type const &)=default
Defaulted.
seqan3::debug_stream_type::flags
fmtflags flags() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:158
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:71
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:164
std::basic_ostream
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::debug_stream_type::unsetf
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:176
seqan3::debug_stream_type::unsetf
void unsetf(fmtflags2 const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:213
seqan3::add_enum_bitwise_operators< fmtflags2 >
constexpr bool add_enum_bitwise_operators< fmtflags2 >
Overload bitwise operators for seqan3::fmtflags2.
Definition: debug_stream_type.hpp:39
add_enum_bitwise_operators.hpp
Provides seqan3::add_enum_bitwise_operators.
seqan3::debug_stream_type::debug_stream_type
debug_stream_type(debug_stream_type &&)=default
Defaulted.
seqan3::fmtflags2
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition: debug_stream_type.hpp:29
seqan3::operator<<
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:103
seqan3::none
@ none
No flag is set.
Definition: debug_stream_type.hpp:30
seqan3::debug_stream_type::operator=
debug_stream_type & operator=(debug_stream_type const &)=default
Defaulted.
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:109
seqan3::debug_stream_type::debug_stream_type
debug_stream_type()=default
Defaulted.
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:123
std::declval
T declval(T... args)
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:200