Public Member Functions | Protected Attributes | List of all members
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 74 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 86 of file NewLine.h.

87  : out(stream), options(std::move(indentOptions)), nLines(0)
88  {}
unsigned int nLines
number of lines in output
Definition: NewLine.h:138
Stream & out
reference to the output stream
Definition: NewLine.h:136
def move(depos, offset)
Definition: depos.py:107
IndentOptions_t options
all indentation options
Definition: NewLine.h:137
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 100 of file NewLine.h.

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

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 132 of file NewLine.h.

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

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

Definition at line 125 of file NewLine.h.

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

Starts a new line (no matter what)

Definition at line 122 of file NewLine.h.

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

Returns the current indentation string.

Definition at line 111 of file NewLine.h.

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

Returns the number of inserted lines.

Definition at line 108 of file NewLine.h.

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

Starts a new line.

Definition at line 116 of file NewLine.h.

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

Calls and returns newLine(). Candy.

Definition at line 119 of file NewLine.h.

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

Replaces the indentation string.

Definition at line 129 of file NewLine.h.

129 { options.indent = newIndent; }
std::string indent
indentation string
Definition: NewLine.h:21
IndentOptions_t options
all indentation options
Definition: NewLine.h:137

Member Data Documentation

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

number of lines in output

Definition at line 138 of file NewLine.h.

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

all indentation options

Definition at line 137 of file NewLine.h.

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

reference to the output stream

Definition at line 136 of file NewLine.h.


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