ENH: minor improvements to printTable(List<wordList>, ..)
- return Ostream& - make header separation optional
This commit is contained in:
parent
0ccc005fe6
commit
5d0f1788e1
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd |
|
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2012-2013 OpenFOAM Foundation
|
| Copyright (C) 2012-2013 OpenFOAM Foundation
|
||||||
@ -40,40 +40,47 @@ namespace Foam
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::printTable
|
Foam::Ostream& Foam::printTable
|
||||||
(
|
(
|
||||||
const List<wordList>& wll,
|
const UList<wordList>& tbl,
|
||||||
List<string::size_type>& columnWidth,
|
List<std::string::size_type>& columnWidths,
|
||||||
Ostream& os
|
Ostream& os,
|
||||||
|
bool headerSeparator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (wll.empty()) return;
|
if (tbl.empty())
|
||||||
|
|
||||||
// Find the maximum word length for each column
|
|
||||||
columnWidth.setSize(wll[0].size(), string::size_type(0));
|
|
||||||
forAll(columnWidth, coli)
|
|
||||||
{
|
{
|
||||||
forAll(wll, rowi)
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find maximum width for each column
|
||||||
|
columnWidths.resize(tbl.first().size(), std::string::size_type(0));
|
||||||
|
|
||||||
|
forAll(columnWidths, coli)
|
||||||
|
{
|
||||||
|
auto& colWidth = columnWidths[coli];
|
||||||
|
|
||||||
|
for (const wordList& tblRow : tbl)
|
||||||
{
|
{
|
||||||
columnWidth[coli] =
|
colWidth =
|
||||||
std::max
|
std::max
|
||||||
(
|
(
|
||||||
columnWidth[coli],
|
colWidth,
|
||||||
string::size_type(wll[rowi][coli].size())
|
string::size_type(tblRow[coli].length())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the rows adding spacing for the columns
|
// Print the rows adding spacing for the columns
|
||||||
forAll(wll, rowi)
|
for (const wordList& tblRow : tbl)
|
||||||
{
|
{
|
||||||
forAll(wll[rowi], coli)
|
forAll(tblRow, coli)
|
||||||
{
|
{
|
||||||
os << wll[rowi][coli];
|
os << tblRow[coli];
|
||||||
for
|
for
|
||||||
(
|
(
|
||||||
string::size_type space=0;
|
string::size_type space = 0;
|
||||||
space < columnWidth[coli] - wll[rowi][coli].size() + 2;
|
space < columnWidths[coli] - tblRow[coli].length() + 2;
|
||||||
++space
|
++space
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -82,15 +89,24 @@ void Foam::printTable
|
|||||||
}
|
}
|
||||||
os << nl;
|
os << nl;
|
||||||
|
|
||||||
if (!rowi) os << nl;
|
if (headerSeparator) os << nl;
|
||||||
|
headerSeparator = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::printTable(const List<wordList>& wll, Ostream& os)
|
Foam::Ostream& Foam::printTable
|
||||||
|
(
|
||||||
|
const UList<wordList>& tbl,
|
||||||
|
Ostream& os,
|
||||||
|
bool headerSeparator
|
||||||
|
)
|
||||||
{
|
{
|
||||||
List<string::size_type> columnWidth;
|
List<std::string::size_type> columnWidths;
|
||||||
printTable(wll, columnWidth, os);
|
printTable(tbl, columnWidths, os, headerSeparator);
|
||||||
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd |
|
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2012-2013 OpenFOAM Foundation
|
| Copyright (C) 2012-2013 OpenFOAM Foundation
|
||||||
@ -44,9 +44,22 @@ namespace Foam
|
|||||||
typedef IOList<word> wordIOList;
|
typedef IOList<word> wordIOList;
|
||||||
typedef IOList<wordList> wordListIOList;
|
typedef IOList<wordList> wordListIOList;
|
||||||
|
|
||||||
// Print word list list as a table
|
//- Print a List of wordList as a table
|
||||||
void printTable(const List<wordList>&, List<string::size_type>&, Ostream&);
|
Ostream& printTable
|
||||||
void printTable(const List<wordList>&, Ostream&);
|
(
|
||||||
|
const UList<wordList>& tbl,
|
||||||
|
List<std::string::size_type>& columnWidths,
|
||||||
|
Ostream& os,
|
||||||
|
bool headerSeparator = true
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Print a List of wordList as a table
|
||||||
|
Ostream& printTable
|
||||||
|
(
|
||||||
|
const UList<wordList>& tbl,
|
||||||
|
Ostream& os,
|
||||||
|
bool headerSeparator = true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
Loading…
Reference in New Issue
Block a user