ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
CTable Class Reference

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

#include <Utils.h>

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

Public Member Functions

 CTable ()
 
virtual ~CTable ()
 
bool AddColumn (const CString &sName)
 Adds a new column to 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
 
elements
 STL member. More...
 

Detailed Description

Generate a grid-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 |
+-------+-------+

Constructor & Destructor Documentation

CTable::CTable ( )
inline
virtual CTable::~CTable ( )
inlinevirtual

Member Function Documentation

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.
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
void CTable::Clear ( )

Completely clear the table.

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.
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.
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.

Member Data Documentation

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

STL member.

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

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