CppTools
Loading...
Searching...
No Matches
CppTools::Table Class Reference

Class Table can be used to print values and text in the table. More...

#include <Table.hpp>

Public Member Functions

 Table ()
 Default constructor.
 Table (const unsigned short nColumns, const int width=-1)
 Constructor with parameters.
void Begin (const std::string &name)
 Prints the top part of the table with it's name.
template<typename... Ts>
void PrintHeader (Ts... args)
 Prints header of the table.
template<typename... Ts>
void PrintRow (Ts... args)
 Prints cells contents in the last row.
void End ()
 Prints the end of the table (bottom line that separates cell contents from other contents in terminal).
virtual ~Table ()
 Default desctructor.

Protected Attributes

std::string ULBorderCornerTable = "╔"
 upper left border corner of the table
std::string URBorderCornerTable = "╗"
 upper right border corner of the table
std::string horizontalBorderTable = "═"
 horizontal border of the table
std::string verticalBorderTable = "║"
 vertical border border of the table
std::string verticalBorderCell = "│"
 vertical separator between cells of the table
std::string rightCellAdjLeftVerticalBorderTable = "╟"
std::string leftCellAdjRightVerticalBorderTable = "╢"
std::string rightTableAdjLeftVerticalBorderTable = "╠"
std::string leftTableAdjRightVerticalBorderTable = "╣"
std::string horizontalCellBorder = "─"
 horizontal border of cells
std::string BLBorderCornerTable = "╚"
 bottom left border of the table
std::string BRBorderCornerTable = "╝"
 bottom right border of the table
std::string bottomCellAdjTopHorizontalBorderTable = "╤"
std::string topCellAdjBottomHorizontalBorderTable = "╧"
std::string cross = "┼"
 cross between cells borders
int numberOfColumns
 number of columns in a table
int tableWidth
 lenght of a row, i.e. width of a table
double cellWidth
 width of one cell

Detailed Description

Class Table can be used to print values and text in the table.

Example:

CppTools::Table t(3, 50); // 3 columns, 50 characters in width
t.Begin("my table"); // name of the table
t.PrintHeader("name1", "name2", "name3"); // header
t.PrintRow("r1c1", "r1c2", "r1c3"); // printing 1st row
t.PrintRow("r2c1", "r2c2", "r2c3"); // printing 2nd row
t.PrintRow("some value", "another value", "1"); t.End(); // printing 3rd row
t.End(); // printing the bottom part of the table
Class Table can be used to print values and text in the table.
Definition Table.hpp:48

Result:

 ╔═══════════════════════════════════════════════╗
 ║                   my table                    ║
 ╠════════════════╤═══════════════╤══════════════╣
 ║ name1          │ name2         │ name3        ║
 ╟────────────────┼───────────────┼──────────────╢
 ║ r1c1           │ r1c2          │ r1c3         ║
 ║ r2c1           │ r2c2          │ r2c3         ║
 ║ some value     │ another value │ 1            ║
 ╚════════════════╧═══════════════╧══════════════╝

Constructor & Destructor Documentation

◆ Table()

CppTools::Table::Table ( const unsigned short nColumns,
const int width = -1 )

Constructor with parameters.

Parameters
[in]numberOfColumnsnumber of columns in the table
[in]widthwidth of the table (negative value will result for the table to be printed with the width of a terminal). This width includes 2 empty spaces on the very left and right of the table

Member Function Documentation

◆ Begin()

void CppTools::Table::Begin ( const std::string & name)

Prints the top part of the table with it's name.

Parameters
[in]namename of the table that will be printed

◆ PrintHeader()

template<typename... Ts>
void CppTools::Table::PrintHeader ( Ts... args)
inline

Prints header of the table.

Parameters
[in]argsparameter pack containing names of columns. Number of parameters passed must not exceed number of columns passed in the constructor

◆ PrintRow()

template<typename... Ts>
void CppTools::Table::PrintRow ( Ts... args)
inline

Prints cells contents in the last row.

Parameters
[in]argsparameter pack containing values of the cells in the latest row. Number of parameters passed must not exceed number of columns passed in the constructor

Member Data Documentation

◆ bottomCellAdjTopHorizontalBorderTable

std::string CppTools::Table::bottomCellAdjTopHorizontalBorderTable = "╤"
protected

top horizontal border of the table that is adjacent to vertical border of the cell to the bottom

◆ leftCellAdjRightVerticalBorderTable

std::string CppTools::Table::leftCellAdjRightVerticalBorderTable = "╢"
protected

right vertical border of the table that is adjacent to horizontal border of the cell to the left

◆ leftTableAdjRightVerticalBorderTable

std::string CppTools::Table::leftTableAdjRightVerticalBorderTable = "╣"
protected

right vertical border of the table that is adjacent to horizontal border of the tablle to the left

◆ rightCellAdjLeftVerticalBorderTable

std::string CppTools::Table::rightCellAdjLeftVerticalBorderTable = "╟"
protected

left vertical border of the table that is adjacent to horizontal border of the cell to the right

◆ rightTableAdjLeftVerticalBorderTable

std::string CppTools::Table::rightTableAdjLeftVerticalBorderTable = "╠"
protected

left vertical border of the table that is adjacent to horizontal border of the table to the right

◆ topCellAdjBottomHorizontalBorderTable

std::string CppTools::Table::topCellAdjBottomHorizontalBorderTable = "╧"
protected

bottom horizontal border of the table that is adjacent to vertical border of the cell to the top


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