exprDriverIO.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) 2019-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "exprDriver.H"
29 #include "exprTools.H"
30 #include "stringOps.H"
31 
32 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
38 // Write list as single or multiple entries - see exprTools::getList()
39 static void writeList
40 (
41  Ostream& os,
42  const UList<expressions::exprString>& list
43 )
44 {
45  if (list.size() == 1)
46  {
47  os << list[0];
48  }
49  else
50  {
52 
53  if (!list.empty())
54  {
55  os << nl;
56 
57  for (const expressions::exprString& str : list)
58  {
59  os << str << nl;
60  }
61  }
63  }
64 }
65 
67 
68 } // End namespace Foam
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
75 (
76  const word& name,
77  const dictionary& dict
78 )
79 {
81 }
82 
83 
86 (
87  const word& name
88 )
89 {
91 }
92 
93 
96 (
97  const dictionary& dict,
98  const word& keyword,
99  bool mandatory
100 )
101 {
102  return exprTools::getList(keyword, dict, mandatory);
103 }
104 
105 
107 (
108  const dictionary& dict,
109  bool mandatory
110 )
111 {
112  variableStrings_ = readVariableStrings(dict, "variables", mandatory);
113 
114  return variableStrings_.size();
115 }
116 
117 
119 (
120  Ostream& os,
121  const word& keyword
122 ) const
123 {
124  if (keyword.size())
125  {
126  os.writeKeyword(keyword);
127  }
128 
129  writeList(os, variableStrings_);
130 
131  if (keyword.size())
132  {
133  os.endEntry();
134  }
135 
136  return os;
137 }
138 
139 
140 // ************************************************************************* //
dictionary dict
Ostream & writeVariableStrings(Ostream &os, const word &keyword="") const
Write "variables".
Definition: exprDriverIO.C:112
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static List< expressions::exprString > readVariableStrings(const dictionary &dict, const word &name="variables", bool mandatory=false)
Read the list of variable strings.
Definition: exprDriverIO.C:89
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Begin list [isseparator].
Definition: token.H:161
List< expressions::exprString > getList(const word &keyword, const dictionary &dict, bool mandatory=true, label recursionDepth=0)
Get an expression string list from a dictionary.
Definition: exprTools.C:116
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
A variant of Foam::string with expansion of dictionary variables into a comma-separated form...
Definition: exprString.H:55
End list [isseparator].
Definition: token.H:162
label setVariableStrings(const dictionary &dict, bool mandatory=false)
Read "variables" and assigns to the list of expression strings.
Definition: exprDriverIO.C:100
static expressions::exprString readExpression(const word &name, const dictionary &dict)
Read an expression string and do substitutions.
Definition: exprDriverIO.C:68
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
OBJstream os(runTime.globalPath()/outputName)
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
Definition: exprDriver.H:475
Namespace for OpenFOAM.