wordList: Added initial version of printTable which prints a List<wordList> in tabular form

This commit is contained in:
Henry
2012-09-26 23:48:47 +01:00
parent 2801f229fa
commit 931b86335e
2 changed files with 41 additions and 0 deletions

View File

@ -37,4 +37,42 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName(wordListIOList, "wordListList", 0);
}
void Foam::printTable(const List<wordList>& wll, Ostream& os)
{
if (!wll.size()) return;
// Find the maximum word length for each column
List<string::size_type> columnWidth(wll[0].size(), string::size_type(0));
forAll(columnWidth, j)
{
forAll(wll, i)
{
columnWidth[j] = max(columnWidth[j], wll[i][j].size());
}
}
// Print the rows adding spacing for the columns
forAll(wll, i)
{
forAll(wll[i], j)
{
os << wll[i][j];
for
(
string::size_type k=0;
k<columnWidth[j] - wll[i][j].size() + 2;
k++
)
{
os << ' ';
}
}
os << nl;
if (i == 0) os << nl;
}
}
// ************************************************************************* //

View File

@ -41,6 +41,9 @@ namespace Foam
{
typedef IOList<word> wordIOList;
typedef IOList<wordList> wordListIOList;
// Print word list list as a table
void printTable(const List<wordList>&, Ostream&);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //