Stream modifier that makes it "indented". More...
#include <StreamIndenter.h>
Public Member Functions | |
addIndent (std::string indent, std::string firstIndent) | |
addIndent (std::string const &indent) | |
Public Attributes | |
std::string | firstIndent |
std::string | indent |
Stream modifier that makes it "indented".
The intended use of this class is to be "inserted" into an output stream object in order to gain a simple indentation:
firstIndent
will be used to indent the stream;indent
will be used instead.Example:
Technically, after the first insertion (std::cout << addIndent(...)
) the returned object is not std::cout
any more, but a wrapper around it which intercepts all the insertion operations (operator<<
).
The wrapper is designed to steal the stream object if it is a temporary one (e.g. std::ofstream{ "test.txt" } << addIndent("\> ") << ...
) and to reference to it otherwise. Unless the wrapper object is somehow saved, it is destroyed (together with the stream if it was "stolen") as soon as the statement falls out of scope. Therefore, in this two-lines example:
the first line does effectively nothing (the wrapper is created, ready to indent, but it is then immediately destroyed) while the second line performs normal std::cout
output.
std::cout << "A!" << util::addIndent("\> ", "$ ") << "First line.";
will produce A!$ First line.
.Definition at line 69 of file StreamIndenter.h.
|
inline |
Definition at line 72 of file StreamIndenter.h.
|
inline |
Definition at line 75 of file StreamIndenter.h.
std::string util::addIndent::firstIndent |
Definition at line 70 of file StreamIndenter.h.
std::string util::addIndent::indent |
Definition at line 70 of file StreamIndenter.h.