Public Types | Public Member Functions | Private Attributes | List of all members
dump::DumperBase::Indenter< Stream > Class Template Reference

Helper class to keep track of indenting. More...

#include <DumperBase.h>

Public Types

using indenter_t = Indenter< Stream >
 This type. More...
 

Public Member Functions

 Indenter (Stream out, DumperBase const &dumper)
 Records the underlying stream and the dumper associated. More...
 
std::string const & indentString () const
 Returns the default indentation string. More...
 
std::string const & firstIndentString () const
 Returns the indentation string for the first line. More...
 
template<typename T >
indenter_toperator<< (T &&v)
 Forwards data to the underlying stream. More...
 
indenter_tindent (bool first=false)
 Inserts an indentation and returns the indenter for further output. More...
 
indenter_tnewline ()
 Breaks the current line and returns the indenter for further output. More...
 
indenter_tstart ()
 

Private Attributes

Stream out
 
DumperBase const & dumper
 

Detailed Description

template<typename Stream>
class dump::DumperBase::Indenter< Stream >

Helper class to keep track of indenting.

Template Parameters
Streamtype of output stream the class is using

This class is single use, tied to a dumper and to a stream instance. It does not attempt to keep track of whether the output line is the first or not, and it does not try to detect end-of-line characters in the passed strings to insert internal indentation.

Each object is tied to a dump::DumperBase object and it reflects its indentation settings, i.e. if indentation settings of the dump::DumperBase object are changed, the tied Indenter object will reflect the new settings.

Example of usage:

out.start() << "Here is the list of things to do:"; // first line
out.newline() << " (1) first thing";
out.newline() << " (2) third thing";
out.newline() << " (3) fourth thing"
<< "\n" << out.indentString() << " (if allowed)";
out << std::endl;
}

Note how the manual indentation is more complicate than the "implicit" one.

Definition at line 162 of file DumperBase.h.

Member Typedef Documentation

template<typename Stream>
using dump::DumperBase::Indenter< Stream >::indenter_t = Indenter<Stream>

This type.

Definition at line 167 of file DumperBase.h.

Constructor & Destructor Documentation

template<typename Stream>
dump::DumperBase::Indenter< Stream >::Indenter ( Stream  out,
DumperBase const &  dumper 
)
inline

Records the underlying stream and the dumper associated.

Definition at line 170 of file DumperBase.h.

171  : out(std::forward<Stream>(out)), dumper(dumper) {}
DumperBase const & dumper
Definition: DumperBase.h:164

Member Function Documentation

template<typename Stream>
std::string const& dump::DumperBase::Indenter< Stream >::firstIndentString ( ) const
inline

Returns the indentation string for the first line.

Definition at line 177 of file DumperBase.h.

178  { return dumper.firstIndent(); }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:99
DumperBase const & dumper
Definition: DumperBase.h:164
template<typename Stream>
indenter_t& dump::DumperBase::Indenter< Stream >::indent ( bool  first = false)
inline

Inserts an indentation and returns the indenter for further output.

Definition at line 186 of file DumperBase.h.

187  { dumper.indented(out, first); return *this; }
DumperBase const & dumper
Definition: DumperBase.h:164
Stream & indented(Stream &&out, bool first=false) const
Writes the indentation into a stream, and returns it for further output.
Definition: DumperBase.h:112
template<typename Stream>
std::string const& dump::DumperBase::Indenter< Stream >::indentString ( ) const
inline

Returns the default indentation string.

Definition at line 174 of file DumperBase.h.

174 { return dumper.indent(); }
DumperBase const & dumper
Definition: DumperBase.h:164
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:96
template<typename Stream>
indenter_t& dump::DumperBase::Indenter< Stream >::newline ( )
inline

Breaks the current line and returns the indenter for further output.

Definition at line 190 of file DumperBase.h.

190 { out << '\n'; return indent(); }
indenter_t & indent(bool first=false)
Inserts an indentation and returns the indenter for further output.
Definition: DumperBase.h:186
template<typename Stream>
template<typename T >
indenter_t& dump::DumperBase::Indenter< Stream >::operator<< ( T &&  v)
inline

Forwards data to the underlying stream.

Definition at line 182 of file DumperBase.h.

183  { out << std::forward<T>(v); return *this; }
template<typename Stream>
indenter_t& dump::DumperBase::Indenter< Stream >::start ( )
inline

Inserts a first-line indentation and returns the indenter for further output.

Definition at line 194 of file DumperBase.h.

194 { return indent(true); }
indenter_t & indent(bool first=false)
Inserts an indentation and returns the indenter for further output.
Definition: DumperBase.h:186

Member Data Documentation

template<typename Stream>
DumperBase const& dump::DumperBase::Indenter< Stream >::dumper
private

Definition at line 164 of file DumperBase.h.

template<typename Stream>
Stream dump::DumperBase::Indenter< Stream >::out
private

Definition at line 163 of file DumperBase.h.


The documentation for this class was generated from the following file: