LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
recob::dumper::NewLine< Stream > Class Template Reference

Starts a new line in a output stream. More...

#include "NewLine.h"

Public Member Functions

 NewLine (Stream &stream, IndentOptions_t indentOptions)
 Constructor: associates with the stream. More...
 
 NewLine (Stream &stream, std::string indent="", bool followLine=false)
 Constructor: associates with the stream. More...
 
Stream & newLine ()
 Starts a new line. More...
 
Stream & operator() ()
 Calls and returns newLine(). Candy. More...
 
void forceNewLine ()
 Starts a new line (no matter what) More...
 
bool append () const
 Returns whether newLine() will append text on the current line. More...
 
void setIndent (std::string newIndent)
 Replaces the indentation string. More...
 
void addIndent (std::string moreIndent)
 Adds to the end to the indentation string. More...
 
Accessors
unsigned int lines () const
 Returns the number of inserted lines. More...
 
std::string indent () const
 Returns the current indentation string. More...
 

Protected Attributes

Stream & out
 reference to the output stream More...
 
IndentOptions_t options
 all indentation options More...
 
unsigned int nLines
 number of lines in output More...
 

Detailed Description

template<typename Stream>
class recob::dumper::NewLine< Stream >

Starts a new line in a output stream.

Template Parameters
Streamtype of output stream

Example of usage:

std::cout << "Preamble on its own line." << std::endl;
NewLine OutLn(std::cout, "> ");
OutLn() << "An indented line.";
OutLn() << "Another indented line.";

that (after flush) will result in the output

Preamble on its own line.

> An indented line.
> Another indented line.

Asking to consider the first line already started, instead:

std::cout << "Preamble on its own line." << std::endl;
NewLine OutLn(std::cout, "> ", true);
OutLn() << "An indented line.";
OutLn() << "Another indented line.";

will instead result in the output

Preamble on its own line.
> An indented line.
> Another indented line.

(note that the line that we consider started was actually an empty one).

Definition at line 76 of file NewLine.h.

Constructor & Destructor Documentation

template<typename Stream>
recob::dumper::NewLine< Stream >::NewLine ( Stream &  stream,
IndentOptions_t  indentOptions 
)
inline

Constructor: associates with the stream.

Parameters
streama reference to the stream where to insert new lines
indentOptionsall indentation options (will be copied)

The constructor does not start a new line. If followLine is true, the first line is supposed to be already started and no indentation nor new line will be set on it.

Definition at line 87 of file NewLine.h.

88  : out(stream), options(std::move(indentOptions)), nLines(0)
89  {}
unsigned int nLines
number of lines in output
Definition: NewLine.h:142
Stream & out
reference to the output stream
Definition: NewLine.h:140
IndentOptions_t options
all indentation options
Definition: NewLine.h:141
template<typename Stream>
recob::dumper::NewLine< Stream >::NewLine ( Stream &  stream,
std::string  indent = "",
bool  followLine = false 
)
inline

Constructor: associates with the stream.

Parameters
streama reference to the stream where to insert new lines
indentstring used for indentation (default: none)
followLinewhether first line is already started (default: no)

The constructor does not start a new line. If followLine is true, the first line is supposed to be already started and no indentation nor new line will be set on it.

Definition at line 101 of file NewLine.h.

References recob::dumper::IndentOptions_t::indent.

102  : NewLine(stream, IndentOptions_t{indent, followLine})
103  {}
std::string indent() const
Returns the current indentation string.
Definition: NewLine.h:112
NewLine(Stream &stream, IndentOptions_t indentOptions)
Constructor: associates with the stream.
Definition: NewLine.h:87

Member Function Documentation

template<typename Stream>
void recob::dumper::NewLine< Stream >::addIndent ( std::string  moreIndent)
inline

Adds to the end to the indentation string.

Definition at line 137 of file NewLine.h.

137 { options.indent += moreIndent; }
std::string indent
indentation string
Definition: NewLine.h:20
IndentOptions_t options
all indentation options
Definition: NewLine.h:141
template<typename Stream>
bool recob::dumper::NewLine< Stream >::append ( ) const
inline

Returns whether newLine() will append text on the current line.

Definition at line 131 of file NewLine.h.

131 { return (lines() == 0) && options.appendFirst; }
unsigned int lines() const
Returns the number of inserted lines.
Definition: NewLine.h:109
bool appendFirst
skip indentation on the first line
Definition: NewLine.h:21
IndentOptions_t options
all indentation options
Definition: NewLine.h:141
template<typename Stream>
void recob::dumper::NewLine< Stream >::forceNewLine ( )
inline

Starts a new line (no matter what)

Definition at line 128 of file NewLine.h.

128 { out << "\n" << options.indent; }
std::string indent
indentation string
Definition: NewLine.h:20
Stream & out
reference to the output stream
Definition: NewLine.h:140
IndentOptions_t options
all indentation options
Definition: NewLine.h:141
template<typename Stream>
std::string recob::dumper::NewLine< Stream >::indent ( ) const
inline

Returns the current indentation string.

Definition at line 112 of file NewLine.h.

112 { return options.indent; }
std::string indent
indentation string
Definition: NewLine.h:20
IndentOptions_t options
all indentation options
Definition: NewLine.h:141
template<typename Stream>
unsigned int recob::dumper::NewLine< Stream >::lines ( ) const
inline

Returns the number of inserted lines.

Definition at line 109 of file NewLine.h.

109 { return nLines; }
unsigned int nLines
number of lines in output
Definition: NewLine.h:142
template<typename Stream>
Stream& recob::dumper::NewLine< Stream >::newLine ( )
inline

Starts a new line.

Definition at line 117 of file NewLine.h.

118  {
119  if (!append()) forceNewLine();
120  ++nLines;
121  return out;
122  }
unsigned int nLines
number of lines in output
Definition: NewLine.h:142
Stream & out
reference to the output stream
Definition: NewLine.h:140
void forceNewLine()
Starts a new line (no matter what)
Definition: NewLine.h:128
bool append() const
Returns whether newLine() will append text on the current line.
Definition: NewLine.h:131
template<typename Stream>
Stream& recob::dumper::NewLine< Stream >::operator() ( )
inline

Calls and returns newLine(). Candy.

Definition at line 125 of file NewLine.h.

125 { return newLine(); }
Stream & newLine()
Starts a new line.
Definition: NewLine.h:117
template<typename Stream>
void recob::dumper::NewLine< Stream >::setIndent ( std::string  newIndent)
inline

Replaces the indentation string.

Definition at line 134 of file NewLine.h.

134 { options.indent = newIndent; }
std::string indent
indentation string
Definition: NewLine.h:20
IndentOptions_t options
all indentation options
Definition: NewLine.h:141

Member Data Documentation

template<typename Stream>
unsigned int recob::dumper::NewLine< Stream >::nLines
protected

number of lines in output

Definition at line 142 of file NewLine.h.

template<typename Stream>
IndentOptions_t recob::dumper::NewLine< Stream >::options
protected

all indentation options

Definition at line 141 of file NewLine.h.

template<typename Stream>
Stream& recob::dumper::NewLine< Stream >::out
protected

reference to the output stream

Definition at line 140 of file NewLine.h.


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