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 -------------------------------------------------------------------------------
11 License
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 
34 namespace Foam
35 {
36  defineCompoundTypeName(List<word>, wordList);
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 // ************************************************************************* //
wordIOList.H
Foam::wordListIOList
IOList< wordList > wordListIOList
Definition: wordIOList.H:46
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::UList::first
T & first()
Return the first element of the list.
Definition: UListI.H:202
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::wordIOList
IOList< word > wordIOList
IO of a list of words.
Definition: wordIOList.H:45
Foam::printTable
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
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:76
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::UList::empty
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::addCompoundToRunTimeSelectionTable
addCompoundToRunTimeSelectionTable(List< complex >, complexList)
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::defineCompoundTypeName
defineCompoundTypeName(List< complex >, complexList)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::defineTemplateTypeNameAndDebugWithName
defineTemplateTypeNameAndDebugWithName(psiReactionsSensitivityAnalysisFunctionObject, "psiReactionsSensitivityAnalysis", 0)