preCICE
v3.1.2
Loading...
Searching...
No Matches
src
utils
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
10
Column::Column
(
std::string
const
&
name
)
11
:
name
(
name
),
12
width(
name
.size())
13
{
14
}
15
16
Column::Column
(
std::string
const
&
name
,
int
width)
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
23
Column::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
30
Table::Table
()
31
:
out
(
std
::cout)
32
{
33
}
34
35
Table::Table
(
std::ostream
&
out
)
36
:
out
(
out
)
37
{
38
}
39
40
void
Table::printHeader
()
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
}
out
std::ostream & out
Definition
EventUtils.cpp:193
name
std::string name
Definition
SocketCommunication.cpp:718
TableWriter.hpp
std::accumulate
T accumulate(T... args)
algorithm
std::ostream
std::string
std::vector::begin
T begin(T... args)
Table::Table
Table()
Definition
TableWriter.cpp:30
Table::cols
std::vector< Column > cols
Definition
TableWriter.hpp:28
Table::out
std::ostream & out
Definition
TableWriter.hpp:31
Table::sepChar
std::string sepChar
Definition
TableWriter.hpp:29
Table::padding
char padding
Definition
TableWriter.hpp:30
Table::printHeader
void printHeader()
Prints the formatted header.
Definition
TableWriter.cpp:40
std::vector::end
T end(T... args)
iomanip
iostream
std::min
T min(T... args)
std
STL namespace.
numeric
string
Column
Definition
TableWriter.hpp:14
Column::precision
int precision
Definition
TableWriter.hpp:17
Column::Column
Column(std::string const &name)
Definition
TableWriter.cpp:10
vector