Image Component Library (ICL)
Classes | Public Member Functions | Private Attributes | List of all members
icl::utils::TextTable Class Reference

Utility class for pretty console output. More...

#include <TextTable.h>

Classes

class  RowAssigner
 Utility class that is used, to assign a table row at once. More...
 

Public Member Functions

 TextTable (int width=0, int height=0, int maxCellWidth=20)
 creates a new table with optionally given dimensions More...
 
std::string & operator() (int xCell, int yCell)
 returns a reference to the entry at given cell coordinates More...
 
void ensureSize (int width, int height)
 allocates at least as much memory for given amount of rows and columns More...
 
int getMaxCellWidth () const
 returns the maximum cell width More...
 
void setMaxCellWidth (int maxCellWidth)
 returns the current maxCellWidth value More...
 
const SizegetSize () const
 returns the current table size More...
 
const std::vector< std::string > & getData () const
 returns the internal data vector More...
 
RowAssigner operator[] (int row)
 gives access to the table row (this can be assigned directly if needed) More...
 
std::string toString () const
 serializes the table to a std::string More...
 
void clear ()
 clears all current existing table cells More...
 

Private Attributes

std::vector< std::string > m_texts
 internal text data More...
 
Size m_size
 current size More...
 
int m_maxCellWidth
 current maximum cell width for serialization More...
 

Detailed Description

Utility class for pretty console output.

The text table implements a simple tabular structure (rows x colums cells that have string content). The TextTable structure can always be serialized as a pretty printed. The table's size is automatically expanded if new data is set. Optionally, the table can be created with a given row- and column count. The table data can be set using the (x,y)-function- call operator.

Example (Image Convolution)

#inclue <iostream>
using namespace icl::utils;
int main(int n, char **ppc){
t(0,0) = "name";
t(1,0) = "forename";
t(2,0) = "age";
t(3,0) = "address";
t[1] = tok("elbrechter,christof,34,Some Street in Oerlinghausen (close to Bielefeld)",",");
t[2] = tok("gotting,michael,??,Somewhere else",",");
std::cout << t << std::endl;
}
// output
// +------------+----------+-----+----------------------+
// | name | forename | age | address |
// +------------+----------+-----+----------------------+
// | elbrechter | christof | 34 | Some Street in Oerli |
// | | | | nghausen (close to B |
// | | | | ielefeld) |
// +------------+----------+-----+----------------------+
// | gotting | michael | ?? | Somewhere else |
// +------------+----------+-----+----------------------+

Constructor & Destructor Documentation

◆ TextTable()

icl::utils::TextTable::TextTable ( int  width = 0,
int  height = 0,
int  maxCellWidth = 20 
)
inline

creates a new table with optionally given dimensions

The table size is automatically expanded whenever a non- existing row- or column-index is passed to the (x,y)- index operator to (read or set data)

Member Function Documentation

◆ clear()

void icl::utils::TextTable::clear ( )

clears all current existing table cells

Please note: the table size is not changed here.

◆ ensureSize()

void icl::utils::TextTable::ensureSize ( int  width,
int  height 
)

allocates at least as much memory for given amount of rows and columns

◆ getData()

const std::vector<std::string>& icl::utils::TextTable::getData ( ) const
inline

returns the internal data vector

◆ getMaxCellWidth()

int icl::utils::TextTable::getMaxCellWidth ( ) const
inline

returns the maximum cell width

This option is just for serialization. Cells will never become wider than this size. If a cell's content is larger than the maxCellWidth the row-height is increased automatically

◆ getSize()

const Size& icl::utils::TextTable::getSize ( ) const
inline

returns the current table size

◆ operator()()

std::string& icl::utils::TextTable::operator() ( int  xCell,
int  yCell 
)
inline

returns a reference to the entry at given cell coordinates

Please note, that there is no const-version since this method does expand the table dimensions if the selected cell-coordinates are larger than the cell size

◆ operator[]()

RowAssigner icl::utils::TextTable::operator[] ( int  row)
inline

gives access to the table row (this can be assigned directly if needed)

◆ setMaxCellWidth()

void icl::utils::TextTable::setMaxCellWidth ( int  maxCellWidth)
inline

returns the current maxCellWidth value

◆ toString()

std::string icl::utils::TextTable::toString ( ) const

serializes the table to a std::string

Member Data Documentation

◆ m_maxCellWidth

int icl::utils::TextTable::m_maxCellWidth
private

current maximum cell width for serialization

◆ m_size

Size icl::utils::TextTable::m_size
private

current size

◆ m_texts

std::vector<std::string> icl::utils::TextTable::m_texts
private

internal text data


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