wordIOList.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2013 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "wordIOList.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
38
41}
42
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
47(
48 const UList<wordList>& tbl,
49 List<std::string::size_type>& columnWidths,
50 Ostream& os,
51 bool headerSeparator
52)
53{
54 if (tbl.empty())
55 {
56 return os;
57 }
58
59 // Find maximum width for each column
60 columnWidths.resize(tbl.first().size(), std::string::size_type(0));
61
62 forAll(columnWidths, coli)
63 {
64 auto& colWidth = columnWidths[coli];
65
66 for (const wordList& tblRow : tbl)
67 {
68 colWidth =
69 std::max
70 (
71 colWidth,
72 string::size_type(tblRow[coli].length())
73 );
74 }
75 }
76
77 // Print the rows adding spacing for the columns
78 for (const wordList& tblRow : tbl)
79 {
80 forAll(tblRow, coli)
81 {
82 os << tblRow[coli];
83 for
84 (
85 string::size_type space = 0;
86 space < columnWidths[coli] - tblRow[coli].length() + 2;
87 ++space
88 )
89 {
90 os << ' ';
91 }
92 }
93 os << nl;
94
95 if (headerSeparator) os << nl;
96 headerSeparator = false;
97 }
98
99 return os;
100}
101
102
104(
105 const UList<wordList>& tbl,
106 Ostream& os,
107 bool headerSeparator
108)
109{
110 List<std::string::size_type> columnWidths;
111 printTable(tbl, columnWidths, os, headerSeparator);
112 return os;
113}
114
115
116// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
label size_type
The type to represent the size of a buffer.
A List of objects of type <T> with automated input and output.
Definition: IOList.H:58
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
T & first()
Return the first element of the list.
Definition: UListI.H:202
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
#define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch)
Define the typeName and debug information, lookup as Name.
Definition: className.H:126
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & printTable(const UList< wordList > &tbl, List< std::string::size_type > &columnWidths, Ostream &os, bool headerSeparator=true)
Print a List of wordList as a table.
Definition: wordIOList.C:47
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define addCompoundToRunTimeSelectionTable(Type, Tag)
Add compound to selection table, lookup using typeName.
Definition: token.H:720
#define defineCompoundTypeName(Type, UnusedTag)
Define compound using Type for its name.
Definition: token.H:712