SeqAn3  3.1.0
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 
76 template <typename char_t = char>
78 {
79 public:
84  debug_stream_type() = default;
85  debug_stream_type(debug_stream_type const &) = default;
89  ~debug_stream_type() = default;
90 
92  constexpr explicit debug_stream_type(std::basic_ostream<char_t> & out) : stream{&out}
93  {}
95 
117  {
118  stream = &out;
119  }
121 
126  template <typename other_char_t, typename t>
128 
131  {
132  *stream << fp;
133  return *this;
134  }
135 
137  debug_stream_type & operator<<(int8_t const v)
138  {
140  *stream << static_cast<int>(v);
141  else
142  *stream << v;
143  return *this;
144  }
145 
146  debug_stream_type & operator<<(uint8_t const v)
147  {
149  *stream << static_cast<unsigned>(v);
150  else
151  *stream << v;
152  return *this;
153  }
156 
159 
165  fmtflags flags() const
166  {
167  return stream->flags();
168  }
169 
171  fmtflags flags(fmtflags const flgs)
172  {
173  return stream->flags(flgs);
174  }
175 
177  void setf(fmtflags const flag)
178  {
179  stream->setf(flag);
180  }
181 
183  void unsetf(fmtflags const flag)
184  {
185  stream->unsetf(flag);
186  }
187 
190  {
191  setf(flag);
192  return *this;
193  }
195 
202  {
203  return flgs2;
204  }
205 
208  {
209  flgs2 = flgs;
210  return flgs2;
211  }
212 
214  void setf(fmtflags2 const flag)
215  {
216  flgs2 |= flag;
217  }
218 
220  void unsetf(fmtflags2 const flag)
221  {
222  flgs2 &= ~flag;
223  }
224 
227  {
228  setf(flag);
229  return *this;
230  }
232 
233 private:
235  std::basic_ostream<char_t> *stream/* = &std::cerr*/;
236 
238  fmtflags2 flgs2{fmtflags2::default_};
239 };
240 
242 template <typename char_t, typename t>
243 debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, t && v)
244 {
245  (*s.stream) << v;
246  return s;
247 }
248 
249 } // namespace seqan3
Provides seqan3::add_enum_bitwise_operators.
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:78
fmtflags2 flags2() const
Retrieve the format flags from the stream.
Definition: debug_stream_type.hpp:201
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:207
constexpr debug_stream_type(std::basic_ostream< char_t > &out)
Construction from an output stream.
Definition: debug_stream_type.hpp:92
void unsetf(fmtflags const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:183
~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:214
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:171
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:177
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:189
debug_stream_type & operator<<(std::ostream &(*fp)(std::ostream &))
This overloads enables forwarding std::endl and other manipulators.
Definition: debug_stream_type.hpp:130
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:165
decltype(std::declval< std::basic_ostream< char_t > >().flags()) fmtflags
This type is std::ios_base::fmtflags.
Definition: debug_stream_type.hpp:158
void unsetf(fmtflags2 const flag)
Unset the format flag(s) on the stream.
Definition: debug_stream_type.hpp:220
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:226
void set_underlying_stream(std::basic_ostream< char_t > &out)
Change the underlying output stream.
Definition: debug_stream_type.hpp:116
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
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
@ flag
The alignment flag (bit information), uint16_t value.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29