Classes | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
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:

Definition at line 39 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:56
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.

71  {}
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:99
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:96
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:56
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:96
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 99 of file DumperBase.h.

100  { return indentSettings().firstIndent; }
IndentSettings & indentSettings()
Definition: DumperBase.h:207
std::string firstIndent
Indentation string for the first line.
Definition: DumperBase.h:43
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 118 of file DumperBase.h.

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

Returns the indentation string currently configured for all lines.

Definition at line 96 of file DumperBase.h.

96 { return indentSettings().indent; }
IndentSettings & indentSettings()
Definition: DumperBase.h:207
std::string indent
Default indentation string.
Definition: DumperBase.h:42
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 112 of file DumperBase.h.

113  { out << (first? firstIndent(): indent()); return out; }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:99
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:96
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 202 of file DumperBase.h.

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

Definition at line 207 of file DumperBase.h.

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

Definition at line 208 of file DumperBase.h.

209  { return fIndentSettings.back(); }
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:56
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 124 of file DumperBase.h.

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

Restores and returns the last saved settings.

Definition at line 220 of file DumperBase.h.

221  {
222  if (fIndentSettings.size() > 1U) fIndentSettings.pop_back();
223  assert(!fIndentSettings.empty());
224  return indentSettings();
225  }
IndentSettings & indentSettings()
Definition: DumperBase.h:207
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:56
IndentSettings& dump::DumperBase::saveIndentSettings ( )
inlineprotected

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

Definition at line 212 of file DumperBase.h.

213  {
214  auto oldSettings = indentSettings();
215  fIndentSettings.push_back(std::move(oldSettings));
216  return indentSettings();
217  }
def move(depos, offset)
Definition: depos.py:107
IndentSettings & indentSettings()
Definition: DumperBase.h:207
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:56
void dump::DumperBase::setIndent ( std::string const &  indent,
std::string const &  firstIndent 
)
inline

Sets indentation strings to the specified values.

Definition at line 103 of file DumperBase.h.

104  { indentSettings() = { indent, firstIndent }; }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:99
IndentSettings & indentSettings()
Definition: DumperBase.h:207
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:96
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.

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

Member Data Documentation

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

All indentation settings.

Definition at line 56 of file DumperBase.h.


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