14 #include <stk_util/diag/PrintTable.hpp> 15 #include <stk_util/diag/Writer.hpp> 21 PrintTable::transpose_table()
const 26 PrintTable::calculate_column_widths()
const 28 ColumnWidthVector column_width_set;
31 for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
32 if ((*row_it).size() > m_columnWidth.size())
33 m_columnWidth.resize((*row_it).size(), 0);
34 if ((*row_it).size() > column_width_set.size())
35 column_width_set.resize((*row_it).size(), 0);
38 for (Row::const_iterator cell_it = (*row_it).begin(); cell_it != (*row_it).end(); ++cell_it, ++i) {
39 m_columnWidth[i] = std::max(m_columnWidth[i], (*cell_it).m_string.size());
40 column_width_set[i] = std::max(column_width_set[i], (*cell_it).m_width);
45 for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
46 if ((*row_it).size() > m_columnWidth.size())
47 m_columnWidth.resize((*row_it).size(), 0);
48 if ((*row_it).size() > column_width_set.size())
49 column_width_set.resize((*row_it).size(), 0);
52 for (Row::const_iterator cell_it = (*row_it).begin(); cell_it != (*row_it).end(); ++cell_it, ++i) {
53 m_columnWidth[i] = std::max(m_columnWidth[i], (*cell_it).m_string.size());
54 column_width_set[i] = std::max(column_width_set[i], (*cell_it).m_width);
60 for (ColumnWidthVector::size_type i = 0; i < m_columnWidth.size(); ++i) {
61 if (column_width_set[i] != 0)
62 m_columnWidth[i] = column_width_set[i];
63 m_tableWidth += m_columnWidth[i] + 1;
73 for (Table::size_type i = m_table.size(); i <= row; ++i)
74 m_table.push_back(Row());
75 for (Row::size_type i = m_table[row].size(); i <= col; ++i)
76 m_table[row].push_back(Cell());
78 m_currentCell.m_string = std::string(m_currentCell.m_indent*2,
' ') + m_currentString.str();
79 m_table[row][col] = m_currentCell;
81 m_currentCell = Cell();
82 m_currentString.str(
"");
91 m_currentCell.m_string = std::string(m_currentCell.m_indent*2,
' ') + m_currentString.str();
92 m_table.back().push_back(m_currentCell);
93 if (m_table.size() > 1 && m_table[0].size() <= m_table.back().size()) {
94 m_currentCell.m_string =
"";
95 m_currentCell.m_flags = 0;
96 m_currentCell.m_justification = m_table[0][m_table[0].size() - 1].m_justification;
97 m_currentCell.m_width = m_table[0][m_table[0].size() - 1].m_width;
98 m_currentCell.m_indent = m_table[0][m_table[0].size() - 1].m_indent;
101 m_currentCell = Cell();
103 m_currentString.str(
"");
110 PrintTable::end_row()
112 if (!m_currentString.str().empty())
114 m_table.push_back(Row());
121 std::ostream & os)
const 123 if (m_flags & COMMA_SEPARATED_VALUES)
127 if (m_flags & PRINT_TRANSPOSED)
130 calculate_column_widths();
132 if (!m_title.empty()) {
135 if(m_title.length() < m_tableWidth)
136 prespaces = (m_tableWidth - m_title.length())/2;
138 os << m_commentPrefix;
139 os << std::left <<
std::setw(prespaces) <<
"" << m_title <<
'\n';
142 for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
143 os << m_commentPrefix;
144 printRow(os, *row_it);
148 if (m_header.size() > 0) {
149 os << m_commentPrefix;
154 for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
155 os << std::left <<
std::setw(m_commentPrefix.size()) <<
"";
156 printRow(os, *row_it);
166 PrintTable::printRow(
168 const Row & row)
const 172 for (Row::const_iterator cell_it = row.begin(); cell_it != row.end(); ++cell_it, ++i) {
174 << std::left <<
std::setw(postspaces) <<
"";
177 if (cell_it != row.begin())
180 if ((*cell_it).m_flags & Cell::SPAN)
181 os << (*cell_it).m_string;
182 else if ((*cell_it).m_string.length() > m_columnWidth[i]) {
183 if ((*cell_it).m_justification & Cell::ENDS) {
184 int front_end = m_columnWidth[i]/4;
185 int back_begin = (*cell_it).m_string.size() - (m_columnWidth[i] - front_end);
186 os << (*cell_it).m_string.substr(0, front_end - 3) +
"..." + (*cell_it).m_string.substr(back_begin, (*cell_it).m_string.size());
189 os << (*cell_it).m_string.substr(0, m_columnWidth[i]);
193 if ((*cell_it).m_string.length() == 0)
194 postspaces = m_columnWidth[i];
195 else if (((*cell_it).m_justification & Cell::JUSTIFY_MASK) == Cell::LEFT) {
196 postspaces = m_columnWidth[i] - (*cell_it).m_string.length();
198 << std::left << (*cell_it).m_string;
200 else if (((*cell_it).m_justification & Cell::JUSTIFY_MASK) == Cell::CENTER) {
201 int prespaces = (m_columnWidth[i] - (*cell_it).m_string.length())/2;
202 postspaces = m_columnWidth[i] - (*cell_it).m_string.length() - prespaces;
204 << std::left <<
std::setw(prespaces) <<
"" << (*cell_it).m_string;
208 << std::right <<
std::setw(m_columnWidth[i]) << (*cell_it).m_string;
217 PrintTable::printHeaderBar(
218 std::ostream & os)
const 222 for (ColumnWidthVector::size_type i = 0; i < m_columnWidth.size(); ++i) {
234 PrintTable::csvPrint(
235 std::ostream & os)
const 237 if (!m_title.empty())
238 os << m_title <<
'\n';
240 for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
241 const Row &row = (*row_it);
242 for (Row::const_iterator cell_it = row.begin(); cell_it != row.end(); ++cell_it) {
243 if (cell_it != row.begin())
245 os << (*cell_it).m_string;
250 for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
251 const Row &row = (*row_it);
252 for (Row::const_iterator cell_it = row.begin(); cell_it != row.end(); ++cell_it) {
253 if (cell_it != row.begin())
255 os << (*cell_it).m_string;
265 PrintTable::verbose_print(
266 diag::Writer & dout)
const 288 calculate_column_widths();
290 dout << m_title << std::endl;
292 for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
294 printRow(
dout.getStream(), *row_it);
298 if (m_header.size() > 0) {
300 printHeaderBar(
dout.getStream());
304 for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
306 printRow(
dout.getStream(), *row_it);
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
std::ostream & dout()
Diagnostic output stream.
_setfill setfill(char fill)
Function setfill sets the fill character as a manipulator.
Writer & dendl(Writer &dout)
Writer function dendl calls the Writer::dendl manipulator.
_setw setw(int width)
Function setw sets the width for the next field as a manipulator.