This class produces a formatted table of text lines and columns.
More...
#include <tsTextTable.h>
|
| 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.
|
|
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.
◆ Align
Alignment of columns.
Enumerator |
---|
RIGHT | Align right.
|
LEFT | Align left.
|
◆ Headers
Define the style of top headers.
Enumerator |
---|
NONE | No header.
|
TEXT | Simple text line.
|
UNDERLINED | Text line and underline.
|
◆ addColumn()
template<typename ID , typename std::enable_if< std::is_integral< ID >::value||std::is_enum< ID >::value >::type * = nullptr>
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
-
ID | An integral of enumeration type which is used to identify the columns. |
- Parameters
-
[in] | id | Identifier of the column. |
[in] | header | Top-column header text. |
[in] | align | Column 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
-
ID | An integral of enumeration type which is used to identify the columns. |
- Parameters
-
[in] | column | Identifier of the column. |
[in] | value | Text 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>
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
-
ID | An integral of enumeration type which is used to identify the columns. |
- Parameters
-
[in] | column | Identifier of the column. |
[in] | value | Text 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
-
ID | An integral of enumeration type which is used to identify the columns. |
- Parameters
-
[in] | line | Number of the line to fill. If the line does not exist, the table is extended up to that line. |
[in] | column | Identifier of the column. |
[in] | value | Text 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>
Fill a table cell of the given line with text.
The current line remains unchanged.
- Template Parameters
-
ID | An integral of enumeration type which is used to identify the columns. |
- Parameters
-
[in] | line | Number of the line to fill. If the line does not exist, the table is extended up to that line. |
[in] | column | Identifier of the column. |
[in] | value | Text 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] | line | Number 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] | out | Reference to the output text device. |
[in] | headers | Style of column headers. |
[in] | skip_empty | If true, empty lines and empty columns are removed. |
[in] | margin | Left margin to print. |
[in] | separator | Separator string between columns. |
The documentation for this class was generated from the following file: