Image Component Library (ICL)
|
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 | |
std::string & | operator() (int xCell, int yCell) |
returns a reference to the entry at given cell coordinates | |
void | ensureSize (int width, int height) |
allocates at least as much memory for given amount of rows and columns | |
int | getMaxCellWidth () const |
returns the maximum cell width | |
void | setMaxCellWidth (int maxCellWidth) |
returns the current maxCellWidth value | |
const Size & | getSize () const |
returns the current table size | |
const std::vector< std::string > & | getData () const |
returns the internal data vector | |
RowAssigner | operator[] (int row) |
gives access to the table row (this can be assigned directly if needed) | |
std::string | toString () const |
serializes the table to a std::string | |
void | clear () |
clears all current existing table cells | |
Private Attributes | |
std::vector< std::string > | m_texts |
internal text data | |
Size | m_size |
current size | |
int | m_maxCellWidth |
current maximum cell width for serialization |
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.
#include <ICLUtils/TextTable.h> #inclue <iostream> using namespace icl::utils; int main(int n, char **ppc){ TextTable t; 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 | // +------------+----------+-----+----------------------+
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)
void icl::utils::TextTable::clear | ( | ) |
clears all current existing table cells
Please note: the table size is not changed here.
void icl::utils::TextTable::ensureSize | ( | int | width, |
int | height | ||
) |
allocates at least as much memory for given amount of rows and columns
const std::vector<std::string>& icl::utils::TextTable::getData | ( | ) | const [inline] |
returns the internal data vector
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
const Size& icl::utils::TextTable::getSize | ( | ) | const [inline] |
returns the current table size
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
RowAssigner icl::utils::TextTable::operator[] | ( | int | row | ) | [inline] |
gives access to the table row (this can be assigned directly if needed)
void icl::utils::TextTable::setMaxCellWidth | ( | int | maxCellWidth | ) | [inline] |
returns the current maxCellWidth value
std::string icl::utils::TextTable::toString | ( | ) | const |
serializes the table to a std::string
int icl::utils::TextTable::m_maxCellWidth [private] |
current maximum cell width for serialization
Size icl::utils::TextTable::m_size [private] |
current size
std::vector<std::string> icl::utils::TextTable::m_texts [private] |
internal text data