SeqAn3  3.0.1
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,
33  default_ = small_int_as_number
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;
79  debug_stream_type(debug_stream_type &&) = default;
80  debug_stream_type & operator= (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 t>
121  {
122  *stream << v;
123  return *this;
124  }
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 
161  fmtflags flags() const
163  {
164  return stream->flags();
165  }
166 
168  fmtflags flags(fmtflags const flgs)
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 
187  {
188  setf(flag);
189  return *this;
190  }
192 
197  fmtflags2 flags2() const
199  {
200  return flgs2;
201  }
202 
205  {
206  flgs2 = flgs;
207  return flgs2;
208  }
209 
211  void setf(fmtflags2 const flag)
212  {
213  flgs2 |= flag;
214  }
215 
217  void unsetf(fmtflags2 const flag)
218  {
219  flgs2 &= ~flag;
220  }
221 
224  {
225  setf(flag);
226  return *this;
227  }
229 
230 private:
232  std::basic_ostream<char_t> *stream/* = &std::cerr*/;
233 
235  fmtflags2 flgs2{fmtflags2::default_};
236 };
237 
238 } // namespace seqan3
seqan3::small_int_as_number
Definition: debug_stream_type.hpp:32
seqan3::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:223
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:174
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:155
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:186
iosfwd
seqan3::debug_stream_type::flags2
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:198
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:211
seqan3::debug_stream_type::flags
fmtflags flags() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:162
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:70
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:168
std::basic_ostream< char_t >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
std::basic_ostream::setf
T setf(T... args)
seqan3::debug_stream_type::unsetf
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:180
std::basic_ostream::flags
T flags(T... args)
seqan3::debug_stream_type::operator<<
debug_stream_type & operator<<(t &&v)
Forwards to the underlying stream object.
Definition: debug_stream_type.hpp:120
seqan3::debug_stream_type::unsetf
void unsetf(fmtflags2 const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:217
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::fmtflags2
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition: debug_stream_type.hpp:28
seqan3::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::field::flag
The alignment flag (bit information), uint16_t value.
std::basic_ostream::unsetf
T unsetf(T... args)
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:127
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:204