| 1 |
#ifndef INCLUDED_TABLESUPPORT_ |
| 2 |
#define INCLUDED_TABLESUPPORT_ |
| 3 |
|
| 4 |
#include <ostream> |
| 5 |
#include <vector> |
| 6 |
#include <numeric> |
| 7 |
|
| 8 |
namespace FBB |
| 9 |
{ |
| 10 |
|
| 11 |
class TableSupport |
| 12 |
{ |
| 13 |
std::ostream *d_streamPtr; |
| 14 |
size_t d_rows; |
| 15 |
std::vector<size_t> const *d_colWidth; |
| 16 |
size_t d_maxWidth; |
| 17 |
size_t d_tableWidth; |
| 18 |
|
| 19 |
public: |
| 20 |
TableSupport() |
| 21 |
: |
| 22 |
d_streamPtr(0), |
| 23 |
d_rows(0), |
| 24 |
d_colWidth(0), |
| 25 |
d_maxWidth(0), |
| 26 |
d_tableWidth(0) |
| 27 |
{} |
| 28 |
|
| 29 |
virtual ~TableSupport() |
| 30 |
{} |
| 31 |
|
| 32 |
void setParam(std::ostream &ostr, size_t rows, |
| 33 |
std::vector<size_t> const &colWidth, |
| 34 |
size_t maxWidth) |
| 35 |
{ |
| 36 |
d_streamPtr = &ostr; |
| 37 |
d_rows = rows; |
| 38 |
d_colWidth = &colWidth; |
| 39 |
d_maxWidth = maxWidth; // 0 if colWidth should be used. |
| 40 |
d_tableWidth = d_maxWidth ? |
| 41 |
d_maxWidth * colWidth.size() |
| 42 |
: |
| 43 |
std::accumulate(colWidth.begin(), |
| 44 |
colWidth.end(), 0); |
| 45 |
} |
| 46 |
|
| 47 |
void setParam(size_t maxWidth) |
| 48 |
{ |
| 49 |
d_maxWidth = maxWidth; // 0 if colWidth should be used. |
| 50 |
} |
| 51 |
|
| 52 |
size_t tableWidth() const |
| 53 |
{ |
| 54 |
return d_tableWidth; |
| 55 |
} |
| 56 |
|
| 57 |
size_t nColumns() const |
| 58 |
{ |
| 59 |
return d_colWidth->size(); |
| 60 |
} |
| 61 |
|
| 62 |
std::ostream &out() const |
| 63 |
{ |
| 64 |
return *d_streamPtr; |
| 65 |
} |
| 66 |
|
| 67 |
virtual void hline(size_t row) const |
| 68 |
{} |
| 69 |
|
| 70 |
virtual void hline() const |
| 71 |
{} |
| 72 |
|
| 73 |
virtual void vline(size_t col) const |
| 74 |
{ |
| 75 |
if (col) |
| 76 |
*d_streamPtr << ' '; |
| 77 |
} |
| 78 |
|
| 79 |
virtual void vline() const |
| 80 |
{ |
| 81 |
*d_streamPtr << '\n'; |
| 82 |
} |
| 83 |
}; |
| 84 |
|
| 85 |
} // FBB |
| 86 |
|
| 87 |
#endif |