This class helps to print a table data with alignment.
More...
#include <TabularPrinter.h>
This class helps to print a table data with alignment.
Definition at line 29 of file TabularPrinter.h.
TabularPrinter::TabularPrinter |
( |
| ) |
|
CppSamples::Common::TabularPrinter::~TabularPrinter |
( |
| ) |
|
|
inline |
void CppSamples::Common::TabularPrinter::AddCellValue |
( |
std::string |
value | ) |
|
Add a std::string value to the current cell in the table and forward the pointer to next cell.
- Parameters
-
value | New std::string value to be added.. |
void TabularPrinter::AddCellValue |
( |
int |
value | ) |
|
Add a std::string value to the current cell in the table and forward the pointer to next cell.
Add a string value to the current cell in the table and forward the pointer to next cell.
- Parameters
-
value | New int value to be added.. |
Definition at line 53 of file TabularPrinter.cpp.
void AddCellValue(std::string value)
Add a std::string value to the current cell in the table and forward the pointer to next cell...
void TabularPrinter::AddColumn |
( |
std::string |
heading, |
|
|
int |
width, |
|
|
int |
alignment = -1 |
|
) |
| |
Add a column to the table.
- Parameters
-
heading | Heading of the column. |
width | Width of the column. |
isLeftAligned | -1 for Left alignment. 0 for center. 1 for right alignment. [Default is Left Alignment]. |
Definition at line 22 of file TabularPrinter.cpp.
25 columnHeading->
Value = heading;
26 columnHeading->
Width = width;
std::vector< ColumnHeading * > _headings
This class represents a column heading.
void TabularPrinter::AddRow |
( |
| ) |
|
Add a row to the table.
Definition at line 34 of file TabularPrinter.cpp.
This class represents a row of data in the table.
std::vector< Row * > _rows
string TabularPrinter::GetAlignedCellValue |
( |
std::string |
actualValue, |
|
|
ColumnHeading * |
columnHeading |
|
) |
| |
|
staticprivate |
Definition at line 83 of file TabularPrinter.cpp.
85 string alignedCellValue =
"";
86 int colWidth = columnHeading->
Width;
87 int currentWidth = actualValue.size();
88 if (currentWidth > colWidth)
89 alignedCellValue = actualValue.substr(0, colWidth);
91 int spacing = colWidth - currentWidth;
94 alignedCellValue = actualValue + string(spacing,
' ');
95 else if (alignment == 1)
96 alignedCellValue = string(spacing,
' ') + actualValue;
98 int left = spacing / 2;
99 int right = spacing - left;
100 alignedCellValue = string(left,
' ') + actualValue + string(right,
' ');
103 return alignedCellValue;
string TabularPrinter::GetHeader |
( |
| ) |
|
|
private |
Definition at line 106 of file TabularPrinter.cpp.
107 string rowValue =
"";
109 for (
int i = 0; i < colCount; i++)
static std::string GetAlignedCellValue(std::string actualValue, ColumnHeading *columnHeading)
std::vector< ColumnHeading * > _headings
string TabularPrinter::PrintRow |
( |
Row * |
row | ) |
|
|
private |
Definition at line 74 of file TabularPrinter.cpp.
77 int colCount = row->
Values.size();
78 for (
int i = 0; i < colCount; i++)
static std::string GetAlignedCellValue(std::string actualValue, ColumnHeading *columnHeading)
std::vector< std::string > Values
std::vector< ColumnHeading * > _headings
string TabularPrinter::ToString |
( |
| ) |
|
Convert the table to std::string and return it.
Convert the table to string and return it.
- Returns
- String value representing the table.
Definition at line 61 of file TabularPrinter.cpp.
64 string line = string(tableValue.size(),
'-');
65 tableValue = line +
"\n" + tableValue +
"\n" + line +
"\n";
67 int rowCount =
_rows.size();
68 for (
int i = 0; i < rowCount; i++)
70 tableValue += line +
"\n";
std::string PrintRow(Row *row)
std::vector< Row * > _rows
int CppSamples::Common::TabularPrinter::_columnCount |
|
private |
std::vector<ColumnHeading*> CppSamples::Common::TabularPrinter::_headings |
|
private |
std::vector<Row*> CppSamples::Common::TabularPrinter::_rows |
|
private |
The documentation for this class was generated from the following files: