LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
dump::DumperBase Class Reference

Base class for data dumpers. More...

#include "DumperBase.h"

Inheritance diagram for dump::DumperBase:
dump::raw::OpDetWaveformDumper

Classes

class  Indenter
 Helper class to keep track of indenting. More...
 
struct  IndentSettings
 

Public Member Functions

 DumperBase ()
 Default constructor: no indentation. More...
 
 DumperBase (std::string const &indent, std::string const &firstIndent)
 Constructor: sets indentation. More...
 
 DumperBase (std::string const &indent)
 Constructor: sets indentation. More...
 
template<typename Stream >
decltype(auto) indenter (Stream &&out) const
 Returns an Indenter object tied to this dumper and out stream. More...
 
Indentation.

Indentation strings are expected to be written by the dumping algorithms at the beginning of each output line to ensure the proper alignment of the dump. The indent() string should be written at the beginning of every new output line, with the exception of the first one, for which firstIndent() should be written instead.

Note that this infrastructure only keeps track of the strings needed to indent the output, but it does not provide any tool to apply the indentation.

std::string const & indent () const
 Returns the indentation string currently configured for all lines. More...
 
std::string const & firstIndent () const
 Returns the indentation string currently configured for the first line. More...
 
void setIndent (std::string const &indent, std::string const &firstIndent)
 Sets indentation strings to the specified values. More...
 
void setIndent (std::string const &indent)
 Sets both indentation strings to the same specified value. More...
 
template<typename Stream >
Stream & indented (Stream &&out, bool first=false) const
 Writes the indentation into a stream, and returns it for further output. More...
 
template<typename Stream >
Stream & firstIndented (Stream &&out) const
 
template<typename Stream >
Stream & newline (Stream &&out) const
 

Protected Member Functions

IndentSettingsindentSettings ()
 
IndentSettings const & indentSettings () const
 
IndentSettingssaveIndentSettings ()
 Stacks a copy of the current settings, and returns the "new" ones. More...
 
IndentSettingsrestoreIndentSettings ()
 Restores and returns the last saved settings. More...
 

Private Attributes

std::vector< IndentSettingsfIndentSettings
 All indentation settings. More...
 

Detailed Description

Base class for data dumpers.

This class provides some basic and common infrastructure:

  • managing of indentation strings

Definition at line 37 of file DumperBase.h.

Constructor & Destructor Documentation

dump::DumperBase::DumperBase ( )
inline

Default constructor: no indentation.

Definition at line 61 of file DumperBase.h.

61 : fIndentSettings{{}} {}
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
dump::DumperBase::DumperBase ( std::string const &  indent,
std::string const &  firstIndent 
)
inline

Constructor: sets indentation.

Parameters
indentindentation for all lines except the first one (see indent())
firstIndentindentation for the first line (see firstIndent())

Definition at line 69 of file DumperBase.h.

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

71  {}
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:98
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
dump::DumperBase::DumperBase ( std::string const &  indent)
inline

Constructor: sets indentation.

Parameters
indentindentation for all lines

Definition at line 77 of file DumperBase.h.

std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
DumperBase()
Default constructor: no indentation.
Definition: DumperBase.h:61

Member Function Documentation

std::string const& dump::DumperBase::firstIndent ( ) const
inline

Returns the indentation string currently configured for the first line.

Definition at line 98 of file DumperBase.h.

References dump::DumperBase::IndentSettings::firstIndent, and indentSettings().

Referenced by dump::DumperBase::Indenter< Stream >::firstIndentString().

98 { return indentSettings().firstIndent; }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::string firstIndent
Indentation string for the first line.
Definition: DumperBase.h:41
template<typename Stream >
Stream& dump::DumperBase::firstIndented ( Stream &&  out) const
inline

Writes first line indentation into a stream, and returns it for further output.

Definition at line 120 of file DumperBase.h.

References indented().

121  {
122  return indented(std::forward<Stream>(out), true);
123  }
Stream & indented(Stream &&out, bool first=false) const
Writes the indentation into a stream, and returns it for further output.
Definition: DumperBase.h:111
std::string const& dump::DumperBase::indent ( ) const
inline

Returns the indentation string currently configured for all lines.

Definition at line 95 of file DumperBase.h.

References dump::DumperBase::IndentSettings::indent, and indentSettings().

Referenced by dump::raw::OpDetWaveformDumper::dump(), and dump::DumperBase::Indenter< Stream >::indentString().

95 { return indentSettings().indent; }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::string indent
Default indentation string.
Definition: DumperBase.h:40
template<typename Stream >
Stream& dump::DumperBase::indented ( Stream &&  out,
bool  first = false 
) const
inline

Writes the indentation into a stream, and returns it for further output.

Definition at line 111 of file DumperBase.h.

References dump::DumperBase::IndentSettings::firstIndent, and dump::DumperBase::IndentSettings::indent.

Referenced by firstIndented(), dump::DumperBase::Indenter< Stream >::indent(), and newline().

112  {
113  out << (first ? firstIndent() : indent());
114  return out;
115  }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:98
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
template<typename Stream >
decltype(auto) dump::DumperBase::indenter ( Stream &&  out) const
inline

Returns an Indenter object tied to this dumper and out stream.

Definition at line 215 of file DumperBase.h.

Referenced by dump::raw::OpDetWaveformDumper::dump().

216  {
217  return Indenter<Stream>(std::forward<Stream>(out), *this);
218  }
IndentSettings& dump::DumperBase::indentSettings ( )
inlineprotected

Definition at line 221 of file DumperBase.h.

Referenced by firstIndent(), indent(), restoreIndentSettings(), saveIndentSettings(), and setIndent().

221 { return fIndentSettings.back(); }
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
IndentSettings const& dump::DumperBase::indentSettings ( ) const
inlineprotected

Definition at line 222 of file DumperBase.h.

222 { return fIndentSettings.back(); }
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
template<typename Stream >
Stream& dump::DumperBase::newline ( Stream &&  out) const
inline

Initiates a new output line, including indentation, and returns the stream for further output.

Definition at line 128 of file DumperBase.h.

References indented().

129  {
130  return indented(std::forward<Stream>(out));
131  }
Stream & indented(Stream &&out, bool first=false) const
Writes the indentation into a stream, and returns it for further output.
Definition: DumperBase.h:111
IndentSettings& dump::DumperBase::restoreIndentSettings ( )
inlineprotected

Restores and returns the last saved settings.

Definition at line 233 of file DumperBase.h.

References indentSettings().

Referenced by dump::raw::OpDetWaveformDumper::dump().

234  {
235  if (fIndentSettings.size() > 1U) fIndentSettings.pop_back();
236  assert(!fIndentSettings.empty());
237  return indentSettings();
238  }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
IndentSettings& dump::DumperBase::saveIndentSettings ( )
inlineprotected

Stacks a copy of the current settings, and returns the "new" ones.

Definition at line 225 of file DumperBase.h.

References indentSettings().

Referenced by dump::raw::OpDetWaveformDumper::dump().

226  {
227  auto oldSettings = indentSettings();
228  fIndentSettings.push_back(std::move(oldSettings));
229  return indentSettings();
230  }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
void dump::DumperBase::setIndent ( std::string const &  indent,
std::string const &  firstIndent 
)
inline

Sets indentation strings to the specified values.

Definition at line 101 of file DumperBase.h.

References dump::DumperBase::IndentSettings::indent, and indentSettings().

102  {
104  }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:98
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
void dump::DumperBase::setIndent ( std::string const &  indent)
inline

Sets both indentation strings to the same specified value.

Definition at line 107 of file DumperBase.h.

References setIndent().

Referenced by setIndent().

107 { setIndent(indent, indent); }
void setIndent(std::string const &indent, std::string const &firstIndent)
Sets indentation strings to the specified values.
Definition: DumperBase.h:101
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95

Member Data Documentation

std::vector<IndentSettings> dump::DumperBase::fIndentSettings
private

All indentation settings.

Definition at line 57 of file DumperBase.h.


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