9 #ifndef STK_UTIL_DIAG_PrintTable_hpp 10 #define STK_UTIL_DIAG_PrintTable_hpp 16 #include <stk_util/diag/Writer_fwd.hpp> 23 friend PrintTable &
operator<<(PrintTable &table,
const T &t);
26 typedef std::string::size_type ColumnWidth;
27 typedef std::vector<ColumnWidth> ColumnWidthVector;
47 m_justification(RIGHT | TRUNC),
52 Cell(
const Cell &cell)
53 : m_string(cell.m_string),
54 m_flags(cell.m_flags),
55 m_justification(cell.m_justification),
56 m_indent(cell.m_indent),
60 Cell &operator=(
const Cell &cell) {
61 m_string = cell.m_string;
62 m_flags = cell.m_flags;
63 m_justification = cell.m_justification;
64 m_indent = cell.m_indent;
65 m_width = cell.m_width;
77 typedef std::vector<Cell> Row;
78 typedef std::vector<Row> Table;
82 COMMA_SEPARATED_VALUES = 0x02,
83 PRINT_TRANSPOSED = 0x04
88 m_flags(AUTO_END_COL),
91 m_table.push_back(Row());
94 explicit PrintTable(std::ostream &os)
96 m_flags(AUTO_END_COL),
100 m_table.push_back(Row());
104 PrintTable(
const PrintTable &);
105 PrintTable &operator=(
const PrintTable &);
111 Row::size_type headerSize()
const {
112 return m_header.empty() ? 0 : m_header.begin()->size();
115 inline Table::size_type size()
const {
116 return m_table.size();
119 inline std::ostringstream &getCurrentString() {
120 return m_currentString;
123 inline bool autoEndCol()
const {
124 return m_flags & AUTO_END_COL;
127 inline PrintTable &setAutoEndCol(
bool auto_end_col =
true) {
129 m_flags |= AUTO_END_COL;
131 m_flags &= ~AUTO_END_COL;
135 inline bool commaSeparatedValues()
const {
136 return m_flags & COMMA_SEPARATED_VALUES;
139 inline PrintTable &setCommaSeparatedValues(
bool comma_separated_values =
true) {
140 if (comma_separated_values)
141 m_flags |= COMMA_SEPARATED_VALUES;
143 m_flags &= ~COMMA_SEPARATED_VALUES;
147 inline PrintTable &setCommentPrefix(
const std::string &comment_prefix) {
148 m_commentPrefix = comment_prefix;
152 inline const std::string &getCommentPrefix()
const {
153 return m_commentPrefix;
160 inline PrintTable &setTitle(
const std::string &
title){
165 inline const std::string &getTitle()
const {
175 inline PrintTable&
operator<<(PrintTable& (*f)(PrintTable&)) {
187 inline PrintTable&
operator<<(std::ios_base& (*f)(std::ios_base&)) {
192 inline PrintTable &push() {
193 ++m_currentCell.m_indent;
197 inline PrintTable &span() {
198 m_currentCell.m_flags |= Cell::SPAN;
202 inline PrintTable &pop() {
203 if (m_currentCell.m_indent != 0)
204 --m_currentCell.m_indent;
209 inline PrintTable &cell_width(ColumnWidth my_width) {
210 m_currentCell.m_width = my_width;
215 inline PrintTable &indent(ColumnWidth my_indent) {
216 m_currentCell.m_indent = my_indent;
221 inline PrintTable &justify(
int justification) {
222 m_currentCell.m_justification = justification;
227 PrintTable &end_col();
229 PrintTable &end_row();
231 PrintTable &at(
size_t row,
size_t col);
233 PrintTable &end_header() {
234 m_header.push_back(m_table.back());
236 m_table.push_back(Row());
240 PrintTable &end_format() {
241 m_format = m_table.back();
243 m_table.push_back(Row());
247 void calculate_column_widths()
const;
249 void transpose_table()
const;
254 std::ostream &
print(std::ostream &os)
const;
259 std::ostream &printRow(std::ostream &os,
const Row &row)
const;
264 std::ostream &printHeaderBar(std::ostream &os)
const;
269 std::ostream &csvPrint(std::ostream &os)
const;
274 diag::Writer & verbose_print(diag::Writer &dout)
const;
284 void normalize_table(
int row,
int col);
287 std::ostream * m_ostream;
293 std::ostringstream m_currentString;
295 std::string m_commentPrefix;
296 mutable ColumnWidthVector m_columnWidth;
297 mutable ColumnWidth m_tableWidth;
302 inline PrintTable &
operator<<(PrintTable &table,
const T &t) {
303 table.m_currentString << t;
304 if (table.autoEndCol())
313 cell_width(PrintTable::ColumnWidth width)
317 PrintTable::ColumnWidth m_width;
323 at(
size_t row,
size_t col)
335 indent(PrintTable::ColumnWidth my_indent)
336 : m_indent(my_indent)
339 PrintTable::ColumnWidth m_indent;
345 justify(
int my_justify)
346 : m_justify(my_justify)
353 inline PrintTable &
operator<<(PrintTable &tout,
const at &m) {
354 tout.at(m.m_row, m.m_col);
358 inline PrintTable &
operator<<(PrintTable &tout,
const cell_width &m) {
359 tout.cell_width(m.m_width);
363 inline PrintTable &
operator<<(PrintTable &tout,
const indent &m) {
364 tout.indent(m.m_indent);
368 inline PrintTable &
operator<<(PrintTable &tout,
const justify &m) {
369 tout.justify(m.m_justify);
373 inline PrintTable &end_col(PrintTable &tout) {
374 return tout.end_col();
377 inline PrintTable &end_row(PrintTable &tout) {
378 return tout.end_row();
381 inline PrintTable &end_header(PrintTable &tout) {
382 return tout.end_header();
385 inline PrintTable &end_format(PrintTable &tout) {
386 return tout.end_format();
389 inline PrintTable &push(PrintTable &tout) {
393 inline PrintTable &pop(PrintTable &tout) {
397 inline PrintTable &span(PrintTable &tout) {
401 inline std::ostream &
operator<<(std::ostream &os,
const PrintTable &table){
402 return table.print(os);
405 inline diag::Writer &
operator<<(diag::Writer &dout,
const PrintTable &table){
406 return table.verbose_print(dout);
421 #endif // STK_UTIL_DIAG_PrintTable_hpp std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
std::string title(const std::string &s)
Function title returns a first letter of each word capitalized of the string.
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
static const char LEFT
Meta-character to force left justification.
std::ostream & tout()
Regression test textual output stream.