SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
debug_stream_type.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 
31 {
32  none = 0,
33  utf8 = 1,
34  small_int_as_number = 1 << 1,
36  default_ = small_int_as_number
37 };
38 
42 template <>
43 constexpr bool add_enum_bitwise_operators<fmtflags2> = true;
45 
46 // ------------------------------------------------------------------
47 // seqan3::debug_stream_type
48 // ------------------------------------------------------------------
49 
74 template <typename char_t = char>
76 {
77 public:
82  debug_stream_type() = default;
83  debug_stream_type(debug_stream_type const &) = default;
87  ~debug_stream_type() = default;
88 
90  constexpr explicit debug_stream_type(std::basic_ostream<char_t> & out) : stream{&out}
91  {}
93 
115  {
116  stream = &out;
117  }
119 
124  template <typename other_char_t, typename t>
126 
129  {
130  *stream << fp;
131  return *this;
132  }
133 
135  debug_stream_type & operator<<(int8_t const v)
136  {
138  *stream << static_cast<int>(v);
139  else
140  *stream << v;
141  return *this;
142  }
143 
144  debug_stream_type & operator<<(uint8_t const v)
145  {
147  *stream << static_cast<unsigned>(v);
148  else
149  *stream << v;
150  return *this;
151  }
154 
157 
163  fmtflags flags() const
164  {
165  return stream->flags();
166  }
167 
169  fmtflags flags(fmtflags const flgs)
170  {
171  return stream->flags(flgs);
172  }
173 
175  void setf(fmtflags const flag)
176  {
177  stream->setf(flag);
178  }
179 
181  void unsetf(fmtflags const flag)
182  {
183  stream->unsetf(flag);
184  }
185 
188  {
189  setf(flag);
190  return *this;
191  }
193 
200  {
201  return flgs2;
202  }
203 
206  {
207  flgs2 = flgs;
208  return flgs2;
209  }
210 
212  void setf(fmtflags2 const flag)
213  {
214  flgs2 |= flag;
215  }
216 
218  void unsetf(fmtflags2 const flag)
219  {
220  flgs2 &= ~flag;
221  }
222 
225  {
226  setf(flag);
227  return *this;
228  }
230 
231 private:
233  std::basic_ostream<char_t> *stream/* = &std::cerr*/;
234 
236  fmtflags2 flgs2{fmtflags2::default_};
237 };
238 
240 template <typename char_t, typename t>
241 debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, t && v)
242 {
243  (*s.stream) << v;
244  return s;
245 }
246 
247 } // namespace seqan3
Provides seqan3::add_enum_bitwise_operators.
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:76
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:199
friend debug_stream_type< other_char_t > & operator<<(debug_stream_type< other_char_t > &s, t &&v)
Forwards to the underlying stream object.
fmtflags2 flags2(fmtflags2 flgs)
Replace the current flags on the stream with the given argument.
Definition: debug_stream_type.hpp:205
constexpr debug_stream_type(std::basic_ostream< char_t > &out)
Construction from an output stream.
Definition: debug_stream_type.hpp:90
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:181
~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:212
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:169
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:175
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:187
debug_stream_type & operator<<(std::ostream &(*fp)(std::ostream &))
This overloads enables forwarding std::endl and other manipulators.
Definition: debug_stream_type.hpp:128
debug_stream_type & operator=(debug_stream_type const &)=default
Defaulted.
fmtflags flags() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:163
decltype(std::declval< std::basic_ostream< char_t > >().flags()) fmtflags
This type is std::ios_base::fmtflags.
Definition: debug_stream_type.hpp:156
void unsetf(fmtflags2 const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:218
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:224
void set_underlying_stream(std::basic_ostream< char_t > &out)
Change the underlying output stream.
Definition: debug_stream_type.hpp:114
T declval(T... args)
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:101
@ flag
The alignment flag (bit information), uint16_t value.
fmtflags2
Flags that change the behaviour of the seqan3::debug_stream.
Definition: debug_stream_type.hpp:31
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition: debug_stream_type.hpp:33
@ small_int_as_number
Definition: debug_stream_type.hpp:34
@ none
No flag is set.
Definition: debug_stream_type.hpp:32
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29