ug4
|
Useful for printing a table to the terminal or into a file. More...
#include <table.h>
Public Member Functions | |
void | add_cols (size_t num) |
void | add_rows (size_t num) |
void | clear () |
const T & | get (size_t rowInd, size_t colInd) const |
uses operator() to get a value More... | |
char | get_col_alignment (size_t col) const |
char | get_col_sep (size_t col) const |
char | get_row_sep (size_t row) const |
size_t | num_cols () const |
size_t | num_rows () const |
T & | operator() (size_t rowInd, size_t colInd) |
Returns a reference to the given entry. More... | |
const T & | operator() (size_t rowInd, size_t colInd) const |
Returns a reference to the given entry. More... | |
void | set (size_t rowInd, size_t colInd, T value) |
uses operator() to set an entry to a value More... | |
void | set_col_alignment (size_t i_col, const char *c) |
void | set_col_alignments (std::string s) |
void | set_col_seperator (size_t i_col, const char *c) |
void | set_col_seperators (std::string s) |
void | set_default_col_alignment (const char *c) |
void | set_default_col_seperator (const char *c) |
void | set_default_row_seperator (const char *c) |
void | set_row_seperator (size_t i_row, const char *c) |
void | set_row_seperators (std::string s) |
std::ostream & | stream (std::ostream &os) const |
Table () | |
Table (size_t numRows, size_t numCols) | |
std::string | to_csv (const char *seperator) const |
std::string | to_latex () const |
std::string | to_string () const |
void | transpose () |
~Table () | |
Private Types | |
typedef std::vector< std::vector< T * > > | DataVec |
Private Attributes | |
std::vector< char > | m_colAlign |
std::vector< char > | m_colSep |
DataVec | m_data |
char | m_defaultColAlignment |
char | m_defaultColSeperator |
char | m_defaultRowSeperator |
size_t | m_numCols |
size_t | m_numRows |
std::vector< char > | m_rowSep |
Useful for printing a table to the terminal or into a file.
This class is for output purposes only. It automatically adds spacings, so that all entries in a column are indeed displayed in the same column. Note that the implementation is not optimized in regards to speed and efficiency. The class thus shouldn't be used in performance critical sections of your code. If it is however used in output related code, the introduced overhead should be fine and probably even negligible.
The class is most commonly used as a string table (Table<std::string>
) or as a stringstream table (Table<std::stringstream>
). If you want to use it for your own types, you may specialize the template method
The default implementation of EntryToString may already be suited for most cases.
Here's an example on how to use the class:
And this is what the output looks like:
num rows: 2 num columns: 2 *
Note that several typedefs exist: StringTable, StringStreamTable
void ug::Table< T >::add_cols | ( | size_t | num | ) |
Referenced by ug::Table< T >::Table().
void ug::Table< T >::add_rows | ( | size_t | num | ) |
Referenced by ug::Table< T >::Table().
void ug::Table< T >::clear |
Referenced by ug::StringTableStream::clear(), and ug::StringTableStream::operator<<().
|
inline |
uses operator() to get a value
References ug::Table< T >::operator()().
|
inline |
References ug::Table< T >::m_colAlign, and ug::Table< T >::m_defaultColAlignment.
|
inline |
References ug::Table< T >::m_colSep, and ug::Table< T >::m_defaultColSeperator.
|
inline |
References ug::Table< T >::m_defaultRowSeperator, and ug::Table< T >::m_rowSep.
size_t ug::Table< T >::num_cols |
Referenced by ug::LoadBalancer::print_last_quality_record().
size_t ug::Table< T >::num_rows |
T & ug::Table< T >::operator() | ( | size_t | rowInd, |
size_t | colInd | ||
) |
Returns a reference to the given entry.
If an entry lies outside of the tables bounds, the table will automatically be resized accordingly.
Referenced by ug::Table< T >::get(), and ug::Table< T >::set().
const T & ug::Table< T >::operator() | ( | size_t | rowInd, |
size_t | colInd | ||
) | const |
Returns a reference to the given entry.
References num_cols(), num_rows(), and UG_COND_THROW.
|
inline |
uses operator() to set an entry to a value
References ug::Table< T >::operator()().
|
inline |
References ug::Table< T >::m_colAlign.
|
inline |
References ug::Table< T >::m_colAlign, and s.
|
inline |
References ug::Table< T >::m_colSep.
|
inline |
References ug::Table< T >::m_colSep, and s.
|
inline |
References ug::Table< T >::m_defaultColAlignment.
|
inline |
References ug::Table< T >::m_defaultColSeperator.
|
inline |
References ug::Table< T >::m_defaultRowSeperator.
|
inline |
References ug::Table< T >::m_rowSep.
|
inline |
References ug::Table< T >::m_rowSep, and s.
std::ostream & ug::Table< T >::stream | ( | std::ostream & | os | ) | const |
References ug::EntryToString(), num_cols(), num_rows(), ug::repeat(), and s.
Referenced by ug::operator<<().
std::string ug::Table< T >::to_csv | ( | const char * | seperator | ) | const |
References ug::EntryToString(), num_cols(), and num_rows().
std::string ug::Table< T >::to_latex |
References num_cols(), and num_rows().
std::string ug::Table< T >::to_string |
|
inline |
References ug::Table< T >::m_data, ug::Table< T >::m_numCols, and ug::Table< T >::m_numRows.
|
private |
|
private |
Referenced by ug::Table< T >::transpose().
|
private |
|
private |
|
private |
|
private |
Referenced by ug::Table< T >::transpose().
|
private |
Referenced by ug::Table< T >::transpose().
|
private |