TSDuck v3.40-4025
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TextTable Class Reference

This class produces a formatted table of text lines and columns. More...

#include <tsTextTable.h>

Public Types

enum class  Align {
  RIGHT ,
  LEFT
}
 Alignment of columns. More...
 
enum class  Headers {
  NONE ,
  TEXT ,
  UNDERLINED
}
 Define the style of top headers. More...
 

Public Member Functions

 TextTable ()=default
 Default constructor.
 
template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool addColumn (ID id, const UString &header, Align align=Align::LEFT)
 Define a column.
 
void clear ()
 Clear the content of the table.
 
size_t columnCount () const
 Get the number of columns in the table.
 
size_t currentLine () const
 Get the current line.
 
size_t lineCount () const
 Get the number of lines in the table.
 
size_t newLine ()
 Creates a new line at the end of the table and make it the current line.
 
void output (std::ostream &out, Headers headers, bool skip_empty=false, const UString &margin=UString(), const UString &separator=u" ") const
 Display the table.
 
template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool setCell (ID column, const StringifyInterface &value)
 Fill a table cell of the current line with text.
 
template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool setCell (ID column, const UString &value)
 Fill a table cell of the current line with text.
 
template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool setCell (size_t line, ID column, const StringifyInterface &value)
 Fill a table cell of the given line with text.
 
template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool setCell (size_t line, ID column, const UString &value)
 Fill a table cell of the given line with text.
 
void setCurrentLine (size_t line)
 Set the current line.
 

Detailed Description

This class produces a formatted table of text lines and columns.

See also
Grid

Comparison with class Grid:

  • Grid creates tables with fixed layout and borders. It fills the fixed-size grid with text. The lines of the table are output on the fly, using an output stream which is associated with the table from the beginning (constructor).
  • TextTable creates variable-size tables without border which are resized according to the content. The table is built in memory. When the table is complete, it can be resized and output.

Member Enumeration Documentation

◆ Align

enum class ts::TextTable::Align
strong

Alignment of columns.

Enumerator
RIGHT 

Align right.

LEFT 

Align left.

◆ Headers

enum class ts::TextTable::Headers
strong

Define the style of top headers.

Enumerator
NONE 

No header.

TEXT 

Simple text line.

UNDERLINED 

Text line and underline.

Member Function Documentation

◆ addColumn()

template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool ts::TextTable::addColumn ( ID  id,
const UString header,
Align  align = Align::LEFT 
)
inline

Define a column.

A new column is added. Columns must be added in order, from left to right. Each column is identified by an identifier, an integer of enumeration value. Content lines will be filled in any order using the id of the column.

Template Parameters
IDAn integral of enumeration type which is used to identify the columns.
Parameters
[in]idIdentifier of the column.
[in]headerTop-column header text.
[in]alignColumn alignment.
Returns
True on success, false if the id column already exists.

◆ setCell() [1/4]

template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool ts::TextTable::setCell ( ID  column,
const UString value 
)
inline

Fill a table cell of the current line with text.

If the table is empty, the first line is implicitly created and becomes the current line.

Template Parameters
IDAn integral of enumeration type which is used to identify the columns.
Parameters
[in]columnIdentifier of the column.
[in]valueText value to set.
Returns
True on success, false if column does not exist.

◆ setCell() [2/4]

template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool ts::TextTable::setCell ( ID  column,
const StringifyInterface value 
)
inline

Fill a table cell of the current line with text.

If the table is empty, the first line is implicitly created and becomes the current line.

Template Parameters
IDAn integral of enumeration type which is used to identify the columns.
Parameters
[in]columnIdentifier of the column.
[in]valueText value to set.
Returns
True on success, false if column does not exist.

◆ setCell() [3/4]

template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool ts::TextTable::setCell ( size_t  line,
ID  column,
const UString value 
)
inline

Fill a table cell of the given line with text.

The current line remains unchanged.

Template Parameters
IDAn integral of enumeration type which is used to identify the columns.
Parameters
[in]lineNumber of the line to fill. If the line does not exist, the table is extended up to that line.
[in]columnIdentifier of the column.
[in]valueText value to set.
Returns
True on success, false if column does not exist.

◆ setCell() [4/4]

template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
bool ts::TextTable::setCell ( size_t  line,
ID  column,
const StringifyInterface value 
)
inline

Fill a table cell of the given line with text.

The current line remains unchanged.

Template Parameters
IDAn integral of enumeration type which is used to identify the columns.
Parameters
[in]lineNumber of the line to fill. If the line does not exist, the table is extended up to that line.
[in]columnIdentifier of the column.
[in]valueText value to set.
Returns
True on success, false if column does not exist.

◆ columnCount()

size_t ts::TextTable::columnCount ( ) const
inline

Get the number of columns in the table.

Returns
The number of columns in the table.

◆ lineCount()

size_t ts::TextTable::lineCount ( ) const
inline

Get the number of lines in the table.

Returns
The number of lines in the table.

◆ newLine()

size_t ts::TextTable::newLine ( )
inline

Creates a new line at the end of the table and make it the current line.

Returns
The index of the new line in the table.

◆ currentLine()

size_t ts::TextTable::currentLine ( ) const
inline

Get the current line.

Returns
The current line number.

◆ setCurrentLine()

void ts::TextTable::setCurrentLine ( size_t  line)
inline

Set the current line.

Parameters
[in]lineNumber of the line. If the line does not exist, the table is extended up to that line.

◆ output()

void ts::TextTable::output ( std::ostream &  out,
Headers  headers,
bool  skip_empty = false,
const UString margin = UString(),
const UString separator = u" " 
) const

Display the table.

Parameters
[in,out]outReference to the output text device.
[in]headersStyle of column headers.
[in]skip_emptyIf true, empty lines and empty columns are removed.
[in]marginLeft margin to print.
[in]separatorSeparator string between columns.

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