ZNC  trunk
Public Types | Public Member Functions | Protected Attributes | List of all members
CTable Class Reference

Generate a grid-like or list-like output from a given input. More...

#include <Utils.h>

+ Inheritance diagram for CTable:
+ Collaboration diagram for CTable:

Public Types

enum  EStyle { GridStyle, ListStyle }
 

Public Member Functions

 CTable ()
 
virtual ~CTable ()
 
bool AddColumn (const CString &sName)
 Adds a new column to the table. More...
 
bool SetStyle (EStyle eNewStyle)
 Selects the output style of the table. More...
 
size_type AddRow ()
 Adds a new row to the table. More...
 
bool SetCell (const CString &sColumn, const CString &sValue, size_type uRowIdx=~0)
 Sets a given cell in the table to a value. More...
 
bool GetLine (unsigned int uIdx, CString &sLine) const
 Get a line of the table's output. More...
 
CString::size_type GetColumnWidth (unsigned int uIdx) const
 Return the width of the given column. More...
 
void Clear ()
 Completely clear the table. More...
 

Protected Attributes

std::vector< CStringm_vsHeaders
 
std::map< CString, CString::size_type > m_msuWidths
 
EStyle eStyle = GridStyle
 
elements
 STL member. More...
 

Detailed Description

Generate a grid-like or list-like output from a given input.

CTable table;
table.AddColumn("a");
table.AddColumn("b");
table.AddRow();
table.SetCell("a", "hello");
table.SetCell("b", "world");
unsigned int idx = 0;
CString tmp;
while (table.GetLine(idx++, tmp)) {
// Output tmp somehow
}

The above code would generate the following output:

+-------+-------+
| a     | b     |
+-------+-------+
| hello | world |
+-------+-------+
If the table has at most two columns, one can switch to ListStyle output
like so:
@code
CTable table;
table.AddColumn("a");
table.AddColumn("b");
table.SetStyle(CTable::ListStyle);
// ...
@endcode

This will yield the following (Note that the header is omitted; asterisks
denote bold text):
@verbatim

hello: world

Member Enumeration Documentation

◆ EStyle

Enumerator
GridStyle 
ListStyle 

Constructor & Destructor Documentation

◆ CTable()

CTable::CTable ( )
inline

◆ ~CTable()

virtual CTable::~CTable ( )
inlinevirtual

Member Function Documentation

◆ AddColumn()

bool CTable::AddColumn ( const CString sName)

Adds a new column to the table.

Please note that you should add all columns before starting to fill the table!

Parameters
sNameThe name of the column.
Returns
false if a column by that name already existed or the current style does not allow this many columns.

◆ AddRow()

size_type CTable::AddRow ( )

Adds a new row to the table.

After calling this you can fill the row with content.

Returns
The index of this row

◆ Clear()

void CTable::Clear ( )

Completely clear the table.

◆ GetColumnWidth()

CString::size_type CTable::GetColumnWidth ( unsigned int  uIdx) const

Return the width of the given column.

Please note that adding and filling new rows might change the result of this function!

Parameters
uIdxThe index of the column you are interested in.
Returns
The width of the column.

◆ GetLine()

bool CTable::GetLine ( unsigned int  uIdx,
CString sLine 
) const

Get a line of the table's output.

Parameters
uIdxThe index of the line you want.
sLineThis string will receive the output.
Returns
True unless uIdx is past the end of the table.

◆ SetCell()

bool CTable::SetCell ( const CString sColumn,
const CString sValue,
size_type  uRowIdx = ~0 
)

Sets a given cell in the table to a value.

Parameters
sColumnThe name of the column you want to fill.
sValueThe value to write into that column.
uRowIdxThe index of the row to use as returned by AddRow(). If this is not given, the last row will be used.
Returns
True if setting the cell was successful.

◆ SetStyle()

bool CTable::SetStyle ( EStyle  eNewStyle)

Selects the output style of the table.

Select between different styles for printing. Default is GridStyle.

Parameters
eNewStyleTable style type.
Returns
false if the style cannot be applied (usually too many columns).

Member Data Documentation

◆ elements

T std::vector< T >::elements
inherited

STL member.

◆ eStyle

EStyle CTable::eStyle = GridStyle
protected

◆ m_msuWidths

std::map<CString, CString::size_type> CTable::m_msuWidths
protected

◆ m_vsHeaders

std::vector<CString> CTable::m_vsHeaders
protected

The documentation for this class was generated from the following file:
CTable::GetLine
bool GetLine(unsigned int uIdx, CString &sLine) const
Get a line of the table's output.
CString
String class that is used inside ZNC.
Definition: ZNCString.h:68
CTable::AddColumn
bool AddColumn(const CString &sName)
Adds a new column to the table.
CTable
Generate a grid-like or list-like output from a given input.
Definition: Utils.h:171
CTable::AddRow
size_type AddRow()
Adds a new row to the table.
CTable::SetCell
bool SetCell(const CString &sColumn, const CString &sValue, size_type uRowIdx=~0)
Sets a given cell in the table to a value.