33 #ifndef __H__TABLE_IMPL__
34 #define __H__TABLE_IMPL__
75 for(
size_t i_row = 0; i_row < m_numRows; ++i_row){
76 for(
size_t i_col = 0; i_col < m_numCols; ++i_col){
77 delete m_data[i_row][i_col];
80 m_numRows = m_numCols = 0;
88 size_t newSize = m_numRows + num;
89 m_data.resize(newSize);
92 for(
size_t i_row = m_numRows; i_row < newSize; ++i_row){
93 m_data[i_row].resize(m_numCols);
94 for(
size_t i_col = 0; i_col < m_numCols; ++i_col)
95 m_data[i_row][i_col] =
new T;
106 size_t newSize = m_numCols + num;
107 for(
size_t i_row = 0; i_row < m_numRows; ++i_row){
108 m_data[i_row].resize(newSize);
109 for(
size_t i_col = m_numCols; i_col < newSize; ++i_col)
110 m_data[i_row][i_col] =
new T;
120 add_rows((rowInd + 1) -
num_rows());
123 add_cols((colInd + 1) -
num_cols());
125 return *m_data[rowInd][colInd];
133 return *m_data[rowInd][colInd];
155 std::stringstream ssOut;
167 std::stringstream os;
168 os <<
"\\begin{table}\n\\centering\n";
169 os <<
"\\begin{tabular}{";
171 os << get_col_sep(i) << get_col_alignment(i);
176 for(
size_t i_row = 0; i_row <
num_rows(); ++i_row)
178 if(get_row_sep(i_row) !=
' ')
181 for(
size_t i_col = 0; i_col <
num_cols(); ++i_col)
183 if(i_col != 0) os <<
" & ";
191 os <<
"\\end{tabular}\n";
192 os <<
"\\end{table}\n";
200 std::stringstream os;
201 for(
size_t i_row = 0; i_row <
num_rows(); ++i_row)
203 for(
size_t i_col = 0; i_col <
num_cols(); ++i_col)
205 if(i_col != 0) os <<
" " << seperator <<
" ";
227 std::vector<size_t> colSizes(
num_cols(), 0);
229 for(
size_t i_row = 0; i_row <
num_rows(); ++i_row){
230 for(
size_t i_col = 0; i_col <
num_cols(); ++i_col){
232 colSizes[i_col] = std::max(colSizes[i_col], strTable(i_row, i_col).size());
236 size_t totalRowLength=0;
237 for(
size_t i_col = 0; i_col <
num_cols(); ++i_col)
240 totalRowLength += colSizes[i_col] + 2;
245 for(
size_t i_row = 0; i_row <
num_rows(); ++i_row)
247 if(get_row_sep(i_row) != 0x00 && get_row_sep(i_row) !=
' ')
248 os <<
repeat(get_row_sep(i_row), totalRowLength) <<
"\n";
249 for(
size_t i_col = 0; i_col <
num_cols(); ++i_col)
251 os << get_col_sep(i_col);
252 size_t l = colSizes[i_col] + 1;
253 size_t s = strTable(i_row, i_col).size();
255 if(get_col_alignment(i_col) ==
'r')
256 os << std::setw(l) << std::right << strTable(i_row, i_col);
257 else if(get_col_alignment(i_col) ==
'l')
258 os << std::setw(l) << std::left << strTable(i_row, i_col);
260 os <<
repeat(
' ', (l-
s)/2) << std::setw(l-(l-
s)/2) << std::left << strTable(i_row, i_col);
262 os << get_col_sep(
num_cols()) << std::endl;
276 std::stringstream ss;
277 ss << table(rowInd, colInd);
284 size_t rowInd,
size_t colInd)
286 return table(rowInd, colInd);
291 size_t rowInd,
size_t colInd)
293 return table(rowInd, colInd).str();
~Table()
Definition: table_impl.hpp:67
void add_rows(size_t num)
Definition: table_impl.hpp:85
size_t num_rows() const
Definition: table_impl.hpp:137
char m_defaultColAlignment
Definition: table.h:215
Table()
Definition: table_impl.hpp:45
std::string to_string() const
Definition: table_impl.hpp:153
std::ostream & stream(std::ostream &os) const
Definition: table_impl.hpp:221
void clear()
Definition: table_impl.hpp:73
std::string to_latex() const
Definition: table_impl.hpp:163
T & operator()(size_t rowInd, size_t colInd)
Returns a reference to the given entry.
Definition: table_impl.hpp:117
char m_defaultRowSeperator
Definition: table.h:215
std::string to_csv(const char *seperator) const
Definition: table_impl.hpp:198
size_t num_cols() const
Definition: table_impl.hpp:143
char m_defaultColSeperator
Definition: table.h:215
void add_cols(size_t num)
Definition: table_impl.hpp:103
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
std::string EntryToString(const Table< T > &table, size_t rowInd, size_t colInd)
Returns a string-representation of the current entry.
Definition: table_impl.hpp:274
string repeat(char c, int nr)
Builds a string with specified repetitions of given character.
Definition: string_util.cpp:346
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
size_t num_rows() const
Definition: sparsematrix_interface.h:38
size_t num_cols() const
Definition: sparsematrix_interface.h:39