LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 167 of file DumperBase.h.

Member Typedef Documentation

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

This type.

Definition at line 172 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 175 of file DumperBase.h.

176  : out(std::forward<Stream>(out)), dumper(dumper)
177  {}
DumperBase const & dumper
Definition: DumperBase.h:169

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 183 of file DumperBase.h.

References dump::DumperBase::firstIndent().

183 { return dumper.firstIndent(); }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:98
DumperBase const & dumper
Definition: DumperBase.h:169
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 194 of file DumperBase.h.

References dump::DumperBase::indented().

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

Returns the default indentation string.

Definition at line 180 of file DumperBase.h.

References dump::DumperBase::indent().

180 { return dumper.indent(); }
DumperBase const & dumper
Definition: DumperBase.h:169
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
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 201 of file DumperBase.h.

References dump::DumperBase::IndentSettings::indent.

202  {
203  out << '\n';
204  return indent();
205  }
indenter_t & indent(bool first=false)
Inserts an indentation and returns the indenter for further output.
Definition: DumperBase.h:194
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 187 of file DumperBase.h.

188  {
189  out << std::forward<T>(v);
190  return *this;
191  }
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 209 of file DumperBase.h.

References dump::DumperBase::IndentSettings::indent.

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

Member Data Documentation

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

Definition at line 169 of file DumperBase.h.

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

Definition at line 168 of file DumperBase.h.


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