OpenMS
|
Class for writing data which spans multiple lines with an indentation for each line (all except the first). More...
#include <OpenMS/FORMAT/IndentedStream.h>
Public Types | |
typedef std::ostream &(* | StreamManipulator) (std::ostream &) |
Function pointer to a function that takes an ostream, and returns it, e.g. std::endl. More... | |
Public Member Functions | |
IndentedStream (std::ostream &stream, const UInt indentation, const UInt max_lines) | |
C'tor. More... | |
~IndentedStream () | |
D'tor flushes the stream. More... | |
IndentedStream & | operator<< (Colorizer &colorizer) |
IndentedStream & | operator<< (IndentedStream &self) |
Support calling our member functions within a stream. More... | |
template<typename T > | |
IndentedStream & | operator<< (const T &data) |
IndentedStream & | operator<< (StreamManipulator manip) |
Overload for function pointers, e.g. std::endl. More... | |
IndentedStream & | indent (const UInt new_indent) |
Private Attributes | |
std::ostream * | stream_ |
the underlying stream to print to More... | |
UInt | indentation_ |
number of spaces in prefix of each line More... | |
UInt | max_lines_ |
maximum number of lines a single item is split into before excess lines are replaced by '...' More... | |
UInt | max_line_width_ |
width of console/output More... | |
Size | current_column_pos_ = 0 |
length of last(=current) line More... | |
Class for writing data which spans multiple lines with an indentation for each line (all except the first).
Internally, ConsoleUtils is used to determine the width of the current console.
The stream that is written to can be any ostream (including stdout or stderr).
If a single item passed to IndentedStream::operator<< spans multiple indented lines (e.g. a large string), at most max_lines
will be retained (excess lines will be replaced by '...').
You can manually insert extra linebreaks by pushing '
' into the stream (they can be part of a larger string).
The class supports coloring its output if the underlying stream
is either std::cout or cerr by passing a Colorizer.
Upon destruction of IndentedStream, the underlying stream
is flushed.
typedef std::ostream&(* StreamManipulator) (std::ostream &) |
Function pointer to a function that takes an ostream, and returns it, e.g. std::endl.
IndentedStream | ( | std::ostream & | stream, |
const UInt | indentation, | ||
const UInt | max_lines | ||
) |
C'tor.
stream | Underlying stream to write to (its lifetime must exceed the one of this IndentedStream) |
indentation | Number of spaces in front of each new line written to stream |
max_lines | Shorten excessive single items to at most this many number of lines (replacing excess with '...') |
~IndentedStream | ( | ) |
D'tor flushes the stream.
IndentedStream& indent | ( | const UInt | new_indent | ) |
Support new indentation, on the fly. This will take effect when the next line break is encountered (either manual or automatic linebreak (at the right side of the console).
IndentedStream& operator<< | ( | Colorizer & | colorizer | ) |
Support normal usage of Colorizer (for coloring cout/cerr). The underlying stream will receive ANSI codes unless its a redirected(!) cout/cerr. Warning: the ANSI codes are NOT considered to advance the cursor and will lead to broken formatting if the underlying stream
is NOT cout/cerr. I.e. using an IndentedStream with an underlying stringstream in combination with a Colorizer will mess up the formatting.
|
inline |
IndentedStream& operator<< | ( | IndentedStream & | self | ) |
Support calling our member functions within a stream.
IndentedStream& operator<< | ( | StreamManipulator | manip | ) |
Overload for function pointers, e.g. std::endl.
|
private |
length of last(=current) line
|
private |
number of spaces in prefix of each line
|
private |
width of console/output
|
private |
maximum number of lines a single item is split into before excess lines are replaced by '...'
|
private |
the underlying stream to print to