preCICE v3.1.2
Loading...
Searching...
No Matches
TableWriter.cpp
Go to the documentation of this file.
1#include "TableWriter.hpp"
2
3#include <algorithm>
4#include <iomanip>
5#include <iostream>
6#include <numeric>
7#include <string>
8#include <vector>
9
11 : name(name),
12 width(name.size())
13{
14}
15
17 : name(name),
18 width(std::max(width, static_cast<int>(name.size())))
19{
20 precision = std::min(this->precision, this->width - 1);
21}
22
23Column::Column(std::string const &name, int width, int precision)
24 : name(name),
25 width(std::max(width, static_cast<int>(name.size())))
26{
27 this->precision = std::min(precision, this->width - 1);
28}
29
31 : out(std::cout)
32{
33}
34
39
41{
42 using namespace std;
43
44 for (auto &h : cols) {
45 out << padding << setw(h.width) << h.name << padding << sepChar;
46 }
47
48 out << '\n';
49 int headerLength = std::accumulate(cols.begin(), cols.end(), 0, [this](int count, const Column &col) {
50 return count + col.width + sepChar.size() + 2;
51 });
52 std::string sepLine(headerLength, '-');
53 out << sepLine << '\n';
54}
std::ostream & out
std::string name
T accumulate(T... args)
T begin(T... args)
std::vector< Column > cols
std::ostream & out
std::string sepChar
char padding
void printHeader()
Prints the formatted header.
T end(T... args)
T min(T... args)
STL namespace.
int precision
Column(std::string const &name)