TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
Format and print a text document using various output types and indentation. More...
#include <tsTextFormatter.h>
Public Types | |
enum class | EndOfLineMode { NATIVE , CR , LF , CRLF , SPACING , NONE } |
End-of-line mode. More... | |
using | SuperClass = std::basic_ostream< char > |
Explicit reference to the public superclass. | |
Public Member Functions | |
TextFormatter (Report &report=(ts::NullReport::Instance())) | |
Constructor. | |
virtual | ~TextFormatter () override |
Destructor. | |
void | close () |
Close the current output. | |
TextFormatter & | column (size_t col) |
Insert all necessary new-lines and spaces to move to a given column. | |
TextFormatter & | endl () |
Insert an end-of-line, according to the current end-of-line mode. | |
EndOfLineMode | endOfLineMode () const |
Get the end-of-line mode. | |
bool | formatting () const |
Check if formatting (margin, indentation) is in effect. | |
bool | getString (UString &str) |
Retrieve the current content of the internal string buffer. | |
TextFormatter & | indent () |
Push one indentation level, typically when formatting child items. | |
size_t | indentSize () const |
Get the indent size for inner elements. | |
bool | isOpen () const |
Check if the Output is open to some output. | |
TextFormatter & | margin () |
Insert all necessary new-lines and spaces to move to the current margin. | |
size_t | marginSize () const |
Get the margin size for outer-most elements. | |
Report & | report () const |
Get the current report for log and error messages. | |
TextFormatter & | setEndOfLineMode (EndOfLineMode mode) |
Set the end-of-line mode. | |
bool | setFile (const fs::path &fileName) |
Set output to a text file. | |
TextFormatter & | setIndentSize (size_t indent) |
Set the indent size for inner elements. | |
TextFormatter & | setMarginSize (size_t margin) |
Set the margin size for outer-most elements. | |
TextFormatter & | setStream (std::ostream &strm) |
Set output to an open text stream. | |
TextFormatter & | setString () |
Set output to an internal string buffer. | |
TextFormatter & | spaces (size_t count) |
Output spaces on the stream. | |
UString | toString () |
Return the current content of the internal string buffer. | |
TextFormatter & | unindent () |
Pop one indentation level, typically when formatting back to parent. | |
Static Public Attributes | |
static constexpr size_t | DEFAULT_STREAM_BUFFER_SIZE = 1024 |
Default stream buffer size in bytes. | |
Protected Member Functions | |
virtual bool | writeStreamBuffer (const void *addr, size_t size) override |
Write buffered data to underlying output devicen whatever it is. | |
Format and print a text document using various output types and indentation.
This class is used to format XML documents or other types of structured text output. It is a subclass of std::ostream
and can be used as any output stream. It also defines additional I/O manipulators to handle indentation.
|
strong |
End-of-line mode.
|
explicit |
Constructor.
[in,out] | report | Where to report errors. |
|
inline |
Get the current report for log and error messages.
|
inline |
Get the margin size for outer-most elements.
TextFormatter & ts::TextFormatter::setMarginSize | ( | size_t | margin | ) |
Set the margin size for outer-most elements.
[in] | margin | The margin size for outer-most elements. |
|
inline |
Get the indent size for inner elements.
|
inline |
Set the indent size for inner elements.
[in] | indent | The indent size for inner elements. |
|
inline |
Get the end-of-line mode.
TextFormatter & ts::TextFormatter::setEndOfLineMode | ( | EndOfLineMode | mode | ) |
Set the end-of-line mode.
[in] | mode | The new end-of-line mode. |
|
inline |
Check if formatting (margin, indentation) is in effect.
When end-of-line mode is SPACING or NONE, formatting is disabled, margin and indentation are ignored.
TextFormatter & ts::TextFormatter::setStream | ( | std::ostream & | strm | ) |
Set output to an open text stream.
[in,out] | strm | The output text stream. The referenced stream object must remain valid as long as this object. |
bool ts::TextFormatter::setFile | ( | const fs::path & | fileName | ) |
Set output to a text file.
[in] | fileName | Output file name. |
TextFormatter & ts::TextFormatter::setString | ( | ) |
bool ts::TextFormatter::getString | ( | UString & | str | ) |
Retrieve the current content of the internal string buffer.
Must be called after setString() and before close().
[out] | str | Returned string containing the formatted document. |
UString ts::TextFormatter::toString | ( | ) |
Return the current content of the internal string buffer.
Must be called after setString() and before close().
bool ts::TextFormatter::isOpen | ( | ) | const |
Check if the Output is open to some output.
void ts::TextFormatter::close | ( | ) |
Close the current output.
Depending on the output mode:
TextFormatter & ts::TextFormatter::margin | ( | ) |
Insert all necessary new-lines and spaces to move to the current margin.
TextFormatter & ts::TextFormatter::column | ( | size_t | col | ) |
Insert all necessary new-lines and spaces to move to a given column.
[in] | col | The column position to move to. The first character of a line is at column 0. |
TextFormatter & ts::TextFormatter::endl | ( | ) |
Insert an end-of-line, according to the current end-of-line mode.
TextFormatter & ts::TextFormatter::spaces | ( | size_t | count | ) |
Output spaces on the stream.
[in] | count | Number of spaces to print. |
|
inline |
Push one indentation level, typically when formatting child items.
|
inline |
Pop one indentation level, typically when formatting back to parent.
|
overrideprotectedvirtual |
Write buffered data to underlying output devicen whatever it is.
Must be implemented by subclasses.
[in] | addr | Buffered data address. |
[in] | size | Buffered data size in bytes. |
Implements ts::AbstractOutputStream.