stdx::TableWriter Class Template Reference
template<class T>
class stdx::TableWriter< T >
This class helps make text tables. It takes care of column width and alignment, column and row dividers, and labels. Here is a example which makes use of stdxContainerInit.h Classes and Functions to create the label and data vectors. Notice that you can use spaces in the vertical lable divider and the column separator to create cell inner margins.
typedef vector<string> strvec_t;
strvec_t colLabels = mkVec<string>( "Item1", "Item2", "Item3", "Item4" );
strvec_t rowLabels = mkVec<string>( "Iteresting trees", "Fruits I like", "Animals" );
vector< vector<string> > data;
data += mkVec<string>( "oak", "pine", "maple", "spruce" ),
mkVec<string>( "pear", "apple", "mango", "orange" ),
mkVec<string>( "bear", "fox", "rabbit" );
stdx::TableWriter<string> tblWriter;
tblWriter.setData( stdx::iseq(data) );
tblWriter.setRowLabels( stdx::ciseq(rowLabels) );
tblWriter.setColLabels( stdx::ciseq(colLabels) );
tblWriter.setHorizLabelDivider('-');
tblWriter.setVertLabelDivider(" | ");
tblWriter.setColSep(" : ");
tblWriter.setMinColWidth(10);
tblWriter.setIndent(2);
tblWriter.writeTable( utst::TestLog::msgStream() );
Results in the following table:
| Item1 : Item2 : Item3 : Item4
--------------------------------------------------------------------
Iteresting trees | oak : pine : maple : spruce
Fruits I like | pear : apple : mango : orange
Animals | bear : fox : rabbit :
Public Methods
- TableWriter ()
- ~TableWriter ()
- setData (stdx::Iseq< I1 > inSeq)
- setRowLabels (stdx::Iseq< I > inSeq)
- setColLabels (stdx::Iseq< I > inSeq)
- setTitle (const std::string title)
- setMinColWidth (int colWidth)
- enableColTotals (bool enable)
- enableRowTotals (bool enable)
- setVertLabelDivider (std::string str)
- setHorizLabelDivider (char c)
- setColSep (std::string str)
- setIndent (int chars)
- setNumCols (int numCols)
- writeTable (std::ostream &os)